refactor: Update LogType to include ErrorLogType
The LogType in the schema module has been updated to include the ErrorLogType. This allows for more detailed logging of error messages, including the error message itself and the stack trace. This change improves the accuracy and usefulness of error logging in the application.
This commit is contained in:
parent
4249170fa9
commit
1367212412
10 changed files with 64 additions and 28 deletions
|
|
@ -41,7 +41,9 @@ const SwitchOutputView: React.FC<SwitchOutputViewProps> = ({
|
|||
<div>NO OUTPUT</div>
|
||||
</Case>
|
||||
<Case condition={resultType === "error" || resultType === "ValueError"}>
|
||||
<ErrorOutput value={resultMessage}></ErrorOutput>
|
||||
<ErrorOutput
|
||||
value={`${resultMessage.errorMessage}\n\n${resultMessage.stackTrace}`}
|
||||
></ErrorOutput>
|
||||
</Case>
|
||||
|
||||
<Case condition={node && resultType === "text"}>
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import { useShortcutsStore } from "../../../../stores/shortcuts";
|
|||
import { useTypesStore } from "../../../../stores/typesStore";
|
||||
import { APIClassType } from "../../../../types/api";
|
||||
import { ParameterComponentType } from "../../../../types/components";
|
||||
import { isErrorLog } from "../../../../types/utils/typeCheckingUtils";
|
||||
import {
|
||||
debouncedHandleUpdateValues,
|
||||
handleUpdateValues,
|
||||
|
|
@ -114,11 +115,9 @@ export default function ParameterComponent({
|
|||
if (!outputName) return;
|
||||
const logs = data?.logs[outputName];
|
||||
if (Array.isArray(logs) && logs.length > 1) {
|
||||
return logs.some(
|
||||
(log) => log.type === "error" || log.type === "ValueError",
|
||||
);
|
||||
return logs.some((log) => isErrorLog(log));
|
||||
} else {
|
||||
return logs?.type === "error" || logs?.type === "ValueError";
|
||||
return isErrorLog(logs);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -129,11 +128,6 @@ export default function ParameterComponent({
|
|||
!!flowPool[data.id] &&
|
||||
logHasMessage(flowPool[data.id][flowPool[data.id].length - 1]?.data);
|
||||
|
||||
let hasOutputs;
|
||||
if (flowPoolNode?.data?.logs && outputName) {
|
||||
hasOutputs = flowPoolNode?.data?.logs[outputName] ?? null;
|
||||
}
|
||||
|
||||
const unknownOutput = logTypeIsUnknown(flowPoolNode?.data);
|
||||
const errorOutput = logTypeIsError(flowPoolNode?.data);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { useEffect } from "react";
|
||||
import { LogType, VertexBuildTypeAPI } from "../../types/api";
|
||||
import { VertexBuildTypeAPI } from "../../types/api";
|
||||
import { isErrorLog } from "../../types/utils/typeCheckingUtils";
|
||||
|
||||
const useValidationStatusString = (
|
||||
validationStatus: VertexBuildTypeAPI,
|
||||
|
|
@ -8,11 +9,10 @@ const useValidationStatusString = (
|
|||
useEffect(() => {
|
||||
if (validationStatus?.data?.logs) {
|
||||
// if it is not a string turn it into a string
|
||||
console.log("validationStatus", validationStatus);
|
||||
let newValidationString = "";
|
||||
Object.values(validationStatus?.data?.logs).forEach((log: any) => {
|
||||
if (log.type === "error" || log.type === "ValueError") {
|
||||
newValidationString += `${log.message}\n`;
|
||||
if (isErrorLog(log)) {
|
||||
newValidationString += `${log.message.errorMessage}\n`;
|
||||
}
|
||||
});
|
||||
setValidationString(newValidationString);
|
||||
|
|
|
|||
|
|
@ -181,8 +181,13 @@ export type VertexBuildTypeAPI = {
|
|||
artifacts: any | ChatOutputType | ChatInputType;
|
||||
};
|
||||
|
||||
export type ErrorLogType = {
|
||||
errorMessage: string;
|
||||
stackTrace: string;
|
||||
};
|
||||
|
||||
export type LogType = {
|
||||
message: any;
|
||||
message: any | ErrorLogType;
|
||||
type: string;
|
||||
};
|
||||
|
||||
|
|
|
|||
23
src/frontend/src/types/utils/typeCheckingUtils.ts
Normal file
23
src/frontend/src/types/utils/typeCheckingUtils.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { ErrorLogType } from "../api";
|
||||
|
||||
export function isErrorLogType(value: any): value is ErrorLogType {
|
||||
return (
|
||||
typeof value === "object" &&
|
||||
value !== null &&
|
||||
"errorMessage" in value &&
|
||||
typeof value.errorMessage === "string" &&
|
||||
"stackTrace" in value &&
|
||||
typeof value.stackTrace === "string"
|
||||
);
|
||||
}
|
||||
|
||||
export function isErrorLog(
|
||||
log: any,
|
||||
): log is { type: "error"; message: ErrorLogType } {
|
||||
return (
|
||||
typeof log === "object" &&
|
||||
log !== null &&
|
||||
(log.type === "error" || log.type === "ValueError") &&
|
||||
isErrorLogType(log.message)
|
||||
);
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import { getVerticesOrder, postBuildVertex } from "../controllers/API";
|
|||
import useAlertStore from "../stores/alertStore";
|
||||
import useFlowStore from "../stores/flowStore";
|
||||
import { VertexBuildTypeAPI } from "../types/api";
|
||||
import { isErrorLogType } from "../types/utils/typeCheckingUtils";
|
||||
import { VertexLayerElementType } from "../types/zustand/flow";
|
||||
|
||||
type BuildVerticesParams = {
|
||||
|
|
@ -275,9 +276,14 @@ async function buildVertex({
|
|||
const errorMessages = Object.keys(buildData.data.logs).map((key) => {
|
||||
const logs = buildData.data.logs[key];
|
||||
if (Array.isArray(logs)) {
|
||||
return logs.map((log) => log.message);
|
||||
return logs
|
||||
.filter((log) => isErrorLogType(log.message))
|
||||
.map((log) => log.message.errorMessage);
|
||||
}
|
||||
return [logs.message];
|
||||
if (!isErrorLogType(logs.message)) {
|
||||
return [];
|
||||
}
|
||||
return [logs.message.errorMessage];
|
||||
});
|
||||
onBuildError!(
|
||||
"Error Building Component",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue