Skip to content

Commit

Permalink
Mention node names in error messages (#2920)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored May 30, 2024
1 parent 25e9dc3 commit aecb06a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/common/formatExecutionErrorMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ import { BackendEventMap } from './Backend';
import { SchemaMap } from './SchemaMap';

const defaultListItem = (label: string, value: string) => `- ${label}: ${value}`;
const defaultGetNodeName = () => undefined;

export const formatExecutionErrorMessage = (
{ exception, source }: Pick<BackendEventMap['execution-error'], 'exception' | 'source'>,
schemata: SchemaMap,
formatListItem: (label: string, value: string) => string = defaultListItem
formatListItem: (label: string, value: string) => string = defaultListItem,
getNodeName: (nodeId: string) => string | undefined = defaultGetNodeName
): string => {
if (!source) return exception;

const schema = schemata.get(source.schemaId);
let { name } = schema;
let name = `${schema.name} node`;
if (!schemata.hasUniqueName(source.schemaId)) {
// make the name unique using the category of the schema
name = `${schema.category} ${schema.name}`;
name = `${schema.category} ${name}`;
}
const nodeName = getNodeName(source.nodeId);
if (nodeName) {
name = `${name} (called ${nodeName})`;
}

const inputs = schema.inputs.map((i) => {
Expand Down Expand Up @@ -55,5 +61,5 @@ export const formatExecutionErrorMessage = (

const inputsInfo = inputs.length === 0 ? '' : `Input values:\n${inputs.join('\n')}`;

return `An error occurred in a ${name} node:\n\n${exception.trim()}\n\n${inputsInfo}`;
return `An error occurred in a ${name}:\n\n${exception.trim()}\n\n${inputsInfo}`;
};
3 changes: 2 additions & 1 deletion src/renderer/contexts/ExecutionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ export const ExecutionProvider = memo(({ children }: React.PropsWithChildren<{}>
message: formatExecutionErrorMessage(
data,
schemata,
(label, value) => `• ${label}: ${value}`
(label, value) => `• ${label}: ${value}`,
(nodeId) => getNodes().find((n) => n.id === nodeId)?.data.nodeName
),
trace: data.exceptionTrace,
});
Expand Down

0 comments on commit aecb06a

Please sign in to comment.