skills/bun-runtime-http-error-handling/SKILL.md
Learn how to handle errors in Bun's development server
npx skillsauth add jarle/bun-skills Bun Error HandlingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Learn how to handle errors in Bun's development server
To activate development mode, set development: true.
Bun.serve({
development: true, // [!code ++]
fetch(req) {
throw new Error("woops!");
},
});
In development mode, Bun will surface errors in-browser with a built-in error page.
<Frame><img src="https://mintcdn.com/bun-1dd33a4e/PY1574V41bdK8wNs/images/exception_page.png?fit=max&auto=format&n=PY1574V41bdK8wNs&q=85&s=26f9bec162e97288f1f0d736773b2b6e" alt="Bun's built-in 500 page" data-og-width="800" width="800" data-og-height="579" height="579" data-path="images/exception_page.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/bun-1dd33a4e/PY1574V41bdK8wNs/images/exception_page.png?w=280&fit=max&auto=format&n=PY1574V41bdK8wNs&q=85&s=77f5e65f2bd86c0c9f8aa548169764f6 280w, https://mintcdn.com/bun-1dd33a4e/PY1574V41bdK8wNs/images/exception_page.png?w=560&fit=max&auto=format&n=PY1574V41bdK8wNs&q=85&s=87988ad4288c5a0a06214ef0d7687f87 560w, https://mintcdn.com/bun-1dd33a4e/PY1574V41bdK8wNs/images/exception_page.png?w=840&fit=max&auto=format&n=PY1574V41bdK8wNs&q=85&s=5c605029819509b6e1dbba7ff684ef4f 840w, https://mintcdn.com/bun-1dd33a4e/PY1574V41bdK8wNs/images/exception_page.png?w=1100&fit=max&auto=format&n=PY1574V41bdK8wNs&q=85&s=5b1da6d3ac8b8583e9869385c0c9a8eb 1100w, https://mintcdn.com/bun-1dd33a4e/PY1574V41bdK8wNs/images/exception_page.png?w=1650&fit=max&auto=format&n=PY1574V41bdK8wNs&q=85&s=32e2a5d5903287da38118ea5016c44e1 1650w, https://mintcdn.com/bun-1dd33a4e/PY1574V41bdK8wNs/images/exception_page.png?w=2500&fit=max&auto=format&n=PY1574V41bdK8wNs&q=85&s=5015e6ff9569ae31243c6214021cd9f6 2500w" /></Frame>error callbackTo handle server-side errors, implement an error handler. This function should return a Response to serve to the client when an error occurs. This response will supersede Bun's default error page in development mode.
Bun.serve({
fetch(req) {
throw new Error("woops!");
},
error(error) {
return new Response(`<pre>${error}\n${error.stack}</pre>`, {
headers: {
"Content-Type": "text/html",
},
});
},
});
<Info>Learn more about debugging in Bun</Info>
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling