developer-error-message-translator 1.0.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/LICENSE +21 -0
- package/README.md +129 -0
- package/dist/bin/dev-translate.d.ts +2 -0
- package/dist/bin/dev-translate.js +27 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +21 -0
- package/dist/src/monitor.d.ts +5 -0
- package/dist/src/monitor.js +41 -0
- package/dist/src/patterns/api.d.ts +6 -0
- package/dist/src/patterns/api.js +45 -0
- package/dist/src/patterns/mongoose.d.ts +5 -0
- package/dist/src/patterns/mongoose.js +60 -0
- package/dist/src/patterns/network.d.ts +4 -0
- package/dist/src/patterns/network.js +44 -0
- package/dist/src/patterns/node.d.ts +7 -0
- package/dist/src/patterns/node.js +68 -0
- package/dist/src/patterns/rangeError.d.ts +4 -0
- package/dist/src/patterns/rangeError.js +41 -0
- package/dist/src/patterns/react.d.ts +7 -0
- package/dist/src/patterns/react.js +62 -0
- package/dist/src/patterns/referenceError.d.ts +4 -0
- package/dist/src/patterns/referenceError.js +45 -0
- package/dist/src/patterns/syntaxError.d.ts +5 -0
- package/dist/src/patterns/syntaxError.js +54 -0
- package/dist/src/patterns/typeError.d.ts +8 -0
- package/dist/src/patterns/typeError.js +98 -0
- package/dist/src/patterns/uriError.d.ts +3 -0
- package/dist/src/patterns/uriError.js +23 -0
- package/dist/src/translator.d.ts +2 -0
- package/dist/src/translator.js +44 -0
- package/dist/src/types.d.ts +9 -0
- package/dist/src/types.js +2 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Developer Error Message Translator Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# 🚀 Developer Error Message Translator
|
|
2
|
+
|
|
3
|
+
> **Turn cryptic error messages into plain English.**
|
|
4
|
+
> Instantly understand what went wrong, why it happened, and exactly how to fix it.
|
|
5
|
+
|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 🧐 The Problem
|
|
13
|
+
We've all been there. You run your code, and the console spits out:
|
|
14
|
+
`TypeError: Cannot read properties of undefined (reading 'map')`
|
|
15
|
+
`Error: Objects are not valid as a React child`
|
|
16
|
+
`ReferenceError: Cannot access 'count' before initialization`
|
|
17
|
+
|
|
18
|
+
These messages are accurate but **not helpful**. They tell you *what* broke, but rarely *why* or *how* to fix it.
|
|
19
|
+
|
|
20
|
+
## ✨ The Solution
|
|
21
|
+
**Developer Error Message Translator** takes these raw error strings and returns a structured, human-readable explanation with actionable fixes.
|
|
22
|
+
|
|
23
|
+
It supports:
|
|
24
|
+
* ⚛️ **React:** Hook rules, unique keys, re-renders, object rendering.
|
|
25
|
+
* 🟢 **Node.js:** Module errors, ESM vs CommonJS conflicts.
|
|
26
|
+
* 🌐 **Network/API:** Axios errors, Fetch failures, 404/500 codes.
|
|
27
|
+
* ⚡ **Core JS:** TypeErrors, ReferenceErrors, SyntaxErrors (including TDZ).
|
|
28
|
+
* 📦 **NPM:** Dependency conflicts (ERESOLVE), missing files (ENOENT).
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 📦 Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install developer-error-message-translator
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## 🛠️ Usage
|
|
41
|
+
|
|
42
|
+
### As a Function
|
|
43
|
+
Use it in your error boundaries, logging services, or CLI tools.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import translateError from 'developer-error-message-translator';
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
// Your buggy code
|
|
50
|
+
const user = null;
|
|
51
|
+
console.log(user.name);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const helpful = translateError(error.message);
|
|
54
|
+
|
|
55
|
+
console.log("🔍 Exploration:", helpful.explanation);
|
|
56
|
+
console.log("❓ Possible Causes:", helpful.causes);
|
|
57
|
+
console.log("✅ How to Fix:", helpful.fixes);
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Output:**
|
|
62
|
+
```text
|
|
63
|
+
🔍 Exploration: You are trying to access the property 'name' on a variable that is currently 'null'.
|
|
64
|
+
❓ Possible Causes:
|
|
65
|
+
- The variable hasn't been assigned a value yet.
|
|
66
|
+
- You might be trying to access data from an API call before it has finished loading.
|
|
67
|
+
✅ How to Fix:
|
|
68
|
+
- Use optional chaining: variable?.name
|
|
69
|
+
- Check if the variable exists before accessing 'name'.
|
|
70
|
+
- Initialize the variable with a default value.
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### CLI Tool
|
|
74
|
+
You can also valid errors directly from your terminal!
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npx dev-translate "Error: Objects are not valid as a React child"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 🏆 Supported Errors (30+ Scenarios)
|
|
83
|
+
|
|
84
|
+
### React
|
|
85
|
+
* Objects are not valid as a React child
|
|
86
|
+
* Too many re-renders
|
|
87
|
+
* Each child in a list should have a unique "key" prop
|
|
88
|
+
* Invalid hook call
|
|
89
|
+
* Cannot update a component while rendering a different component
|
|
90
|
+
|
|
91
|
+
### Node.js & NPM
|
|
92
|
+
* Cannot find module 'x'
|
|
93
|
+
* ReferenceError: require is not defined (ESM)
|
|
94
|
+
* SyntaxError: Unexpected token 'export' (CommonJS)
|
|
95
|
+
* ENOENT: no such file or directory
|
|
96
|
+
* npm ERR! ERESOLVE unable to resolve dependency tree
|
|
97
|
+
|
|
98
|
+
### API & Network
|
|
99
|
+
* TypeError: Failed to fetch
|
|
100
|
+
* AxiosError: Network Error
|
|
101
|
+
* Request failed with status code 404 / 500
|
|
102
|
+
* EADDRINUSE: address already in use
|
|
103
|
+
|
|
104
|
+
### Core JavaScript
|
|
105
|
+
* Cannot read property of undefined / null
|
|
106
|
+
* X is not a function
|
|
107
|
+
* Cannot destructure property
|
|
108
|
+
* Assignment to constant variable
|
|
109
|
+
* Cannot access 'X' before initialization (TDZ)
|
|
110
|
+
* Do not know how to serialize a BigInt
|
|
111
|
+
* Converting circular structure to JSON
|
|
112
|
+
* Unexpected token '<' (JSX in JS file)
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 🤝 Contributing
|
|
117
|
+
We love contributions! If you encounter an error that isn't translated well, please open an issue or submit a PR with a new pattern in `src/patterns`.
|
|
118
|
+
|
|
119
|
+
1. Fork the repo
|
|
120
|
+
2. Create your feature branch (`git checkout -b feature/new-error`)
|
|
121
|
+
3. Add your pattern and tests
|
|
122
|
+
4. Commit your changes
|
|
123
|
+
5. Push to the branch
|
|
124
|
+
6. Open a Pull Request
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## 📄 License
|
|
129
|
+
ISC
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const index_1 = require("../src/index");
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
const errorMessage = args.join(' ');
|
|
11
|
+
if (!errorMessage) {
|
|
12
|
+
console.log(chalk_1.default.red('Please provide an error message to translate.'));
|
|
13
|
+
console.log(chalk_1.default.yellow('Usage: dev-translate "Error message here"'));
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
const translation = (0, index_1.translateError)(errorMessage);
|
|
17
|
+
console.log(chalk_1.default.bold.blue('\n🔍 What went wrong:'));
|
|
18
|
+
console.log(translation.explanation);
|
|
19
|
+
if (translation.causes.length > 0) {
|
|
20
|
+
console.log(chalk_1.default.bold.yellow('\n❓ Why it happened:'));
|
|
21
|
+
translation.causes.forEach(cause => console.log(`- ${cause}`));
|
|
22
|
+
}
|
|
23
|
+
if (translation.fixes.length > 0) {
|
|
24
|
+
console.log(chalk_1.default.bold.green('\n✅ How to fix it:'));
|
|
25
|
+
translation.fixes.forEach(fix => console.log(`- ${fix}`));
|
|
26
|
+
}
|
|
27
|
+
console.log('\n');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./translator"), exports);
|
|
19
|
+
__exportStar(require("./monitor"), exports);
|
|
20
|
+
const translator_1 = require("./translator");
|
|
21
|
+
exports.default = translator_1.translateError;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = init;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const translator_1 = require("./translator");
|
|
9
|
+
/**
|
|
10
|
+
* Initializes the error translator to monitor uncaught exceptions and unhandled rejections.
|
|
11
|
+
* This checks for errors at runtime and prints a friendly explanation before exiting.
|
|
12
|
+
*/
|
|
13
|
+
function init() {
|
|
14
|
+
process.on('uncaughtException', (error) => {
|
|
15
|
+
handleError(error);
|
|
16
|
+
process.exit(1);
|
|
17
|
+
});
|
|
18
|
+
process.on('unhandledRejection', (reason) => {
|
|
19
|
+
handleError(reason);
|
|
20
|
+
process.exit(1);
|
|
21
|
+
});
|
|
22
|
+
console.log(chalk_1.default.gray('ℹ️ Developer Error Message Translator is monitoring your application...'));
|
|
23
|
+
}
|
|
24
|
+
function handleError(error) {
|
|
25
|
+
const errorMessage = error instanceof Error ? error.toString() : String(error);
|
|
26
|
+
const translation = (0, translator_1.translateError)(errorMessage);
|
|
27
|
+
console.error(chalk_1.default.bgRed.white.bold('\n 💥 APPLICATION CRASHED \n'));
|
|
28
|
+
console.error(chalk_1.default.bold.blue('🔍 What went wrong:'));
|
|
29
|
+
console.error(translation.explanation);
|
|
30
|
+
if (translation.causes.length > 0) {
|
|
31
|
+
console.error(chalk_1.default.bold.yellow('\n❓ Why it happened:'));
|
|
32
|
+
translation.causes.forEach(cause => console.error(`- ${cause}`));
|
|
33
|
+
}
|
|
34
|
+
if (translation.fixes.length > 0) {
|
|
35
|
+
console.error(chalk_1.default.bold.green('\n✅ How to fix it:'));
|
|
36
|
+
translation.fixes.forEach(fix => console.error(`- ${fix}`));
|
|
37
|
+
}
|
|
38
|
+
console.error('\n');
|
|
39
|
+
console.error(chalk_1.default.gray('Original Error Stack:'));
|
|
40
|
+
console.error(error);
|
|
41
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ErrorPattern } from '../types';
|
|
2
|
+
export declare const failedToFetchPattern: ErrorPattern;
|
|
3
|
+
export declare const axiosNetworkErrorPattern: ErrorPattern;
|
|
4
|
+
export declare const status404Pattern: ErrorPattern;
|
|
5
|
+
export declare const status500Pattern: ErrorPattern;
|
|
6
|
+
export declare const apiPatterns: ErrorPattern[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.apiPatterns = exports.status500Pattern = exports.status404Pattern = exports.axiosNetworkErrorPattern = exports.failedToFetchPattern = void 0;
|
|
4
|
+
exports.failedToFetchPattern = {
|
|
5
|
+
// Matches "TypeError: Failed to fetch"
|
|
6
|
+
regex: /TypeError: Failed to fetch/,
|
|
7
|
+
handler: () => ({
|
|
8
|
+
explanation: "The browser or runtime failed to make a network request.",
|
|
9
|
+
causes: ["The server is down or unreachable.", "You are blocked by CORS (Cross-Origin Resource Sharing).", "You are offline."],
|
|
10
|
+
fixes: ["Check if the backend server is running.", "Check the browser console for CORS errors.", "Verify your internet connection."]
|
|
11
|
+
})
|
|
12
|
+
};
|
|
13
|
+
exports.axiosNetworkErrorPattern = {
|
|
14
|
+
// Matches "AxiosError: Network Error"
|
|
15
|
+
regex: /AxiosError: Network Error/,
|
|
16
|
+
handler: () => ({
|
|
17
|
+
explanation: "Axios failed to connect to the server.",
|
|
18
|
+
causes: ["The server is offline.", "CORS issues.", "Invalid protocol (http vs https)."],
|
|
19
|
+
fixes: ["Check the server status.", "Verify the URL endpoint."]
|
|
20
|
+
})
|
|
21
|
+
};
|
|
22
|
+
exports.status404Pattern = {
|
|
23
|
+
// Matches "Request failed with status code 404"
|
|
24
|
+
regex: /Request failed with status code 404/,
|
|
25
|
+
handler: () => ({
|
|
26
|
+
explanation: "The requested resource was not found (404).",
|
|
27
|
+
causes: ["The API endpoint URL is incorrect.", "The ID you provided doesn't exist in the database."],
|
|
28
|
+
fixes: ["Check the URL path.", "Verify the resource ID."]
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
exports.status500Pattern = {
|
|
32
|
+
// Matches "Request failed with status code 500"
|
|
33
|
+
regex: /Request failed with status code 500/,
|
|
34
|
+
handler: () => ({
|
|
35
|
+
explanation: "The server encountered an internal error (500).",
|
|
36
|
+
causes: ["The backend code crashed.", "Database connection failed."],
|
|
37
|
+
fixes: ["Check the backend server logs for the real error."]
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
exports.apiPatterns = [
|
|
41
|
+
exports.failedToFetchPattern,
|
|
42
|
+
exports.axiosNetworkErrorPattern,
|
|
43
|
+
exports.status404Pattern,
|
|
44
|
+
exports.status500Pattern
|
|
45
|
+
];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ErrorPattern } from '../types';
|
|
2
|
+
export declare const mongooseCastErrorPattern: ErrorPattern;
|
|
3
|
+
export declare const mongooseDuplicateKeyPattern: ErrorPattern;
|
|
4
|
+
export declare const mongooseValidationErrorPattern: ErrorPattern;
|
|
5
|
+
export declare const mongoosePatterns: ErrorPattern[];
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mongoosePatterns = exports.mongooseValidationErrorPattern = exports.mongooseDuplicateKeyPattern = exports.mongooseCastErrorPattern = void 0;
|
|
4
|
+
exports.mongooseCastErrorPattern = {
|
|
5
|
+
// Matches "Cast to ObjectId failed for value..." or variants
|
|
6
|
+
regex: /Cast to \w+ failed for value/,
|
|
7
|
+
handler: (match) => {
|
|
8
|
+
return {
|
|
9
|
+
explanation: "A Mongoose 'CastError' occurred. You tried to use a value that couldn't be converted to the expected type (e.g., an invalid string for an ObjectId).",
|
|
10
|
+
causes: [
|
|
11
|
+
"You passed an invalid MongoDB ObjectId string to a query like `.findById()`.",
|
|
12
|
+
"You passed a string to a field expecting a Number or Date."
|
|
13
|
+
],
|
|
14
|
+
fixes: [
|
|
15
|
+
"Validate input IDs to ensure they are 24-character hex strings.",
|
|
16
|
+
"Check that your request body matches the schema types."
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.mongooseDuplicateKeyPattern = {
|
|
22
|
+
// Matches "E11000 duplicate key error..."
|
|
23
|
+
regex: /E11000 duplicate key error/,
|
|
24
|
+
handler: (match) => {
|
|
25
|
+
return {
|
|
26
|
+
explanation: "A MongoDB 'Duplicate Key' error occurred. You tried to save a record with a field that must be unique, but it already exists.",
|
|
27
|
+
causes: [
|
|
28
|
+
"You are registering a user with an email that is already in the database.",
|
|
29
|
+
"You are creating a document with a unique index that conflicts with existing data."
|
|
30
|
+
],
|
|
31
|
+
fixes: [
|
|
32
|
+
"Check if the record already exists before creating it.",
|
|
33
|
+
"Catch this error and show a user-friendly message like 'Email already taken'."
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.mongooseValidationErrorPattern = {
|
|
39
|
+
// Matches "ValidationError: ..."
|
|
40
|
+
regex: /ValidationError: /,
|
|
41
|
+
handler: (match) => {
|
|
42
|
+
return {
|
|
43
|
+
explanation: "A Mongoose 'ValidationError' occurred. The data you tried to save didn't match the schema requirements.",
|
|
44
|
+
causes: [
|
|
45
|
+
"A required field is missing.",
|
|
46
|
+
"A field value is shorter/longer than the defined minlength/maxlength.",
|
|
47
|
+
"Enum validation failed."
|
|
48
|
+
],
|
|
49
|
+
fixes: [
|
|
50
|
+
"Check the error details to see which field failed.",
|
|
51
|
+
"Ensure your request body provides all required fields."
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.mongoosePatterns = [
|
|
57
|
+
exports.mongooseCastErrorPattern,
|
|
58
|
+
exports.mongooseDuplicateKeyPattern,
|
|
59
|
+
exports.mongooseValidationErrorPattern
|
|
60
|
+
];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.networkPatterns = exports.connectionRefusedPattern = exports.addressInUsePattern = void 0;
|
|
4
|
+
exports.addressInUsePattern = {
|
|
5
|
+
// Matches "Error: listen EADDRINUSE: address already in use :::3000"
|
|
6
|
+
regex: /EADDRINUSE/,
|
|
7
|
+
handler: (match) => {
|
|
8
|
+
return {
|
|
9
|
+
explanation: "The network port you are trying to use is already taken by another process.",
|
|
10
|
+
causes: [
|
|
11
|
+
"You have the server running in another terminal window.",
|
|
12
|
+
"Another application is using the same port (e.g., 3000 or 8080)."
|
|
13
|
+
],
|
|
14
|
+
fixes: [
|
|
15
|
+
"Close the other terminal where the server is running.",
|
|
16
|
+
"Kill the process using the port (e.g., `kill -9 <PID>` or task manager).",
|
|
17
|
+
"Change the port number in your code or `.env` file."
|
|
18
|
+
]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.connectionRefusedPattern = {
|
|
23
|
+
// Matches "Error: connect ECONNREFUSED 127.0.0.1:27017"
|
|
24
|
+
regex: /ECONNREFUSED/,
|
|
25
|
+
handler: (match) => {
|
|
26
|
+
return {
|
|
27
|
+
explanation: "The connection to the server or database was refused. It couldn't be reached.",
|
|
28
|
+
causes: [
|
|
29
|
+
"The database server (e.g., MongoDB) is not running.",
|
|
30
|
+
"You are using the wrong host or port.",
|
|
31
|
+
"A firewall is blocking the connection."
|
|
32
|
+
],
|
|
33
|
+
fixes: [
|
|
34
|
+
"Ensure your database server is running (`mongod`, `postgres`, etc.).",
|
|
35
|
+
"Check your connection string (URI) for typos.",
|
|
36
|
+
"Check if the service is reachable."
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.networkPatterns = [
|
|
42
|
+
exports.addressInUsePattern,
|
|
43
|
+
exports.connectionRefusedPattern
|
|
44
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ErrorPattern } from '../types';
|
|
2
|
+
export declare const moduleNotFoundPattern: ErrorPattern;
|
|
3
|
+
export declare const requireNotDefinedPattern: ErrorPattern;
|
|
4
|
+
export declare const unexpectedExportPattern: ErrorPattern;
|
|
5
|
+
export declare const enoentPattern: ErrorPattern;
|
|
6
|
+
export declare const npmResolvePattern: ErrorPattern;
|
|
7
|
+
export declare const nodePatterns: ErrorPattern[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nodePatterns = exports.npmResolvePattern = exports.enoentPattern = exports.unexpectedExportPattern = exports.requireNotDefinedPattern = exports.moduleNotFoundPattern = void 0;
|
|
4
|
+
exports.moduleNotFoundPattern = {
|
|
5
|
+
// Matches "Error: Cannot find module 'x'"
|
|
6
|
+
regex: /Cannot find module '([^']+)'/,
|
|
7
|
+
handler: (match) => {
|
|
8
|
+
const moduleName = match[1];
|
|
9
|
+
return {
|
|
10
|
+
explanation: `Node.js cannot find the module '${moduleName}'.`,
|
|
11
|
+
causes: [
|
|
12
|
+
`You forgot to install the package: \`npm install ${moduleName}\`.`,
|
|
13
|
+
"You misspelled the import path.",
|
|
14
|
+
"You are trying to import a relative file without `./` (e.g., `import user from 'user'` instead of `'./user'`)."
|
|
15
|
+
],
|
|
16
|
+
fixes: [
|
|
17
|
+
`Run \`npm install ${moduleName}\`.`,
|
|
18
|
+
"Check your import path."
|
|
19
|
+
]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.requireNotDefinedPattern = {
|
|
24
|
+
// Matches "ReferenceError: require is not defined"
|
|
25
|
+
regex: /require is not defined/,
|
|
26
|
+
handler: () => ({
|
|
27
|
+
explanation: "You are trying to use CommonJS `require()` in an ES Module environment.",
|
|
28
|
+
causes: ["Your `package.json` has `\"type\": \"module\"` but you are using `require()`.", "You are using a `.mjs` file extension."],
|
|
29
|
+
fixes: ["Use `import` statements instead.", "Remove `\"type\": \"module\"` from package.json if you want to use CommonJS."]
|
|
30
|
+
})
|
|
31
|
+
};
|
|
32
|
+
exports.unexpectedExportPattern = {
|
|
33
|
+
// Matches "SyntaxError: Unexpected token 'export'"
|
|
34
|
+
regex: /Unexpected token 'export'/,
|
|
35
|
+
handler: () => ({
|
|
36
|
+
explanation: "You are trying to use ES Module `export` syntax in a CommonJS environment.",
|
|
37
|
+
causes: ["You are attempting to use `export` in a generic script or CommonJS file."],
|
|
38
|
+
fixes: ["Add `\"type\": \"module\"` to your `package.json`.", "Use `module.exports = ...` instead."]
|
|
39
|
+
})
|
|
40
|
+
};
|
|
41
|
+
exports.enoentPattern = {
|
|
42
|
+
// Matches "ENOENT: no such file or directory, open '...'"
|
|
43
|
+
regex: /ENOENT: no such file or directory, open '([^']+)'/,
|
|
44
|
+
handler: (match) => {
|
|
45
|
+
const filePath = match[1];
|
|
46
|
+
return {
|
|
47
|
+
explanation: `The system cannot find the file or directory at '${filePath}'.`,
|
|
48
|
+
causes: ["The file path is incorrect.", "The file hasn't been created yet.", "You are running the script from the wrong directory."],
|
|
49
|
+
fixes: ["Check that the file exists.", "Verify your current working directory."]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
exports.npmResolvePattern = {
|
|
54
|
+
// Matches "npm ERR! ERESOLVE unable to resolve dependency tree"
|
|
55
|
+
regex: /ERESOLVE unable to resolve dependency tree/,
|
|
56
|
+
handler: () => ({
|
|
57
|
+
explanation: "NPM is facing a conflict between dependencies (e.g., Package A needs React 17, but Packet B needs React 18).",
|
|
58
|
+
causes: ["Incompatible peer dependencies."],
|
|
59
|
+
fixes: ["Try running `npm install --legacy-peer-deps`.", "Update your dependencies to compatible versions."]
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
exports.nodePatterns = [
|
|
63
|
+
exports.moduleNotFoundPattern,
|
|
64
|
+
exports.requireNotDefinedPattern,
|
|
65
|
+
exports.unexpectedExportPattern,
|
|
66
|
+
exports.enoentPattern,
|
|
67
|
+
exports.npmResolvePattern
|
|
68
|
+
];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rangeErrorPatterns = exports.invalidArrayLengthPattern = exports.stackOverflowPattern = void 0;
|
|
4
|
+
exports.stackOverflowPattern = {
|
|
5
|
+
// Matches "RangeError: Maximum call stack size exceeded"
|
|
6
|
+
regex: /RangeError: Maximum call stack size exceeded/,
|
|
7
|
+
handler: (match) => {
|
|
8
|
+
return {
|
|
9
|
+
explanation: "The function called itself too many times (infinite recursion) or the call stack is too deep.",
|
|
10
|
+
causes: [
|
|
11
|
+
"You have a recursive function that is missing a base case (an exit condition).",
|
|
12
|
+
"Two functions are calling each other in a loop."
|
|
13
|
+
],
|
|
14
|
+
fixes: [
|
|
15
|
+
"Check your recursive functions to ensure they have a condition to stop.",
|
|
16
|
+
"Use a loop instead of recursion if possible for deep iterations."
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.invalidArrayLengthPattern = {
|
|
22
|
+
// Matches "RangeError: Invalid array length"
|
|
23
|
+
regex: /RangeError: Invalid array length/,
|
|
24
|
+
handler: (match) => {
|
|
25
|
+
return {
|
|
26
|
+
explanation: "You tried to create an Array with an invalid length (e.g., negative or too large).",
|
|
27
|
+
causes: [
|
|
28
|
+
"You passed a negative number to `new Array()`.",
|
|
29
|
+
"You passed a non-integer float to `new Array()`."
|
|
30
|
+
],
|
|
31
|
+
fixes: [
|
|
32
|
+
"Ensure the array length is a positive integer.",
|
|
33
|
+
"Check variables passed to the Array constructor."
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.rangeErrorPatterns = [
|
|
39
|
+
exports.stackOverflowPattern,
|
|
40
|
+
exports.invalidArrayLengthPattern
|
|
41
|
+
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ErrorPattern } from '../types';
|
|
2
|
+
export declare const objectsNotValidChildPattern: ErrorPattern;
|
|
3
|
+
export declare const tooManyRerendersPattern: ErrorPattern;
|
|
4
|
+
export declare const uniqueKeyPattern: ErrorPattern;
|
|
5
|
+
export declare const invalidHookCallPattern: ErrorPattern;
|
|
6
|
+
export declare const updateWhileRenderingPattern: ErrorPattern;
|
|
7
|
+
export declare const reactPatterns: ErrorPattern[];
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reactPatterns = exports.updateWhileRenderingPattern = exports.invalidHookCallPattern = exports.uniqueKeyPattern = exports.tooManyRerendersPattern = exports.objectsNotValidChildPattern = void 0;
|
|
4
|
+
exports.objectsNotValidChildPattern = {
|
|
5
|
+
// Matches "Error: Objects are not valid as a React child..."
|
|
6
|
+
regex: /Objects are not valid as a React child/,
|
|
7
|
+
handler: () => ({
|
|
8
|
+
explanation: "You are trying to render a JavaScript Object directly in JSX. React only renders strings, numbers, or elements.",
|
|
9
|
+
causes: ["You used `<div>{obj}</div>` instead of `<div>{obj.name}</div>`.", "You forgot to map over an array."],
|
|
10
|
+
fixes: ["Render a specific property.", "Use `JSON.stringify()` for debugging.", "Use `.map()` for arrays."]
|
|
11
|
+
})
|
|
12
|
+
};
|
|
13
|
+
exports.tooManyRerendersPattern = {
|
|
14
|
+
// Matches "Error: Too many re-renders"
|
|
15
|
+
regex: /Too many re-renders/,
|
|
16
|
+
handler: () => ({
|
|
17
|
+
explanation: "Your component is caught in an infinite update loop.",
|
|
18
|
+
causes: ["You are setting state directly inside the render body (e.g., `setCount(0)`).", "You have a `useEffect` without a dependency array that updates state."],
|
|
19
|
+
fixes: ["Wrap state updates in `useEffect` or event handlers.", "Check your `useEffect` dependency array."]
|
|
20
|
+
})
|
|
21
|
+
};
|
|
22
|
+
exports.uniqueKeyPattern = {
|
|
23
|
+
// Matches "Warning: Each child in a list should have a unique 'key' prop"
|
|
24
|
+
regex: /Each child in a list should have a unique "key" prop/,
|
|
25
|
+
handler: () => ({
|
|
26
|
+
explanation: "You are rendering a list of elements but forgot to give each one a unique `key` prop.",
|
|
27
|
+
causes: ["You are using `.map()` without adding `key={id}` to the returned element."],
|
|
28
|
+
fixes: ["Add a unique `key` prop (e.g., `<li key={item.id}>`).", "Avoid using index as a key if the list can change order."]
|
|
29
|
+
})
|
|
30
|
+
};
|
|
31
|
+
exports.invalidHookCallPattern = {
|
|
32
|
+
// Matches "Error: Invalid hook call"
|
|
33
|
+
regex: /Invalid hook call/,
|
|
34
|
+
handler: () => ({
|
|
35
|
+
explanation: "You tried to use a React Hook (like `useState` or `useEffect`) in an invalid place.",
|
|
36
|
+
causes: [
|
|
37
|
+
"You called a hook inside a loop, condition, or nested function.",
|
|
38
|
+
"You called a hook from a regular JavaScript function (not a component).",
|
|
39
|
+
"You likely have mismatched versions of React and React DOM."
|
|
40
|
+
],
|
|
41
|
+
fixes: [
|
|
42
|
+
"Move the hook to the top level of your function component.",
|
|
43
|
+
"Ensure you aren't calling hooks conditionally."
|
|
44
|
+
]
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
exports.updateWhileRenderingPattern = {
|
|
48
|
+
// Matches "Warning: Cannot update a component (`X`) while rendering a different component (`Y`)"
|
|
49
|
+
regex: /Cannot update a component .* while rendering a different component/,
|
|
50
|
+
handler: () => ({
|
|
51
|
+
explanation: "You are triggering a state update in a parent component purely as a side effect of a child rendering.",
|
|
52
|
+
causes: ["A child component is calling a state-setter prop (e.g., `setParentState`) directly in its body."],
|
|
53
|
+
fixes: ["Wrap the update in `useEffect`.", "Move the logic to an event handler."]
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
exports.reactPatterns = [
|
|
57
|
+
exports.objectsNotValidChildPattern,
|
|
58
|
+
exports.tooManyRerendersPattern,
|
|
59
|
+
exports.uniqueKeyPattern,
|
|
60
|
+
exports.invalidHookCallPattern,
|
|
61
|
+
exports.updateWhileRenderingPattern
|
|
62
|
+
];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.referenceErrorPatterns = exports.accessBeforeInitPattern = exports.notDefinedPattern = void 0;
|
|
4
|
+
exports.notDefinedPattern = {
|
|
5
|
+
// Matches "ReferenceError: x is not defined"
|
|
6
|
+
regex: /ReferenceError: (.+) is not defined/,
|
|
7
|
+
handler: (match) => {
|
|
8
|
+
const variableName = match[1];
|
|
9
|
+
return {
|
|
10
|
+
explanation: `The variable '${variableName}' is being used, but it hasn't been defined or is out of scope.`,
|
|
11
|
+
causes: [
|
|
12
|
+
"You misspelled the variable name.",
|
|
13
|
+
"You are using a variable declared in a different function or block (scope issue).",
|
|
14
|
+
"You forgot to import the variable."
|
|
15
|
+
],
|
|
16
|
+
fixes: [
|
|
17
|
+
`Check the spelling of '${variableName}'.`,
|
|
18
|
+
"Ensure the variable is declared (let, const, var) before use.",
|
|
19
|
+
"Check if you need to import it from another file."
|
|
20
|
+
]
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
exports.accessBeforeInitPattern = {
|
|
25
|
+
// Matches "ReferenceError: Cannot access 'x' before initialization"
|
|
26
|
+
regex: /Cannot access '([^']+)' before initialization/,
|
|
27
|
+
handler: (match) => {
|
|
28
|
+
const variableName = match[1];
|
|
29
|
+
return {
|
|
30
|
+
explanation: `You are trying to use the variable '${variableName}' before it has been initialized in the code.`,
|
|
31
|
+
causes: [
|
|
32
|
+
"You are using a `let` or `const` variable before the line where it is declared.",
|
|
33
|
+
"You have a circular dependency where two files import each other."
|
|
34
|
+
],
|
|
35
|
+
fixes: [
|
|
36
|
+
"Move the declaration of the variable above the line where you use it.",
|
|
37
|
+
"Check for circular dependencies in your imports."
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.referenceErrorPatterns = [
|
|
43
|
+
exports.notDefinedPattern,
|
|
44
|
+
exports.accessBeforeInitPattern
|
|
45
|
+
];
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ErrorPattern } from '../types';
|
|
2
|
+
export declare const jsonParsePattern: ErrorPattern;
|
|
3
|
+
export declare const unexpectedTokenPattern: ErrorPattern;
|
|
4
|
+
export declare const unexpectedTokenReactPattern: ErrorPattern;
|
|
5
|
+
export declare const syntaxErrorPatterns: ErrorPattern[];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.syntaxErrorPatterns = exports.unexpectedTokenReactPattern = exports.unexpectedTokenPattern = exports.jsonParsePattern = void 0;
|
|
4
|
+
exports.jsonParsePattern = {
|
|
5
|
+
// Matches "SyntaxError: Unexpected token X in JSON at position Y"
|
|
6
|
+
// OR "SyntaxError: Unexpected end of JSON input"
|
|
7
|
+
regex: /Unexpected (token|end) .* JSON/,
|
|
8
|
+
handler: (match) => {
|
|
9
|
+
return {
|
|
10
|
+
explanation: "The text you are trying to parse as JSON is not valid JSON.",
|
|
11
|
+
causes: [
|
|
12
|
+
"You are trying to parse an HTML response (common when 404/500 errors return HTML pages).",
|
|
13
|
+
"The JSON string is empty or incomplete.",
|
|
14
|
+
"The JSON is malformed (e.g., trailing commas, single quotes instead of double quotes)."
|
|
15
|
+
],
|
|
16
|
+
fixes: [
|
|
17
|
+
"Log the response text before parsing it to see what it actually contains.",
|
|
18
|
+
"Check if the API returned an error page (HTML) instead of JSON."
|
|
19
|
+
]
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
exports.unexpectedTokenPattern = {
|
|
24
|
+
// Matches "SyntaxError: Unexpected token }"
|
|
25
|
+
regex: /Unexpected token ('|")?([^'"]+)('|")?/,
|
|
26
|
+
handler: (match) => {
|
|
27
|
+
const token = match[2];
|
|
28
|
+
return {
|
|
29
|
+
explanation: `The code contains a character or sequence '${token}' that the JavaScript engine didn't expect.`,
|
|
30
|
+
causes: [
|
|
31
|
+
`You might be missing a closing brace '}', parenthesis ')', or bracket ']'.`,
|
|
32
|
+
"You might have an extra comma or semicolon."
|
|
33
|
+
],
|
|
34
|
+
fixes: [
|
|
35
|
+
"Check for mismatched brackets or parentheses.",
|
|
36
|
+
"Look for extra characters near usage of the reported token."
|
|
37
|
+
]
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.unexpectedTokenReactPattern = {
|
|
42
|
+
// Matches "SyntaxError: Unexpected token '<'"
|
|
43
|
+
regex: /Unexpected token '<'/,
|
|
44
|
+
handler: () => ({
|
|
45
|
+
explanation: "You are trying to use JSX (like `<div>`) in a file that is not compiled as React/JSX.",
|
|
46
|
+
causes: ["You are using a `.js` extension instead of `.jsx` or `.tsx`.", "Your build tool (Babel/Webpack) is not configured for React."],
|
|
47
|
+
fixes: ["Rename the file to `.jsx` or `.tsx`.", "Check your Babel configuration."]
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
exports.syntaxErrorPatterns = [
|
|
51
|
+
exports.jsonParsePattern,
|
|
52
|
+
exports.unexpectedTokenReactPattern, // specific check first
|
|
53
|
+
exports.unexpectedTokenPattern
|
|
54
|
+
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ErrorPattern } from '../types';
|
|
2
|
+
export declare const cannotReadPropertyPattern: ErrorPattern;
|
|
3
|
+
export declare const isNotAFunctionPattern: ErrorPattern;
|
|
4
|
+
export declare const destructuringPattern: ErrorPattern;
|
|
5
|
+
export declare const assignmentToConstantPattern: ErrorPattern;
|
|
6
|
+
export declare const bigIntSerializationPattern: ErrorPattern;
|
|
7
|
+
export declare const circularJsonPattern: ErrorPattern;
|
|
8
|
+
export declare const typeErrorPatterns: ErrorPattern[];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typeErrorPatterns = exports.circularJsonPattern = exports.bigIntSerializationPattern = exports.assignmentToConstantPattern = exports.destructuringPattern = exports.isNotAFunctionPattern = exports.cannotReadPropertyPattern = void 0;
|
|
4
|
+
exports.cannotReadPropertyPattern = {
|
|
5
|
+
// Matches "Cannot read property 'x' of undefined" OR "of null"
|
|
6
|
+
regex: /Cannot read propert(?:y|ies) (?:'([^']+)' )?of (undefined|null)(?: \(reading '([^']+)'\))?/,
|
|
7
|
+
handler: (match) => {
|
|
8
|
+
const property = match[1] || match[3] || 'unknown';
|
|
9
|
+
const valueType = match[2]; // 'undefined' or 'null'
|
|
10
|
+
return {
|
|
11
|
+
explanation: `You are trying to access the property '${property}' on a variable that is currently '${valueType}'.`,
|
|
12
|
+
causes: [
|
|
13
|
+
"The variable hasn't been assigned a value yet.",
|
|
14
|
+
"You might be trying to access data from an API call before it has finished loading.",
|
|
15
|
+
"You are accessing a nested property (e.g., user.address.city) where the parent (user.address) doesn't exist."
|
|
16
|
+
],
|
|
17
|
+
fixes: [
|
|
18
|
+
`Use optional chaining: variable?.${property}`,
|
|
19
|
+
`Check if the variable exists before accessing '${property}': if (variable) { ... }`,
|
|
20
|
+
"Initialize the variable with a default value."
|
|
21
|
+
]
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.isNotAFunctionPattern = {
|
|
26
|
+
// Matches "TypeError: X is not a function"
|
|
27
|
+
regex: /TypeError: (.+) is not a function/,
|
|
28
|
+
handler: (match) => {
|
|
29
|
+
const variableName = match[1];
|
|
30
|
+
return {
|
|
31
|
+
explanation: `You are trying to call '${variableName}' as a function, but it is not one.`,
|
|
32
|
+
causes: [
|
|
33
|
+
`'${variableName}' might be undefined or null.`,
|
|
34
|
+
`'${variableName}' might be an object or a string, not a function.`,
|
|
35
|
+
"You might have a typo in the function name."
|
|
36
|
+
],
|
|
37
|
+
fixes: [
|
|
38
|
+
`Log '${variableName}' to see what it actually contains.`,
|
|
39
|
+
"Check if you imported the function correctly."
|
|
40
|
+
]
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.destructuringPattern = {
|
|
45
|
+
// Matches "TypeError: Cannot destructure property 'name' of 'user' as it is undefined"
|
|
46
|
+
regex: /Cannot destructure property '([^']+)' of '([^']+)' as it is (undefined|null)/,
|
|
47
|
+
handler: (match) => {
|
|
48
|
+
const property = match[1];
|
|
49
|
+
const variableName = match[2];
|
|
50
|
+
const valueType = match[3];
|
|
51
|
+
return {
|
|
52
|
+
explanation: `You tried to extract (destructure) the property '${property}' from '${variableName}', but '${variableName}' is ${valueType}.`,
|
|
53
|
+
causes: [
|
|
54
|
+
`The variable '${variableName}' is ${valueType}, so you cannot pull properties from it.`,
|
|
55
|
+
"An API response might be missing the expected object structure."
|
|
56
|
+
],
|
|
57
|
+
fixes: [
|
|
58
|
+
`Ensure '${variableName}' is defined before destructuring.`,
|
|
59
|
+
`Use default values: const { ${property} = 'default' } = ${variableName} || {};`
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.assignmentToConstantPattern = {
|
|
65
|
+
// Matches "TypeError: Assignment to constant variable."
|
|
66
|
+
regex: /Assignment to constant variable/,
|
|
67
|
+
handler: () => ({
|
|
68
|
+
explanation: "You are trying to reassign a value to a variable declared with `const`.",
|
|
69
|
+
causes: ["You used `const` but then tried to change the value later (e.g., `x = 10`)."],
|
|
70
|
+
fixes: ["Change `const` to `let` if you need to reassign it.", "Don't reassign the variable."]
|
|
71
|
+
})
|
|
72
|
+
};
|
|
73
|
+
exports.bigIntSerializationPattern = {
|
|
74
|
+
// Matches "TypeError: Do not know how to serialize a BigInt"
|
|
75
|
+
regex: /Do not know how to serialize a BigInt/,
|
|
76
|
+
handler: () => ({
|
|
77
|
+
explanation: "You are trying to use `JSON.stringify()` on an object containing a BigInt (e.g., `10n`). JSON doesn't support BigInt.",
|
|
78
|
+
causes: ["Your data contains BigInt values."],
|
|
79
|
+
fixes: ["Convert BigInts to strings or numbers before stringifying: `.toString()`."]
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
exports.circularJsonPattern = {
|
|
83
|
+
// Matches "TypeError: Converting circular structure to JSON"
|
|
84
|
+
regex: /Converting circular structure to JSON/,
|
|
85
|
+
handler: () => ({
|
|
86
|
+
explanation: "You are trying to `JSON.stringify()` an object that refers to itself.",
|
|
87
|
+
causes: ["Object A references Object B, and Object B references Object A."],
|
|
88
|
+
fixes: ["Remove the circular reference.", "Use a custom serializer (replacer function) for `JSON.stringify`."]
|
|
89
|
+
})
|
|
90
|
+
};
|
|
91
|
+
exports.typeErrorPatterns = [
|
|
92
|
+
exports.cannotReadPropertyPattern,
|
|
93
|
+
exports.isNotAFunctionPattern,
|
|
94
|
+
exports.destructuringPattern,
|
|
95
|
+
exports.assignmentToConstantPattern,
|
|
96
|
+
exports.bigIntSerializationPattern,
|
|
97
|
+
exports.circularJsonPattern
|
|
98
|
+
];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uriErrorPatterns = exports.uriMalformedPattern = void 0;
|
|
4
|
+
exports.uriMalformedPattern = {
|
|
5
|
+
// Matches "URIError: URI malformed"
|
|
6
|
+
regex: /URIError: URI malformed/,
|
|
7
|
+
handler: (match) => {
|
|
8
|
+
return {
|
|
9
|
+
explanation: "The URL encoding or decoding failed because the sequence was not valid.",
|
|
10
|
+
causes: [
|
|
11
|
+
"You passed a string with a '%' character not followed by two hex digits to `decodeURIComponent` or `decodeURI`.",
|
|
12
|
+
"You are trying to parse a URL param that wasn't encoded properly."
|
|
13
|
+
],
|
|
14
|
+
fixes: [
|
|
15
|
+
"Ensure strings containing '%' are properly escaped (e.g., use '%25' for a literal percent sign).",
|
|
16
|
+
"Check that the input to decodeURIComponent is a valid UTF-8 sequence."
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.uriErrorPatterns = [
|
|
22
|
+
exports.uriMalformedPattern
|
|
23
|
+
];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.translateError = translateError;
|
|
4
|
+
const typeError_1 = require("./patterns/typeError");
|
|
5
|
+
const referenceError_1 = require("./patterns/referenceError");
|
|
6
|
+
const syntaxError_1 = require("./patterns/syntaxError");
|
|
7
|
+
const uriError_1 = require("./patterns/uriError");
|
|
8
|
+
const rangeError_1 = require("./patterns/rangeError");
|
|
9
|
+
const mongoose_1 = require("./patterns/mongoose");
|
|
10
|
+
const network_1 = require("./patterns/network");
|
|
11
|
+
const react_1 = require("./patterns/react");
|
|
12
|
+
const node_1 = require("./patterns/node");
|
|
13
|
+
const api_1 = require("./patterns/api");
|
|
14
|
+
const allPatterns = [
|
|
15
|
+
// Specific frameworks/environments first
|
|
16
|
+
...node_1.nodePatterns,
|
|
17
|
+
...api_1.apiPatterns,
|
|
18
|
+
...react_1.reactPatterns,
|
|
19
|
+
...mongoose_1.mongoosePatterns,
|
|
20
|
+
...network_1.networkPatterns,
|
|
21
|
+
// Generic JS errors last
|
|
22
|
+
...typeError_1.typeErrorPatterns,
|
|
23
|
+
...referenceError_1.referenceErrorPatterns,
|
|
24
|
+
...syntaxError_1.syntaxErrorPatterns,
|
|
25
|
+
...uriError_1.uriErrorPatterns,
|
|
26
|
+
...rangeError_1.rangeErrorPatterns
|
|
27
|
+
];
|
|
28
|
+
function translateError(errorMessage) {
|
|
29
|
+
for (const pattern of allPatterns) {
|
|
30
|
+
const match = errorMessage.match(pattern.regex);
|
|
31
|
+
if (match) {
|
|
32
|
+
return pattern.handler(match);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Fallback for unknown errors
|
|
36
|
+
return {
|
|
37
|
+
explanation: "I couldn't recognize this specific error message.",
|
|
38
|
+
causes: ["This might be a custom error or a less common edge case."],
|
|
39
|
+
fixes: [
|
|
40
|
+
"Copy and paste the error into Google or StackOverflow.",
|
|
41
|
+
"Check the line number mentioned in the stack trace to narrow down the issue."
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "developer-error-message-translator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Translate cryptic developer errors (React, Node, TypeScript) into plain English with causes and fixes.",
|
|
5
|
+
"main": "dist/src/index.js",
|
|
6
|
+
"types": "dist/src/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"dev-translate": "./dist/bin/dev-translate.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"test": "jest",
|
|
17
|
+
"start": "ts-node bin/dev-translate.ts"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"error",
|
|
21
|
+
"translator",
|
|
22
|
+
"debugging",
|
|
23
|
+
"react",
|
|
24
|
+
"node",
|
|
25
|
+
"typescript",
|
|
26
|
+
"developer-tools"
|
|
27
|
+
],
|
|
28
|
+
"author": "Antigravity",
|
|
29
|
+
"license": "ISC",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"chalk": "^4.1.2"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/jest": "^29.5.12",
|
|
35
|
+
"@types/node": "^20.11.24",
|
|
36
|
+
"jest": "^29.7.0",
|
|
37
|
+
"ts-jest": "^29.1.2",
|
|
38
|
+
"ts-node": "^10.9.2",
|
|
39
|
+
"typescript": "^5.3.3"
|
|
40
|
+
}
|
|
41
|
+
}
|