{"record":{"id":"ad2a8bca6b3ded79","repo":"n8n-io/n8n","slug":"error-description-error-message-unknown-e","errorCode":null,"errorMessage":"error?.description || error?.message || 'Unknown error'","messagePattern":"error\\?\\.description \\|\\| error\\?\\.message \\|\\| 'Unknown error'","errorType":"exception","errorClass":"GuardrailError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/Guardrails/helpers/base.ts","lineNumber":18,"sourceCode":"import {\n\ttype GuardrailResult,\n\tGuardrailError,\n\ttype GroupedGuardrailResults,\n\ttype StageGuardRails,\n} from '../actions/types';\n\ntype RunStageGuardrailsOptions = {\n\tstageGuardrails: StageGuardRails;\n\tstage: keyof StageGuardRails;\n\tinputText: string;\n\tfailOnlyOnErrors?: boolean;\n};\n\n// eslint-disable-next-line @typescript-eslint/promise-function-async\nconst wrapInGuardrailError = (guardrailName: string, promise: Promise<GuardrailResult>) => {\n\treturn promise.catch((error) => {\n\t\tthrow new GuardrailError(\n\t\t\tguardrailName,\n\t\t\terror?.description || error?.message || 'Unknown error',\n\t\t\terror?.description,\n\t\t);\n\t});\n};\n\nexport async function runStageGuardrails({\n\tstageGuardrails,\n\tstage,\n\tinputText,\n\tfailOnlyOnErrors,\n}: RunStageGuardrailsOptions): Promise<GroupedGuardrailResults> {\n\tconst guardrailPromises: Array<Promise<GuardrailResult>> = [];\n\tfor (const guardrail of stageGuardrails[stage]) {\n\t\tguardrailPromises.push(\n\t\t\twrapInGuardrailError(\n\t\t\t\tguardrail.name,","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/Guardrails/helpers/base.ts#L1-L36","documentation":"This is the fallback message inside GuardrailError thrown by wrapInGuardrailError() in the Guardrails base helper. It catches any rejection from a guardrail check promise and re-throws a GuardrailError whose message is error?.description || error?.message || 'Unknown error' and whose description is error?.description. It normalizes arbitrary thrown values into the GuardrailError shape so stage aggregation can group them.","triggerScenarios":"runStageGuardrails() wraps each guardrail.check(inputText) promise with wrapInGuardrailError. If the check function throws, rejects, or yields a non-GuardrailError, the wrapper converts it. Triggers: a guardrail check throwing a plain Error, a string, or undefined; an exception inside a custom guardrail implementation.","commonSituations":"A custom guardrail whose check function throws a non-standard error; a third-party guardrail raising an Error without a description; an unexpected runtime fault inside a guardrail (null dereference, bad cast).","solutions":["Inspect the GuardrailError.guardrailName to identify which check threw, then debug that guardrail's check function.","Make custom guardrail implementations throw errors with both `message` and `description` so the surfaced text is meaningful.","Ensure guardrail check functions catch their own internal errors and return a structured GuardrailResult instead of throwing when the failure is a normal 'flagged' outcome.","Reproduce the failing input in isolation against the named guardrail to find the triggering value."],"exampleFix":"// before: guardrail throws a bare string\ncheck: (text) => { if (bad(text)) throw 'invalid'; }\n// after: throw an Error with description, or return a structured result\ncheck: (text) => { if (bad(text)) throw new Error('invalid input'); }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isGuardrailError(e): e is GuardrailError { return e instanceof GuardrailError; }","tryCatchPattern":"try {\n  await runStageGuardrails({ ... });\n} catch (e) {\n  if (e instanceof GuardrailError) {\n    // e.guardrailName tells you which check failed\n  }\n}","preventionTips":["Make custom guardrail checks return structured GuardrailResult instead of throwing.","Add try/catch inside custom checks to convert internal errors to results.","Always populate both message and description on thrown errors."],"tags":["guardrails","error-wrapping","promise","guardrail"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}