why-is-it-broken
v1.0.1
Published
Understand common JavaScript errors with clear explanations and actionable suggestions.
Maintainers
Readme
why-is-it-broken
A lightweight JavaScript utility that explains common JavaScript errors and provides actionable suggestions to help you debug them.
Installation
npm install why-is-it-brokenUsage
import { explain } from "why-is-it-broken";
const error = new TypeError("Cannot read properties of undefined");
console.log(explain(error));Example output:
{
name: "TypeError",
message: "Cannot read properties of undefined",
explanation: "A TypeError occurs when a value is used in a way that its type does not support...",
suggestion: "Check the value and its type before using it..."
}Supported errors
TypeErrorReferenceErrorSyntaxErrorRangeErrorURIErrorEvalError- Generic
Error - Unknown custom error types (fallback explanation)
API
explain(error)
Accepts a JavaScript Error object and returns an object containing:
| Property | Description |
| --- | --- |
| name | Name/type of the error |
| message | Original error message |
| explanation | A plain-language explanation |
| suggestion | A suggested debugging step |
Passing a value that is not an Error object throws a TypeError.
Run tests
npm testRequirements
Node.js 18 or later.
License
MIT
