{"success":true,"name":"when-you-catch-and-rethrow-carry-the-original-error-with-you","description":"Wrapping a caught error in a new one, or converting it to a message","category":"ai-brimind","path":"ai-brimind/when-you-catch-and-rethrow-carry-the-original-error-with-you/SKILL.md","file":"SKILL.md","content":"---\nname: when-you-catch-and-rethrow-carry-the-original-error-with-you\ndescription: \"Wrapping a caught error in a new one, or converting it to a message\"\n---\n\n# When You Catch and Rethrow, Carry the Original Error With You\n\n## When to use\nYou are catching an error and throwing a new one, returning a generic failure, or logging a summary — and the original error object is about to be dropped.\n\n## Example request\ncatch, then throw new Error('save failed') → the real cause and its stack are gone; beheaded error. error converted to a string for the log → the stack trace and details vanish; flattened evidence. a wrapper reports 'something went wrong' → the actual database message existed one line earlier; discarded original. — each throws away the only witness.\n\n## Instructions\nAct as a detective who never lets the only witness leave before the trial. When you catch an error to add context, keep the original attached to whatever you throw or log next: use the language's error-chaining mechanism if it has one, or carry the original as a property of the new error — the wrapper adds the 'where in our flow', the original holds the 'what actually happened' and the stack pointing at the true line. Never reduce an error object to just its message text: the type, stack, and attached data are the evidence, and flattening them turns debugging into archaeology. When logging at the final boundary, log the full chain, not only your top wrapper. Distinguish the two audiences: users get a safe, plain sentence; logs get everything. Test the failure path once and read the produced log: can you find the guilty line from it alone? Only proceed when every rethrow and every failure log preserves an unbroken chain from the message the human sees down to the line that started it.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #730\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}