@deployanyway/error-translator 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +24 -7
- package/bin/cli.js +1 -1
- package/package.json +1 -1
- package/src/index.js +17 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0 — 2026-10-08
|
|
4
|
+
|
|
5
|
+
- Rubber-duck translations: Keep the debugging guidance, add workplace-safe rubber-duck commentary. Plain output remains the default.
|
|
6
|
+
- Add npm and CI badges to the published README.
|
|
7
|
+
|
|
3
8
|
## 0.1.1 — 2026-10-08
|
|
4
9
|
|
|
5
10
|
- Correct npm installation and npx documentation after the initial publication.
|
package/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# error-translator
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@deployanyway/error-translator)
|
|
4
|
+
[](https://github.com/DeployAnyway/error-translator/actions/workflows/ci.yml)
|
|
5
|
+
|
|
3
6
|
Plain-English Node.js error explanations and debugging tips, because the stack trace has chosen violence.
|
|
4
7
|
|
|
5
8
|
```text
|
|
@@ -70,7 +73,7 @@ An explicit code takes precedence, followed by a recognized name, then a
|
|
|
70
73
|
case-sensitive whole-word match in the message. Unknown errors return general
|
|
71
74
|
guidance with code `UNKNOWN`, or preserve an explicit unknown code.
|
|
72
75
|
Invalid input throws TypeError; unsupported modes throw RangeError.
|
|
73
|
-
|
|
76
|
+
Modes: `plain` (default) and `rubber-duck`, which preserves the guidance and adds commentary.
|
|
74
77
|
|
|
75
78
|
### `renderTranslation(result)`
|
|
76
79
|
|
|
@@ -95,12 +98,12 @@ and stack trace for context. No AI API or remote service is used.
|
|
|
95
98
|
|
|
96
99
|
`error-translator <code or message> [options]`
|
|
97
100
|
|
|
98
|
-
| Option | Behavior
|
|
99
|
-
| ----------------- |
|
|
100
|
-
| `--help`, `-h` | Show usage
|
|
101
|
-
| `--version`, `-v` | Show package version
|
|
102
|
-
| `--json` | Print structured JSON
|
|
103
|
-
| `--mode plain` | Select plain mode
|
|
101
|
+
| Option | Behavior |
|
|
102
|
+
| ----------------- | -------------------------------- |
|
|
103
|
+
| `--help`, `-h` | Show usage |
|
|
104
|
+
| `--version`, `-v` | Show package version |
|
|
105
|
+
| `--json` | Print structured JSON |
|
|
106
|
+
| `--mode plain` | Select plain or rubber-duck mode |
|
|
104
107
|
|
|
105
108
|
Quote messages containing spaces or shell punctuation. Use `--` before a message
|
|
106
109
|
beginning with a dash. No stdin support is included in the MVP.
|
|
@@ -141,3 +144,17 @@ are welcome.
|
|
|
141
144
|
- [doggo-log](https://github.com/DeployAnyway/doggo-log)
|
|
142
145
|
- [ship-it-meter](https://github.com/DeployAnyway/ship-it-meter)
|
|
143
146
|
- [bro-say](https://github.com/DeployAnyway/bro-say)
|
|
147
|
+
|
|
148
|
+
## Rubber-duck translations
|
|
149
|
+
|
|
150
|
+
Keep the debugging guidance, add workplace-safe rubber-duck commentary. Plain output remains the default.
|
|
151
|
+
|
|
152
|
+
```sh
|
|
153
|
+
npx @deployanyway/error-translator ECONNREFUSED --mode rubber-duck
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
API (import the named functions from this package):
|
|
157
|
+
|
|
158
|
+
```js
|
|
159
|
+
translateError("ENOENT", { mode: "rubber-duck" });
|
|
160
|
+
```
|
package/bin/cli.js
CHANGED
|
@@ -16,7 +16,7 @@ try {
|
|
|
16
16
|
});
|
|
17
17
|
if (values.help) {
|
|
18
18
|
console.log(
|
|
19
|
-
'Usage: error-translator <error code or quoted message> [--json] [--mode plain]\n\nTranslate errors into human-readable guidance.\n\nOptions:\n -h, --help Show help\n -v, --version Show version\n --json Print a structured JSON result\n --mode plain
|
|
19
|
+
'Usage: error-translator <error code or quoted message> [--json] [--mode plain|rubber-duck]\n\nTranslate errors into human-readable guidance.\n\nOptions:\n -h, --help Show help\n -v, --version Show version\n --json Print a structured JSON result\n --mode plain|rubber-duck Keep useful guidance; add duck commentary\n\nExamples:\n error-translator ECONNREFUSED\n error-translator "TypeError: value is not a function" --json\n\nExit codes: 0 translation/help/version; 2 invalid arguments.',
|
|
20
20
|
);
|
|
21
21
|
} else if (values.version) {
|
|
22
22
|
console.log(
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { definitions } from "./definitions.js";
|
|
2
|
+
const duckLines = {
|
|
3
|
+
ECONNREFUSED: "Your app knocked. The service has apparently gone for coffee.",
|
|
4
|
+
ENOENT: "The file is playing hide-and-seek. It is currently winning.",
|
|
5
|
+
EADDRINUSE: "Two servers reserved the same chair. Only one gets to sit.",
|
|
6
|
+
MODULE_NOT_FOUND:
|
|
7
|
+
"The dependency missed roll call. Check its invitation to node_modules.",
|
|
8
|
+
ERR_MODULE_NOT_FOUND:
|
|
9
|
+
"The module took a wrong turn. Extensions are street signs, not decorations.",
|
|
10
|
+
TypeError: "JavaScript received a surprise guest and forgot how to behave.",
|
|
11
|
+
};
|
|
2
12
|
|
|
3
13
|
/**
|
|
4
14
|
* Translate a nonempty string, Error, or error-like object with a code/name/message.
|
|
5
15
|
* Explicit codes take precedence over names and message matching.
|
|
6
16
|
* @param {string | Error | {code?: string, name?: string, message?: string}} error
|
|
7
|
-
* @param {{mode?: 'plain'}} [options]
|
|
17
|
+
* @param {{mode?: 'plain' | 'rubber-duck'}} [options]
|
|
8
18
|
* @returns {{code: string, title: string, explanation: string, likelyCauses: string[], suggestions: string[], mode: string}}
|
|
9
19
|
*/
|
|
10
20
|
export function translateError(error, options = {}) {
|
|
@@ -12,7 +22,8 @@ export function translateError(error, options = {}) {
|
|
|
12
22
|
throw new TypeError("Options must be an object.");
|
|
13
23
|
}
|
|
14
24
|
const mode = options.mode ?? "plain";
|
|
15
|
-
if (
|
|
25
|
+
if (!["plain", "rubber-duck"].includes(mode))
|
|
26
|
+
throw new RangeError("Supported modes: plain, rubber-duck.");
|
|
16
27
|
let code;
|
|
17
28
|
let name;
|
|
18
29
|
let message;
|
|
@@ -58,6 +69,10 @@ export function translateError(error, options = {}) {
|
|
|
58
69
|
return {
|
|
59
70
|
code: matched ?? "UNKNOWN",
|
|
60
71
|
...result,
|
|
72
|
+
explanation:
|
|
73
|
+
mode === "rubber-duck"
|
|
74
|
+
? `${result.explanation} ${Object.hasOwn(duckLines, matched ?? "") ? duckLines[matched] : "The duck recommends investigating before blaming the compiler."}`
|
|
75
|
+
: result.explanation,
|
|
61
76
|
likelyCauses: [...result.likelyCauses],
|
|
62
77
|
suggestions: [...result.suggestions],
|
|
63
78
|
mode,
|