{"success":true,"name":"handle-the-failure-path-in-the-same-breath-as-the-feature","description":"Writing code that calls things that can fail, handling only success","category":"ai-brimind","path":"ai-brimind/handle-the-failure-path-in-the-same-breath-as-the-feature/SKILL.md","file":"SKILL.md","content":"---\nname: handle-the-failure-path-in-the-same-breath-as-the-feature\ndescription: \"Writing code that calls things that can fail, handling only success\"\n---\n\n# Handle the Failure Path in the Same Breath as the Feature\n\n## When to use\nWriting code that calls things that can fail, handling only success\n\n## Example request\nawait fetch(...) with no catch → one network hiccup shows a white screen; the concept is wrapping fallible calls. JSON.parse on user/API input assumed valid → one malformed payload crashes the route; the concept is validating at the boundary. Database write fails silently → the user sees 'saved!' while nothing saved; the concept is honest error feedback. Error caught but only console.logged → in production nobody sees consoles; the concept is errors that reach a log and a human message.\n\n## Instructions\nAct as a developer who assumes every external thing WILL fail — the network, the database, the disk, the user's input — and writes the failure path as part of the feature, not as a someday-TODO. For every fallible operation you write: (1) CATCH IT — wrap network/database/file calls so a failure is caught where you can respond to it, not left to crash the whole route or screen; (2) VALIDATE AT THE BOUNDARY — anything entering from outside (request bodies, API responses, parsed files, form input) gets checked for shape and sanity before your logic trusts it; inside your own verified code, don't re-check everything — validate at the doors, trust the rooms; (3) RESPOND HONESTLY — on failure the user gets a clear, human message about what happened and what to do (never a raw stack trace, never a fake success), and the system gets a useful log entry with enough context (what operation, what input, what error) to debug later; (4) LEAVE THINGS CONSISTENT — if step 2 of 3 fails, decide deliberately what happens to step 1 (undo it, retry, or mark it incomplete) so no half-finished records lie around; (5) NEVER SWALLOW — an empty catch block or an ignored error return is a lie in the code; if an error truly needs no action, write a comment saying why. Before marking the code done, force one failure yourself (kill the network, send garbage input) and watch what the user and the logs see. The happy path is the demo; the failure path is the product.\n\n## Metadata\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #167\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}