nodewise 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 +97 -0
- package/USER_MANUAL.md +106 -0
- package/bin/nodewise.js +166 -0
- package/examples/express-server.js +70 -0
- package/examples/express-with-errors.js +63 -0
- package/examples/module-not-found.js +9 -0
- package/examples/reference-error.js +9 -0
- package/examples/syntax-error.js +11 -0
- package/examples/type-error.js +10 -0
- package/examples/working-app.js +35 -0
- package/package.json +49 -0
- package/src/config.js +167 -0
- package/src/errorPatterns.js +3253 -0
- package/src/errorWrapper.js +43 -0
- package/src/explainer/gemini.js +212 -0
- package/src/explainer/index.js +51 -0
- package/src/explainer/interactive.js +123 -0
- package/src/explainer/normal.js +27 -0
- package/src/expressErrorHandler.js +68 -0
- package/src/index.js +14 -0
- package/src/runner.js +243 -0
- package/src/setup.js +98 -0
|
@@ -0,0 +1,3253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* errorPatterns.js
|
|
3
|
+
*
|
|
4
|
+
* Central repository of error patterns and explanations.
|
|
5
|
+
* This is used by the normal mode explainer to identify and explain common errors.
|
|
6
|
+
*
|
|
7
|
+
* Pattern format:
|
|
8
|
+
* {
|
|
9
|
+
* name: "ERROR_NAME",
|
|
10
|
+
* match: /regex pattern/,
|
|
11
|
+
* explain: (error) => "explanation string"
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* Easy to extend: just add more patterns to the array.
|
|
15
|
+
* Can be moved to a database or external config later.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const errorPatterns = [
|
|
19
|
+
// Module and import errors
|
|
20
|
+
{
|
|
21
|
+
name: "MODULE_NOT_FOUND",
|
|
22
|
+
match: /Cannot find module|MODULE_NOT_FOUND/i,
|
|
23
|
+
explain: (error) => `
|
|
24
|
+
This error occurs when you try to import or require a file or package that doesn't exist.
|
|
25
|
+
|
|
26
|
+
Common causes:
|
|
27
|
+
- Typo in the module name or path
|
|
28
|
+
- Package not installed (missing from node_modules)
|
|
29
|
+
- Incorrect relative path
|
|
30
|
+
|
|
31
|
+
Solution:
|
|
32
|
+
1. Check the spelling of the module name
|
|
33
|
+
2. If it's a package, run: npm install <package-name>
|
|
34
|
+
3. Verify the file path if using relative imports
|
|
35
|
+
`.trim()
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
{
|
|
39
|
+
name: "REFERENCE_ERROR",
|
|
40
|
+
match: /ReferenceError|is not defined/i,
|
|
41
|
+
explain: (error) => `
|
|
42
|
+
You're trying to use a variable that doesn't exist or hasn't been declared.
|
|
43
|
+
|
|
44
|
+
Common causes:
|
|
45
|
+
- Variable name typo
|
|
46
|
+
- Variable used before declaration
|
|
47
|
+
- Variable declared in a different scope
|
|
48
|
+
- Missing 'require' or 'import' statement
|
|
49
|
+
|
|
50
|
+
Solution:
|
|
51
|
+
1. Check spelling of variable names
|
|
52
|
+
2. Ensure variable is declared before using it
|
|
53
|
+
3. Check variable scope (is it defined in the right block?)
|
|
54
|
+
4. Make sure you've imported/required dependencies
|
|
55
|
+
`.trim()
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
{
|
|
59
|
+
name: "TYPE_ERROR",
|
|
60
|
+
match: /TypeError|Cannot read property|Cannot read properties/i,
|
|
61
|
+
explain: (error) => `
|
|
62
|
+
You're trying to call a method or access a property on something that doesn't have it.
|
|
63
|
+
|
|
64
|
+
Common causes:
|
|
65
|
+
- Accessing property on null or undefined
|
|
66
|
+
- Calling a method on non-object type
|
|
67
|
+
- Wrong method name
|
|
68
|
+
|
|
69
|
+
Solution:
|
|
70
|
+
1. Add null/undefined checks: if (obj && obj.property)
|
|
71
|
+
2. Use optional chaining: obj?.property or obj?.method?.()
|
|
72
|
+
3. Verify the object has the method you're calling
|
|
73
|
+
4. Check API documentation for correct method names
|
|
74
|
+
`.trim()
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
{
|
|
78
|
+
name: "SYNTAX_ERROR",
|
|
79
|
+
match: /SyntaxError|Unexpected token|Unexpected identifier/i,
|
|
80
|
+
explain: (error) => `
|
|
81
|
+
There's a syntax error in your JavaScript code - something is written incorrectly.
|
|
82
|
+
|
|
83
|
+
Common causes:
|
|
84
|
+
- Missing closing bracket, parenthesis, or brace
|
|
85
|
+
- Incorrect operator usage
|
|
86
|
+
- Invalid JSON being parsed
|
|
87
|
+
- Mixing tabs and spaces (in some cases)
|
|
88
|
+
|
|
89
|
+
Solution:
|
|
90
|
+
1. Look at the line number mentioned in the error
|
|
91
|
+
2. Check for missing brackets: {}, (), []
|
|
92
|
+
3. Verify semicolons where required
|
|
93
|
+
4. Use a code formatter like Prettier to auto-fix formatting
|
|
94
|
+
`.trim()
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
{
|
|
98
|
+
name: "EADDRINUSE",
|
|
99
|
+
match: /EADDRINUSE|address already in use|Port .* is already in use/i,
|
|
100
|
+
explain: (error) => `
|
|
101
|
+
The port you're trying to bind to is already in use by another process.
|
|
102
|
+
|
|
103
|
+
Common causes:
|
|
104
|
+
- Another instance of your app is running
|
|
105
|
+
- Another service is using that port
|
|
106
|
+
- Previous process didn't fully close
|
|
107
|
+
|
|
108
|
+
Solution:
|
|
109
|
+
1. Find and kill the process using the port:
|
|
110
|
+
On Mac/Linux: lsof -i :PORT_NUMBER | grep LISTEN | awk '{print $2}' | xargs kill
|
|
111
|
+
On Windows: netstat -ano | findstr :PORT_NUMBER
|
|
112
|
+
2. Change port in your code: process.env.PORT || 3000
|
|
113
|
+
3. Use dynamic port: const port = 3000, then increment if in use
|
|
114
|
+
`.trim()
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
{
|
|
118
|
+
name: "ECONNREFUSED",
|
|
119
|
+
match: /ECONNREFUSED|Connection refused|ECONNREFUSED.*127\.0\.0\.1/i,
|
|
120
|
+
explain: (error) => `
|
|
121
|
+
Connection was refused - the server you're trying to connect to isn't running or listening.
|
|
122
|
+
|
|
123
|
+
Common causes:
|
|
124
|
+
- Database server isn't running (MongoDB, PostgreSQL, etc.)
|
|
125
|
+
- API server isn't started
|
|
126
|
+
- Wrong host or port
|
|
127
|
+
- Firewall blocking connection
|
|
128
|
+
|
|
129
|
+
Solution:
|
|
130
|
+
1. Verify the server is running on the correct port
|
|
131
|
+
2. Check host and port configuration
|
|
132
|
+
3. Add connection error handling:
|
|
133
|
+
client.on('error', (err) => console.error('Cannot connect'))
|
|
134
|
+
4. Use retry logic for resilience
|
|
135
|
+
`.trim()
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
{
|
|
139
|
+
name: "EACCES",
|
|
140
|
+
match: /EACCES|permission denied|Error: EACCES/i,
|
|
141
|
+
explain: (error) => `
|
|
142
|
+
Permission denied - you don't have permission to access a file or resource.
|
|
143
|
+
|
|
144
|
+
Common causes:
|
|
145
|
+
- Insufficient file permissions
|
|
146
|
+
- Running without required privileges
|
|
147
|
+
- Reading/writing to protected directory
|
|
148
|
+
|
|
149
|
+
Solution:
|
|
150
|
+
1. Check file/folder permissions: ls -l (Mac/Linux)
|
|
151
|
+
2. Change permissions: chmod +x filename
|
|
152
|
+
3. Run with sudo if necessary (last resort)
|
|
153
|
+
4. Ensure app runs with correct user permissions
|
|
154
|
+
`.trim()
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
{
|
|
158
|
+
name: "ENOENT",
|
|
159
|
+
match: /ENOENT|no such file or directory|ENOENT.*no such file/i,
|
|
160
|
+
explain: (error) => `
|
|
161
|
+
The file or directory you're trying to access doesn't exist.
|
|
162
|
+
|
|
163
|
+
Common causes:
|
|
164
|
+
- Wrong file path
|
|
165
|
+
- File hasn't been created yet
|
|
166
|
+
- File was deleted
|
|
167
|
+
- Typo in filename
|
|
168
|
+
|
|
169
|
+
Solution:
|
|
170
|
+
1. Verify the file path exists
|
|
171
|
+
2. Check if file is created before reading: fs.existsSync(path)
|
|
172
|
+
3. Use absolute paths instead of relative
|
|
173
|
+
4. Ensure the directory exists before creating files
|
|
174
|
+
`.trim()
|
|
175
|
+
},
|
|
176
|
+
|
|
177
|
+
{
|
|
178
|
+
name: "ERR_HTTP_HEADERS_SENT",
|
|
179
|
+
match: /ERR_HTTP_HEADERS_SENT|Cannot set headers after they are sent/i,
|
|
180
|
+
explain: (error) => `
|
|
181
|
+
You tried to send headers or response twice in the same HTTP request.
|
|
182
|
+
|
|
183
|
+
Common causes:
|
|
184
|
+
- Calling res.send() twice
|
|
185
|
+
- Calling res.end() after already sending response
|
|
186
|
+
- Multiple res.redirect() calls
|
|
187
|
+
- No return after res.send()
|
|
188
|
+
|
|
189
|
+
Solution:
|
|
190
|
+
1. Add return after res.send(): return res.send(data)
|
|
191
|
+
2. Use if/else to ensure response is sent only once
|
|
192
|
+
3. Check for early return: if (condition) { return res.send() }
|
|
193
|
+
4. Use middleware properly - don't send response in multiple places
|
|
194
|
+
`.trim()
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
{
|
|
198
|
+
name: "JSON_PARSE_ERROR",
|
|
199
|
+
match: /JSON\.parse|Unexpected token.*JSON|SyntaxError.*JSON/i,
|
|
200
|
+
explain: (error) => `
|
|
201
|
+
The JSON string you're trying to parse is invalid or malformed.
|
|
202
|
+
|
|
203
|
+
Common causes:
|
|
204
|
+
- Invalid JSON syntax (trailing commas, missing quotes)
|
|
205
|
+
- Trying to parse non-JSON string
|
|
206
|
+
- Incomplete JSON data
|
|
207
|
+
- Incorrect escaping
|
|
208
|
+
|
|
209
|
+
Solution:
|
|
210
|
+
1. Validate JSON before parsing: try/catch around JSON.parse()
|
|
211
|
+
2. Check JSON syntax (use jsonlint.com)
|
|
212
|
+
3. Use error handling:
|
|
213
|
+
try { JSON.parse(str) } catch(e) { console.error('Invalid JSON') }
|
|
214
|
+
4. Ensure complete data is received before parsing
|
|
215
|
+
`.trim()
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
{
|
|
219
|
+
name: "MAXIMUM_CALL_STACK_EXCEEDED",
|
|
220
|
+
match: /Maximum call stack size exceeded|stack overflow|RangeError/i,
|
|
221
|
+
explain: (error) => `
|
|
222
|
+
Infinite recursion or very deeply nested loops - your function called itself too many times.
|
|
223
|
+
|
|
224
|
+
Common causes:
|
|
225
|
+
- Infinite recursion without base case
|
|
226
|
+
- Circular dependencies
|
|
227
|
+
- Deep chains of async operations
|
|
228
|
+
- Event emitter loops
|
|
229
|
+
|
|
230
|
+
Solution:
|
|
231
|
+
1. Check recursive functions have a base case
|
|
232
|
+
2. Ensure recursion terminates
|
|
233
|
+
3. Use iteration instead of recursion for large datasets
|
|
234
|
+
4. Increase stack size if needed (not recommended): node --stack-size
|
|
235
|
+
`.trim()
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
{
|
|
239
|
+
name: "UNHANDLED_PROMISE_REJECTION",
|
|
240
|
+
match: /UnhandledPromiseRejectionWarning|unhandledRejection|Promise rejection was not handled/i,
|
|
241
|
+
explain: (error) => `
|
|
242
|
+
A Promise was rejected but there's no .catch() handler to handle the error.
|
|
243
|
+
|
|
244
|
+
Common causes:
|
|
245
|
+
- Missing .catch() after .then()
|
|
246
|
+
- Missing await or Promise error handling
|
|
247
|
+
- Async function error not caught
|
|
248
|
+
- Event listener not added
|
|
249
|
+
|
|
250
|
+
Solution:
|
|
251
|
+
1. Add .catch() to all Promise chains
|
|
252
|
+
2. Use try/catch with async/await:
|
|
253
|
+
try { await asyncFunction() } catch(e) { }
|
|
254
|
+
3. Add error handler to event emitters
|
|
255
|
+
4. Use process.on('unhandledRejection', handler)
|
|
256
|
+
`.trim()
|
|
257
|
+
},
|
|
258
|
+
|
|
259
|
+
{
|
|
260
|
+
name: "UNEXPECTED_TOKEN",
|
|
261
|
+
match: /Unexpected token|Unexpected identifier|SyntaxError: Unexpected/i,
|
|
262
|
+
explain: (error) => `
|
|
263
|
+
The parser encountered unexpected syntax it didn't expect.
|
|
264
|
+
|
|
265
|
+
Common causes:
|
|
266
|
+
- Missing or extra brackets
|
|
267
|
+
- Using reserved keywords incorrectly
|
|
268
|
+
- Mixing import/require syntax
|
|
269
|
+
- HTML/non-JS in JS file
|
|
270
|
+
|
|
271
|
+
Solution:
|
|
272
|
+
1. Look at the line number in the error
|
|
273
|
+
2. Check for balanced brackets: {}, [], ()
|
|
274
|
+
3. Use consistent import syntax (all import or all require)
|
|
275
|
+
4. Check file encoding and format
|
|
276
|
+
`.trim()
|
|
277
|
+
},
|
|
278
|
+
|
|
279
|
+
{
|
|
280
|
+
name: "ECONNRESET",
|
|
281
|
+
match: /ECONNRESET|Connection reset|socket hang up/i,
|
|
282
|
+
explain: (error) => `
|
|
283
|
+
The connection was reset - the remote server or client closed the connection unexpectedly.
|
|
284
|
+
|
|
285
|
+
Common causes:
|
|
286
|
+
- Server crashed or restarted
|
|
287
|
+
- Network connection dropped
|
|
288
|
+
- Timeout - connection idle too long
|
|
289
|
+
- Client forcefully closed connection
|
|
290
|
+
|
|
291
|
+
Solution:
|
|
292
|
+
1. Add connection error handling:
|
|
293
|
+
socket.on('error', (err) => console.error('Connection error'))
|
|
294
|
+
2. Implement retry logic with exponential backoff
|
|
295
|
+
3. Check for timeouts: socket.setTimeout()
|
|
296
|
+
4. Monitor server logs for crashes
|
|
297
|
+
`.trim()
|
|
298
|
+
},
|
|
299
|
+
|
|
300
|
+
{
|
|
301
|
+
name: "MONGO_NETWORK_ERROR",
|
|
302
|
+
match: /MongoNetworkError|MongoDB server selection failed|getaddrinfo.*mongodb/i,
|
|
303
|
+
explain: (error) => `
|
|
304
|
+
Cannot connect to MongoDB - network or database connection issue.
|
|
305
|
+
|
|
306
|
+
Common causes:
|
|
307
|
+
- MongoDB server not running
|
|
308
|
+
- Wrong connection string
|
|
309
|
+
- Database server unreachable
|
|
310
|
+
- Firewall blocking connection
|
|
311
|
+
- Wrong credentials
|
|
312
|
+
|
|
313
|
+
Solution:
|
|
314
|
+
1. Verify MongoDB is running
|
|
315
|
+
2. Check connection string in .env or config
|
|
316
|
+
3. Ensure IP/hostname is correct and accessible
|
|
317
|
+
4. Add connection retries:
|
|
318
|
+
useNewUrlParser: true, useUnifiedTopology: true
|
|
319
|
+
5. Check MongoDB cloud Atlas firewall rules if using cloud
|
|
320
|
+
`.trim()
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
{
|
|
324
|
+
name: "MONGOOSE_VALIDATION_ERROR",
|
|
325
|
+
match: /ValidationError|Mongoose|validation failed|Cast to.*failed/i,
|
|
326
|
+
explain: (error) => `
|
|
327
|
+
MongoDB/Mongoose rejected data because it doesn't match your schema definition.
|
|
328
|
+
|
|
329
|
+
Common causes:
|
|
330
|
+
- Required field missing
|
|
331
|
+
- Data type mismatch
|
|
332
|
+
- Custom validator failed
|
|
333
|
+
- Invalid ObjectId
|
|
334
|
+
|
|
335
|
+
Solution:
|
|
336
|
+
1. Check all required fields are provided
|
|
337
|
+
2. Ensure data types match schema
|
|
338
|
+
3. Validate ObjectIds before querying
|
|
339
|
+
4. Add debug logging to see what field failed
|
|
340
|
+
5. Use schema validation: const schema = new Schema({ ... })
|
|
341
|
+
`.trim()
|
|
342
|
+
},
|
|
343
|
+
|
|
344
|
+
{
|
|
345
|
+
name: "EXPRESS_ROUTE_NOT_FOUND",
|
|
346
|
+
match: /Cannot GET|Cannot POST|Cannot PUT|Cannot DELETE|404.*not found/i,
|
|
347
|
+
explain: (error) => `
|
|
348
|
+
Express couldn't find a route handler that matches this HTTP request.
|
|
349
|
+
|
|
350
|
+
Common causes:
|
|
351
|
+
- Route not defined
|
|
352
|
+
- Wrong HTTP method (GET vs POST)
|
|
353
|
+
- URL path typo
|
|
354
|
+
- Route defined after app.listen()
|
|
355
|
+
- Missing middleware
|
|
356
|
+
|
|
357
|
+
Solution:
|
|
358
|
+
1. Verify route exists: app.get('/path', ...)
|
|
359
|
+
2. Check HTTP method matches (GET, POST, PUT, DELETE)
|
|
360
|
+
3. Add 404 handler at end: app.use((req, res) => res.status(404))
|
|
361
|
+
4. Use app.all('*') for catch-all
|
|
362
|
+
5. Ensure routes defined before app.listen()
|
|
363
|
+
`.trim()
|
|
364
|
+
},
|
|
365
|
+
|
|
366
|
+
{
|
|
367
|
+
name: "CORS_ERROR",
|
|
368
|
+
match: /CORS|Access-Control-Allow-Origin|Cross-Origin/i,
|
|
369
|
+
explain: (error) => `
|
|
370
|
+
Cross-Origin Resource Sharing (CORS) error - browser blocked request from different domain.
|
|
371
|
+
|
|
372
|
+
Common causes:
|
|
373
|
+
- CORS headers not set
|
|
374
|
+
- Frontend and backend on different origins
|
|
375
|
+
- Browser security policy
|
|
376
|
+
- Credentials not allowed
|
|
377
|
+
|
|
378
|
+
Solution:
|
|
379
|
+
1. Install and use cors: npm install cors
|
|
380
|
+
2. Add to Express: const cors = require('cors'); app.use(cors())
|
|
381
|
+
3. Or configure specific origins:
|
|
382
|
+
app.use(cors({ origin: 'http://localhost:3000' }))
|
|
383
|
+
4. For credentials: credentials: true
|
|
384
|
+
`.trim()
|
|
385
|
+
},
|
|
386
|
+
|
|
387
|
+
{
|
|
388
|
+
name: "RATE_LIMIT_ERROR",
|
|
389
|
+
match: /rate limit|too many requests|429|throttle/i,
|
|
390
|
+
explain: (error) => `
|
|
391
|
+
You've exceeded the rate limit - too many requests in a short time.
|
|
392
|
+
|
|
393
|
+
Common causes:
|
|
394
|
+
- API rate limit exceeded
|
|
395
|
+
- Too many concurrent requests
|
|
396
|
+
- Requesting same endpoint repeatedly
|
|
397
|
+
- No backoff/delay between requests
|
|
398
|
+
|
|
399
|
+
Solution:
|
|
400
|
+
1. Implement rate limiting: npm install express-rate-limit
|
|
401
|
+
2. Add delay between requests: await new Promise(r => setTimeout(r, 1000))
|
|
402
|
+
3. Use exponential backoff for retries
|
|
403
|
+
4. Check API documentation for limits
|
|
404
|
+
5. Cache responses to reduce requests
|
|
405
|
+
`.trim()
|
|
406
|
+
},
|
|
407
|
+
|
|
408
|
+
{
|
|
409
|
+
name: "MEMORY_LEAK_ERROR",
|
|
410
|
+
match: /heap out of memory|JavaScript heap out of memory|FATAL/i,
|
|
411
|
+
explain: (error) => `
|
|
412
|
+
Node.js ran out of memory - likely a memory leak or insufficient heap allocation.
|
|
413
|
+
|
|
414
|
+
Common causes:
|
|
415
|
+
- Event listeners not cleaned up
|
|
416
|
+
- Circular references
|
|
417
|
+
- Large objects not garbage collected
|
|
418
|
+
- Unbounded cache/arrays
|
|
419
|
+
- Too many connections
|
|
420
|
+
|
|
421
|
+
Solution:
|
|
422
|
+
1. Check for memory leaks using clinic.js or node inspect
|
|
423
|
+
2. Clean up event listeners: emitter.removeListener()
|
|
424
|
+
3. Limit cache size: implement LRU cache
|
|
425
|
+
4. Close connections properly
|
|
426
|
+
5. Increase heap: node --max-old-space-size=4096 app.js
|
|
427
|
+
`.trim()
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
{
|
|
431
|
+
name: "TIMEOUT_ERROR",
|
|
432
|
+
match: /timeout|ETIMEDOUT|timed out|deadline exceeded/i,
|
|
433
|
+
explain: (error) => `
|
|
434
|
+
Operation took too long and was cancelled - timeout exceeded.
|
|
435
|
+
|
|
436
|
+
Common causes:
|
|
437
|
+
- Network request too slow
|
|
438
|
+
- Database query too slow
|
|
439
|
+
- Operation genuinely taking long time
|
|
440
|
+
- Server not responding
|
|
441
|
+
|
|
442
|
+
Solution:
|
|
443
|
+
1. Increase timeout if needed: setTimeout seems too short
|
|
444
|
+
2. Use Promise.race() with timeout:
|
|
445
|
+
Promise.race([operation, timeoutPromise])
|
|
446
|
+
3. Optimize slow queries/requests
|
|
447
|
+
4. Add error handling with graceful fallback
|
|
448
|
+
5. Monitor performance with profiling tools
|
|
449
|
+
`.trim()
|
|
450
|
+
},
|
|
451
|
+
|
|
452
|
+
{
|
|
453
|
+
name: "FILE_ALREADY_EXISTS",
|
|
454
|
+
match: /EEXIST|File already exists|file exists/i,
|
|
455
|
+
explain: (error) => `
|
|
456
|
+
You're trying to create a file that already exists.
|
|
457
|
+
|
|
458
|
+
Common causes:
|
|
459
|
+
- Re-running script that creates files
|
|
460
|
+
- Not checking if file exists before creating
|
|
461
|
+
- Race condition with concurrent writes
|
|
462
|
+
|
|
463
|
+
Solution:
|
|
464
|
+
1. Check if file exists: fs.existsSync(path)
|
|
465
|
+
2. Use flags appropriately: 'w' (overwrite), 'wx' (fail if exists)
|
|
466
|
+
3. Handle error gracefully:
|
|
467
|
+
if (fs.existsSync(file)) { fs.unlinkSync(file) }
|
|
468
|
+
4. Use callback: fs.writeFile(path, data, (err) => { })
|
|
469
|
+
`.trim()
|
|
470
|
+
},
|
|
471
|
+
|
|
472
|
+
{
|
|
473
|
+
name: "INVALID_ARGUMENT_ERROR",
|
|
474
|
+
match: /ERR_INVALID_ARG_TYPE|ERR_INVALID_ARG|Invalid argument/i,
|
|
475
|
+
explain: (error) => `
|
|
476
|
+
You passed an invalid argument to a function - wrong type or value.
|
|
477
|
+
|
|
478
|
+
Common causes:
|
|
479
|
+
- Wrong data type (string instead of number)
|
|
480
|
+
- Null/undefined where object expected
|
|
481
|
+
- Out of range value
|
|
482
|
+
- Invalid option object
|
|
483
|
+
|
|
484
|
+
Solution:
|
|
485
|
+
1. Check function documentation for expected types
|
|
486
|
+
2. Validate arguments before calling:
|
|
487
|
+
if (typeof x !== 'number') throw new Error('Expected number')
|
|
488
|
+
3. Use TypeScript for type safety
|
|
489
|
+
4. Add JSDoc comments to document expected types
|
|
490
|
+
`.trim()
|
|
491
|
+
},
|
|
492
|
+
|
|
493
|
+
{
|
|
494
|
+
name: "ENOMEM",
|
|
495
|
+
match: /ENOMEM|Cannot allocate memory|out of memory/i,
|
|
496
|
+
explain: (error) => `
|
|
497
|
+
The system is out of memory - no more memory available.
|
|
498
|
+
|
|
499
|
+
Common causes:
|
|
500
|
+
- Memory leak accumulating
|
|
501
|
+
- Process using too much memory
|
|
502
|
+
- System low on overall memory
|
|
503
|
+
- Infinite loops creating data
|
|
504
|
+
|
|
505
|
+
Solution:
|
|
506
|
+
1. Check memory usage: ps aux (Mac/Linux) or Task Manager (Windows)
|
|
507
|
+
2. Profile memory: node --inspect-brk app.js
|
|
508
|
+
3. Reduce memory usage in application
|
|
509
|
+
4. Implement memory limits or pagination
|
|
510
|
+
5. Check for unbounded data structures
|
|
511
|
+
`.trim()
|
|
512
|
+
},
|
|
513
|
+
|
|
514
|
+
{
|
|
515
|
+
name: "PORT_NOT_NUMERIC",
|
|
516
|
+
match: /port should be >= 0|port is not a number|ERR_SOCKET_BAD_PORT/i,
|
|
517
|
+
explain: (error) => `
|
|
518
|
+
The port number is invalid - must be a number between 0 and 65535.
|
|
519
|
+
|
|
520
|
+
Common causes:
|
|
521
|
+
- Port is a string not a number
|
|
522
|
+
- Port less than 0 or greater than 65535
|
|
523
|
+
- Port is NaN or undefined
|
|
524
|
+
|
|
525
|
+
Solution:
|
|
526
|
+
1. Ensure port is a number: const port = parseInt(process.env.PORT) || 3000
|
|
527
|
+
2. Validate range: if (port < 0 || port > 65535) throw Error
|
|
528
|
+
3. Parse from environment variables correctly
|
|
529
|
+
4. Use defaults: port || 3000
|
|
530
|
+
`.trim()
|
|
531
|
+
},
|
|
532
|
+
|
|
533
|
+
{
|
|
534
|
+
name: "ECONNABORTED",
|
|
535
|
+
match: /ECONNABORTED|Connection aborted|socket destroyed/i,
|
|
536
|
+
explain: (error) => `
|
|
537
|
+
The connection was aborted - closed during communication.
|
|
538
|
+
|
|
539
|
+
Common causes:
|
|
540
|
+
- Client closed connection mid-request
|
|
541
|
+
- Server forcefully closed socket
|
|
542
|
+
- Network interruption
|
|
543
|
+
- Timeout during transfer
|
|
544
|
+
|
|
545
|
+
Solution:
|
|
546
|
+
1. Add error handlers: socket.on('error', handler)
|
|
547
|
+
2. Implement connection pooling
|
|
548
|
+
3. Add retry logic for aborted connections
|
|
549
|
+
4. Use keep-alive: agent: new http.Agent({ keepAlive: true })
|
|
550
|
+
`.trim()
|
|
551
|
+
},
|
|
552
|
+
|
|
553
|
+
{
|
|
554
|
+
name: "EMIT_AFTER_CLOSE",
|
|
555
|
+
match: /write after end|ERR_STREAM_DESTROYED|Destroyed stream/i,
|
|
556
|
+
explain: (error) => `
|
|
557
|
+
You're trying to write to a stream that has already been closed/destroyed.
|
|
558
|
+
|
|
559
|
+
Common causes:
|
|
560
|
+
- Writing to closed file/stream
|
|
561
|
+
- Writing after .end() called
|
|
562
|
+
- Double closing
|
|
563
|
+
- Race condition
|
|
564
|
+
|
|
565
|
+
Solution:
|
|
566
|
+
1. Check stream state before writing
|
|
567
|
+
2. Use .once() or .on() but not after .end()
|
|
568
|
+
3. Call .end() only once:
|
|
569
|
+
stream.end(() => { })
|
|
570
|
+
4. Buffer data and write before close
|
|
571
|
+
`.trim()
|
|
572
|
+
},
|
|
573
|
+
|
|
574
|
+
{
|
|
575
|
+
name: "REQUIRE_CYCLE",
|
|
576
|
+
match: /circular.*require|require.*cycle|Cannot find module/i,
|
|
577
|
+
explain: (error) => `
|
|
578
|
+
Circular dependency detected - files require each other creating a loop.
|
|
579
|
+
|
|
580
|
+
Common causes:
|
|
581
|
+
- File A requires File B, File B requires File A
|
|
582
|
+
- Deep circular dependency chains
|
|
583
|
+
- Shared exports
|
|
584
|
+
|
|
585
|
+
Solution:
|
|
586
|
+
1. Restructure code to break circle
|
|
587
|
+
2. Use lazy requires: require() inside function, not top-level
|
|
588
|
+
3. Extract shared code to third file
|
|
589
|
+
4. Check import graph: npm install circular-dependency-plugin
|
|
590
|
+
`.trim()
|
|
591
|
+
},
|
|
592
|
+
|
|
593
|
+
{
|
|
594
|
+
name: "BUFFER_ENCODING_ERROR",
|
|
595
|
+
match: /Unknown encoding|ERR_UNKNOWN_ENCODING|not a valid encoding/i,
|
|
596
|
+
explain: (error) => `
|
|
597
|
+
Invalid character encoding specified - not a recognized encoding.
|
|
598
|
+
|
|
599
|
+
Common causes:
|
|
600
|
+
- Typo in encoding name
|
|
601
|
+
- Unsupported encoding
|
|
602
|
+
- Wrong encoding for data
|
|
603
|
+
|
|
604
|
+
Solution:
|
|
605
|
+
1. Use valid encodings: utf8, utf16le, ascii, latin1, base64, hex
|
|
606
|
+
2. Common encoding is 'utf8' (default)
|
|
607
|
+
3. Check documentation for correct encoding name
|
|
608
|
+
4. Convert between encodings if needed: buffer.toString('utf8')
|
|
609
|
+
`.trim()
|
|
610
|
+
},
|
|
611
|
+
|
|
612
|
+
{
|
|
613
|
+
name: "INVALID_PROTOCOL",
|
|
614
|
+
match: /Invalid protocol|ERR_INVALID_PROTOCOL|protocol.*invalid/i,
|
|
615
|
+
explain: (error) => `
|
|
616
|
+
Invalid URL protocol specified - must be http:, https:, ftp:, etc.
|
|
617
|
+
|
|
618
|
+
Common causes:
|
|
619
|
+
- URL missing protocol
|
|
620
|
+
- Wrong protocol in URL
|
|
621
|
+
- Spaces or invalid characters
|
|
622
|
+
|
|
623
|
+
Solution:
|
|
624
|
+
1. Ensure URL includes protocol: 'https://...' not just '...'
|
|
625
|
+
2. Use new URL() to parse and validate
|
|
626
|
+
3. Common protocols: http:, https:, ftp:, file:
|
|
627
|
+
4. Check URL format: new URL('https://example.com')
|
|
628
|
+
`.trim()
|
|
629
|
+
},
|
|
630
|
+
|
|
631
|
+
{
|
|
632
|
+
name: "ERR_MODULE_NOT_FOUND",
|
|
633
|
+
match: /ERR_MODULE_NOT_FOUND|Cannot find.*module|ERR_PACKAGE_PATH_NOT_EXPORTED/i,
|
|
634
|
+
explain: (error) => `
|
|
635
|
+
The module or export you're trying to import doesn't exist.
|
|
636
|
+
|
|
637
|
+
Common causes:
|
|
638
|
+
- Package not installed
|
|
639
|
+
- Wrong export name
|
|
640
|
+
- Wrong file path
|
|
641
|
+
- Package incompatible with Node version
|
|
642
|
+
|
|
643
|
+
Solution:
|
|
644
|
+
1. Install missing package: npm install package-name
|
|
645
|
+
2. Check exact export name: check package.json "exports" field
|
|
646
|
+
3. Use correct import syntax
|
|
647
|
+
4. Verify package version supports your Node version
|
|
648
|
+
`.trim()
|
|
649
|
+
},
|
|
650
|
+
|
|
651
|
+
{
|
|
652
|
+
name: "ERR_SCRIPT_NOT_FOUND",
|
|
653
|
+
match: /ERR_SCRIPT_NOT_FOUND|npm run.*not found|Unknown script/i,
|
|
654
|
+
explain: (error) => `
|
|
655
|
+
The npm script you're trying to run doesn't exist in package.json.
|
|
656
|
+
|
|
657
|
+
Common causes:
|
|
658
|
+
- Script not defined in package.json
|
|
659
|
+
- Typo in script name
|
|
660
|
+
- Wrong project directory
|
|
661
|
+
|
|
662
|
+
Solution:
|
|
663
|
+
1. Check package.json scripts section
|
|
664
|
+
2. Add the script: "start": "node app.js"
|
|
665
|
+
3. Run scripts with: npm run script-name
|
|
666
|
+
4. List available scripts: npm run
|
|
667
|
+
`.trim()
|
|
668
|
+
},
|
|
669
|
+
|
|
670
|
+
{
|
|
671
|
+
name: "EPERM",
|
|
672
|
+
match: /EPERM|operation not permitted|permission denied/i,
|
|
673
|
+
explain: (error) => `
|
|
674
|
+
Operation not permitted - insufficient permissions for this action.
|
|
675
|
+
|
|
676
|
+
Common causes:
|
|
677
|
+
- File/directory permissions too restrictive
|
|
678
|
+
- Trying to write to read-only file
|
|
679
|
+
- Trying to delete protected file
|
|
680
|
+
- Running as wrong user
|
|
681
|
+
|
|
682
|
+
Solution:
|
|
683
|
+
1. Fix permissions: chmod +w filename (Mac/Linux)
|
|
684
|
+
2. Check file owner: ls -l (Mac/Linux)
|
|
685
|
+
3. Run as correct user
|
|
686
|
+
4. Use sudo if necessary (be cautious)
|
|
687
|
+
`.trim()
|
|
688
|
+
},
|
|
689
|
+
|
|
690
|
+
{
|
|
691
|
+
name: "EISDIR",
|
|
692
|
+
match: /EISDIR|Illegal operation on a directory|Is a directory/i,
|
|
693
|
+
explain: (error) => `
|
|
694
|
+
You're trying to use a directory where a file is expected, or vice versa.
|
|
695
|
+
|
|
696
|
+
Common causes:
|
|
697
|
+
- Trying to read a directory as file
|
|
698
|
+
- fs.readFile() given directory path
|
|
699
|
+
- Wrong path type
|
|
700
|
+
|
|
701
|
+
Solution:
|
|
702
|
+
1. Check if path is directory: fs.lstatSync(path).isDirectory()
|
|
703
|
+
2. Use correct fs method: fs.readdir() for directories
|
|
704
|
+
3. Verify path in code matches actual file/directory
|
|
705
|
+
`.trim()
|
|
706
|
+
},
|
|
707
|
+
|
|
708
|
+
{
|
|
709
|
+
name: "ENOTDIR",
|
|
710
|
+
match: /ENOTDIR|not a directory|ENOTDIR/i,
|
|
711
|
+
explain: (error) => `
|
|
712
|
+
You're trying to use a file where a directory is expected.
|
|
713
|
+
|
|
714
|
+
Common causes:
|
|
715
|
+
- Path should point to directory but doesn't
|
|
716
|
+
- File deleted or renamed
|
|
717
|
+
- Wrong path structure
|
|
718
|
+
|
|
719
|
+
Solution:
|
|
720
|
+
1. Verify directory exists
|
|
721
|
+
2. Create directory if needed: fs.mkdirSync(path, { recursive: true })
|
|
722
|
+
3. Check full path is correct
|
|
723
|
+
4. Ensure intermediate directories exist
|
|
724
|
+
`.trim()
|
|
725
|
+
},
|
|
726
|
+
|
|
727
|
+
{
|
|
728
|
+
name: "ENVFILE_NOT_FOUND",
|
|
729
|
+
match: /\.env.*not found|no such file.*\.env/i,
|
|
730
|
+
explain: (error) => `
|
|
731
|
+
.env configuration file not found - needed for environment variables.
|
|
732
|
+
|
|
733
|
+
Common causes:
|
|
734
|
+
- .env file missing
|
|
735
|
+
- Wrong working directory
|
|
736
|
+
- Gitignored .env not created
|
|
737
|
+
|
|
738
|
+
Solution:
|
|
739
|
+
1. Create .env file in project root
|
|
740
|
+
2. Use env package: require('dotenv').config()
|
|
741
|
+
3. Copy from .env.example if exists: cp .env.example .env
|
|
742
|
+
4. Add to .gitignore: echo '.env' >> .gitignore
|
|
743
|
+
`.trim()
|
|
744
|
+
},
|
|
745
|
+
|
|
746
|
+
{
|
|
747
|
+
name: "SSL_CERTIFICATE_ERROR",
|
|
748
|
+
match: /SSL|certificate|SSL_ERROR|unable to verify|self signed/i,
|
|
749
|
+
explain: (error) => `
|
|
750
|
+
SSL/TLS certificate error - security certificate issue.
|
|
751
|
+
|
|
752
|
+
Common causes:
|
|
753
|
+
- Self-signed certificate
|
|
754
|
+
- Expired certificate
|
|
755
|
+
- Certificate mismatch
|
|
756
|
+
- Wrong hostname
|
|
757
|
+
|
|
758
|
+
Solution:
|
|
759
|
+
1. For development, disable SSL check (NOT for production):
|
|
760
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
|
761
|
+
2. Use valid certificate for production
|
|
762
|
+
3. Check certificate expiry
|
|
763
|
+
4. Use LetsEncrypt for free certificates
|
|
764
|
+
`.trim()
|
|
765
|
+
},
|
|
766
|
+
|
|
767
|
+
{
|
|
768
|
+
name: "HEADER_OVERFLOW",
|
|
769
|
+
match: /ERR_HTTP_HEADERS_OVERFLOW|Headers overflow|header.*too large/i,
|
|
770
|
+
explain: (error) => `
|
|
771
|
+
HTTP headers exceeded size limit - too much header data.
|
|
772
|
+
|
|
773
|
+
Common causes:
|
|
774
|
+
- Too many cookies
|
|
775
|
+
- Large headers in request
|
|
776
|
+
- Headers not cleaned up
|
|
777
|
+
|
|
778
|
+
Solution:
|
|
779
|
+
1. Reduce number/size of cookies
|
|
780
|
+
2. Compress headers
|
|
781
|
+
3. Use configure max header size:
|
|
782
|
+
--max-http-header-size=16384
|
|
783
|
+
`.trim()
|
|
784
|
+
},
|
|
785
|
+
|
|
786
|
+
{
|
|
787
|
+
name: "STREAM_DESTROYED",
|
|
788
|
+
match: /stream destroyed|Writable stream error|destroyed stream/i,
|
|
789
|
+
explain: (error) => `
|
|
790
|
+
Attempting to use a stream that has been destroyed/closed.
|
|
791
|
+
|
|
792
|
+
Common causes:
|
|
793
|
+
- Writing to closed stream
|
|
794
|
+
- Stream destroyed before operation
|
|
795
|
+
- Pipe to destroyed stream
|
|
796
|
+
|
|
797
|
+
Solution:
|
|
798
|
+
1. Check stream state: if (!stream.destroyed)
|
|
799
|
+
2. Add error handlers: stream.on('error', handler)
|
|
800
|
+
3. Don't reuse destroyed streams
|
|
801
|
+
4. Clean up properly: stream.destroy()
|
|
802
|
+
`.trim()
|
|
803
|
+
},
|
|
804
|
+
|
|
805
|
+
{
|
|
806
|
+
name: "INVALID_URL",
|
|
807
|
+
match: /Invalid URL|ERR_INVALID_URL|URL.*invalid/i,
|
|
808
|
+
explain: (error) => `
|
|
809
|
+
The URL format is invalid or malformed.
|
|
810
|
+
|
|
811
|
+
Common causes:
|
|
812
|
+
- Missing protocol (http://, https://)
|
|
813
|
+
- Invalid characters in URL
|
|
814
|
+
- Space or special character not encoded
|
|
815
|
+
- Malformed query string
|
|
816
|
+
|
|
817
|
+
Solution:
|
|
818
|
+
1. Use new URL() to validate: new URL('https://example.com')
|
|
819
|
+
2. Encode special characters: encodeURIComponent()
|
|
820
|
+
3. Include protocol: https://example.com
|
|
821
|
+
4. Use try/catch for URL validation
|
|
822
|
+
`.trim()
|
|
823
|
+
},
|
|
824
|
+
|
|
825
|
+
{
|
|
826
|
+
name: "ABORT_CONTROLLER_ERROR",
|
|
827
|
+
match: /AbortError|abort.*signal|signal.*aborted/i,
|
|
828
|
+
explain: (error) => `
|
|
829
|
+
Operation was aborted using AbortController signal.
|
|
830
|
+
|
|
831
|
+
Common causes:
|
|
832
|
+
- User cancelled operation
|
|
833
|
+
- Timeout triggered abort
|
|
834
|
+
- Request cancelled before completion
|
|
835
|
+
|
|
836
|
+
Solution:
|
|
837
|
+
1. Handle AbortError properly:
|
|
838
|
+
if (error.name === 'AbortError') { }
|
|
839
|
+
2. Use AbortController for cancellation:
|
|
840
|
+
const controller = new AbortController()
|
|
841
|
+
3. Add timeouts: AbortSignal.timeout(5000)
|
|
842
|
+
`.trim()
|
|
843
|
+
},
|
|
844
|
+
|
|
845
|
+
{
|
|
846
|
+
name: "PROCESS_ERROR",
|
|
847
|
+
match: /child process|spawn|fork.*error|ERR_CHILD_PROCESS/i,
|
|
848
|
+
explain: (error) => `
|
|
849
|
+
Error spawning or managing a child process.
|
|
850
|
+
|
|
851
|
+
Common causes:
|
|
852
|
+
- Command not found
|
|
853
|
+
- Permission denied to execute
|
|
854
|
+
- Invalid arguments
|
|
855
|
+
|
|
856
|
+
Solution:
|
|
857
|
+
1. Check command exists and is executable
|
|
858
|
+
2. Use full path: '/usr/bin/node' not just 'node'
|
|
859
|
+
3. Handle child process errors:
|
|
860
|
+
child.on('error', (err) => { })
|
|
861
|
+
4. Check exit code: process.exitCode
|
|
862
|
+
`.trim()
|
|
863
|
+
},
|
|
864
|
+
|
|
865
|
+
{
|
|
866
|
+
name: "ASSERTION_ERROR",
|
|
867
|
+
match: /AssertionError|Assert.*failed|assertion.*false/i,
|
|
868
|
+
explain: (error) => `
|
|
869
|
+
An assertion failed - a condition you asserted was false when it should be true.
|
|
870
|
+
|
|
871
|
+
Common causes:
|
|
872
|
+
- Unit test failed
|
|
873
|
+
- Debug assertion triggered
|
|
874
|
+
- Unexpected state
|
|
875
|
+
|
|
876
|
+
Solution:
|
|
877
|
+
1. Check the assertion message for details
|
|
878
|
+
2. Fix the code or test
|
|
879
|
+
3. Use assertions for debugging: assert(condition, 'message')
|
|
880
|
+
4. Better: console.assert(condition, 'message')
|
|
881
|
+
`.trim()
|
|
882
|
+
},
|
|
883
|
+
|
|
884
|
+
{
|
|
885
|
+
name: "DEPRECATED_API",
|
|
886
|
+
match: /DeprecationWarning|deprecated|Deprecation/i,
|
|
887
|
+
explain: (error) => `
|
|
888
|
+
You're using an API or feature that's deprecated and will be removed.
|
|
889
|
+
|
|
890
|
+
Common causes:
|
|
891
|
+
- Using old Node.js API
|
|
892
|
+
- Old library version
|
|
893
|
+
- Feature marked for removal
|
|
894
|
+
|
|
895
|
+
Solution:
|
|
896
|
+
1. Check deprecation message for replacement
|
|
897
|
+
2. Update to newer API
|
|
898
|
+
3. Suppress warning if necessary (not recommended):
|
|
899
|
+
--no-deprecation flag
|
|
900
|
+
4. Keep code updated with Node.js releases
|
|
901
|
+
`.trim()
|
|
902
|
+
},
|
|
903
|
+
|
|
904
|
+
{
|
|
905
|
+
name: "UNSAFE_INTEGER",
|
|
906
|
+
match: /unsafe integer|MAX_SAFE_INTEGER|Not a safe integer/i,
|
|
907
|
+
explain: (error) => `
|
|
908
|
+
Number exceeds JavaScript's safe integer range (±2^53).
|
|
909
|
+
|
|
910
|
+
Common causes:
|
|
911
|
+
- Very large numbers (BigInt needed)
|
|
912
|
+
- Calculations overflow
|
|
913
|
+
- Precision loss
|
|
914
|
+
|
|
915
|
+
Solution:
|
|
916
|
+
1. Use BigInt for large numbers: 123n
|
|
917
|
+
2. Use BigInt operations: 1n + 1n
|
|
918
|
+
3. Convert carefully: BigInt(number)
|
|
919
|
+
4. Handle in calculations: Math.floor() before using
|
|
920
|
+
`.trim()
|
|
921
|
+
},
|
|
922
|
+
|
|
923
|
+
{
|
|
924
|
+
name: "TEMPLATE_LITERAL_ERROR",
|
|
925
|
+
match: /template|string.*template|backtick/i,
|
|
926
|
+
explain: (error) => `
|
|
927
|
+
Error with template literals or string formatting.
|
|
928
|
+
|
|
929
|
+
Common causes:
|
|
930
|
+
- Missing backticks: \` instead of '
|
|
931
|
+
- Unescaped $ in template
|
|
932
|
+
- Invalid expression in \${}
|
|
933
|
+
|
|
934
|
+
Solution:
|
|
935
|
+
1. Use backticks for template literals: \`text \${var}\`
|
|
936
|
+
2. Escape literal $: \\$ if needed
|
|
937
|
+
3. Use valid expressions in \${}: \${variable}, \${1 + 1}
|
|
938
|
+
`.trim()
|
|
939
|
+
},
|
|
940
|
+
|
|
941
|
+
{
|
|
942
|
+
name: "ARRAY_OUT_OF_BOUNDS",
|
|
943
|
+
match: /out of range|index out of bounds|RangeError|length/i,
|
|
944
|
+
explain: (error) => `
|
|
945
|
+
Array index is out of valid range or operation exceeds array bounds.
|
|
946
|
+
|
|
947
|
+
Common causes:
|
|
948
|
+
- Negative index without check
|
|
949
|
+
- Index equals or exceeds length
|
|
950
|
+
- Wrong loop condition
|
|
951
|
+
|
|
952
|
+
Solution:
|
|
953
|
+
1. Check array length: if (index < arr.length)
|
|
954
|
+
2. Use proper loop: for (let i = 0; i < arr.length; i++)
|
|
955
|
+
3. Use array methods: arr.forEach(), map(), filter()
|
|
956
|
+
4. Handle edge cases
|
|
957
|
+
`.trim()
|
|
958
|
+
},
|
|
959
|
+
|
|
960
|
+
{
|
|
961
|
+
name: "DIVISION_BY_ZERO",
|
|
962
|
+
match: /division.*zero|divide.*zero|Infinity|toDo by zero/i,
|
|
963
|
+
explain: (error) => `
|
|
964
|
+
Division by zero encountered - mathematically undefined.
|
|
965
|
+
|
|
966
|
+
Common causes:
|
|
967
|
+
- Denominator is 0 or evaluates to 0
|
|
968
|
+
- Missing validation
|
|
969
|
+
|
|
970
|
+
Solution:
|
|
971
|
+
1. Check denominator isn't zero: if (divisor !== 0)
|
|
972
|
+
2. Provide fallback value: divisor || 1
|
|
973
|
+
3. Handle Infinity gracefully: if (!isFinite(result))
|
|
974
|
+
4. Validate inputs before operations
|
|
975
|
+
`.trim()
|
|
976
|
+
},
|
|
977
|
+
|
|
978
|
+
{
|
|
979
|
+
name: "MIXED_CONTENT",
|
|
980
|
+
match: /mixed content|https.*http|insecure content/i,
|
|
981
|
+
explain: (error) => `
|
|
982
|
+
HTTPS page is trying to load HTTP content - browser blocks this for security.
|
|
983
|
+
|
|
984
|
+
Common causes:
|
|
985
|
+
- HTTPS page loading HTTP resource
|
|
986
|
+
- Image, script, or API from HTTP
|
|
987
|
+
|
|
988
|
+
Solution:
|
|
989
|
+
1. Use HTTPS for all resources
|
|
990
|
+
2. Update all URLs to https://
|
|
991
|
+
3. Use protocol-relative URLs: //example.com/image.jpg
|
|
992
|
+
4. Update API endpoints to use HTTPS
|
|
993
|
+
`.trim()
|
|
994
|
+
},
|
|
995
|
+
|
|
996
|
+
{
|
|
997
|
+
name: "ENCODING_MISMATCH",
|
|
998
|
+
match: /encoding|charset|UTF-8|BOM|byte order/i,
|
|
999
|
+
explain: (error) => `
|
|
1000
|
+
Character encoding mismatch - data in one encoding, expected another.
|
|
1001
|
+
|
|
1002
|
+
Common causes:
|
|
1003
|
+
- File saved in different encoding than expected
|
|
1004
|
+
- BOM (Byte Order Mark) interference
|
|
1005
|
+
- Locale encoding mismatch
|
|
1006
|
+
|
|
1007
|
+
Solution:
|
|
1008
|
+
1. Save files as UTF-8 consistently
|
|
1009
|
+
2. Specify encoding: fs.readFileSync(path, 'utf8')
|
|
1010
|
+
3. Check for BOM: if (content.charCodeAt(0) === 0xFEFF)
|
|
1011
|
+
4. Use consistent encoding across project
|
|
1012
|
+
`.trim()
|
|
1013
|
+
},
|
|
1014
|
+
|
|
1015
|
+
{
|
|
1016
|
+
name: "LOCK_FILE_ERROR",
|
|
1017
|
+
match: /lock|ELOCKED|in use by another|lockfile/i,
|
|
1018
|
+
explain: (error) => `
|
|
1019
|
+
Resource is locked - being used by another process.
|
|
1020
|
+
|
|
1021
|
+
Common causes:
|
|
1022
|
+
- File/database in use
|
|
1023
|
+
- Another npm install running
|
|
1024
|
+
- Process hasn't closed properly
|
|
1025
|
+
|
|
1026
|
+
Solution:
|
|
1027
|
+
1. Close other processes using resource
|
|
1028
|
+
2. Delete lock files: rm -f package-lock.json
|
|
1029
|
+
3. Wait for process to release lock
|
|
1030
|
+
4. Use proper locking: npm-lock package
|
|
1031
|
+
`.trim()
|
|
1032
|
+
},
|
|
1033
|
+
|
|
1034
|
+
// NPM and Package Management Errors
|
|
1035
|
+
{
|
|
1036
|
+
name: "NPM_ERR_PEER_DEP_MISSING",
|
|
1037
|
+
match: /peer dep.*missing|unmet peer|WARN compat.*peer/i,
|
|
1038
|
+
explain: (error) => `
|
|
1039
|
+
A peer dependency is missing but required by a package.
|
|
1040
|
+
|
|
1041
|
+
Common causes:
|
|
1042
|
+
- Package version mismatch
|
|
1043
|
+
- Peer dependency not installed
|
|
1044
|
+
- Version incompatibility
|
|
1045
|
+
|
|
1046
|
+
Solution:
|
|
1047
|
+
1. Install missing peer dependency: npm install <package>
|
|
1048
|
+
2. Check package.json for correct versions
|
|
1049
|
+
3. Use npm ls to see dependency tree
|
|
1050
|
+
4. Update packages: npm update
|
|
1051
|
+
`.trim()
|
|
1052
|
+
},
|
|
1053
|
+
|
|
1054
|
+
{
|
|
1055
|
+
name: "NPM_AUDIT_VULNERABILITY",
|
|
1056
|
+
match: /npm audit|vulnerability|security|high severity|critical/i,
|
|
1057
|
+
explain: (error) => `
|
|
1058
|
+
Security vulnerability found in dependencies.
|
|
1059
|
+
|
|
1060
|
+
Common causes:
|
|
1061
|
+
- Outdated package with known vulnerability
|
|
1062
|
+
- Transitive dependency has security issue
|
|
1063
|
+
- Using unpatched version
|
|
1064
|
+
|
|
1065
|
+
Solution:
|
|
1066
|
+
1. Run: npm audit to see details
|
|
1067
|
+
2. Update packages: npm audit fix
|
|
1068
|
+
3. Check advisory details online
|
|
1069
|
+
4. Pin safe versions in package.json
|
|
1070
|
+
5. Keep dependencies up to date
|
|
1071
|
+
`.trim()
|
|
1072
|
+
},
|
|
1073
|
+
|
|
1074
|
+
{
|
|
1075
|
+
name: "NPM_INSTALL_FAILED",
|
|
1076
|
+
match: /npm ERR|install failed|cannot compile|build failed/i,
|
|
1077
|
+
explain: (error) => `
|
|
1078
|
+
Package installation failed - typically due to native dependency or build.
|
|
1079
|
+
|
|
1080
|
+
Common causes:
|
|
1081
|
+
- C++ compiler not available
|
|
1082
|
+
- Python not installed
|
|
1083
|
+
- Missing build tools
|
|
1084
|
+
- Node version mismatch
|
|
1085
|
+
|
|
1086
|
+
Solution:
|
|
1087
|
+
1. On Mac: xcode-select --install
|
|
1088
|
+
2. On Windows: npm install --global windows-build-tools
|
|
1089
|
+
3. On Linux: sudo apt-get install build-essential
|
|
1090
|
+
4. Check Node version: node --version
|
|
1091
|
+
5. Try: npm install --ignore-scripts
|
|
1092
|
+
`.trim()
|
|
1093
|
+
},
|
|
1094
|
+
|
|
1095
|
+
{
|
|
1096
|
+
name: "NPM_SHRINKWRAP_CONFLICT",
|
|
1097
|
+
match: /shrinkwrap|npm-shrinkwrap|package-lock.*conflict/i,
|
|
1098
|
+
explain: (error) => `
|
|
1099
|
+
Conflict between npm-shrinkwrap.json and package-lock.json.
|
|
1100
|
+
|
|
1101
|
+
Common causes:
|
|
1102
|
+
- Both lockfiles present
|
|
1103
|
+
- Lockfile corruption
|
|
1104
|
+
- Git merge conflict
|
|
1105
|
+
|
|
1106
|
+
Solution:
|
|
1107
|
+
1. Delete one: rm package-lock.json (if npm-shrinkwrap exists)
|
|
1108
|
+
2. Reinstall: npm install
|
|
1109
|
+
3. Use consistent lockfile strategy
|
|
1110
|
+
4. Don't commit both lockfiles
|
|
1111
|
+
`.trim()
|
|
1112
|
+
},
|
|
1113
|
+
|
|
1114
|
+
{
|
|
1115
|
+
name: "INVALID_PACKAGE_NAME",
|
|
1116
|
+
match: /Invalid package name|package name.*invalid|ERR.*name/i,
|
|
1117
|
+
explain: (error) => `
|
|
1118
|
+
Package name doesn't meet npm naming requirements.
|
|
1119
|
+
|
|
1120
|
+
Common causes:
|
|
1121
|
+
- Name contains uppercase letters
|
|
1122
|
+
- Name starts with dot or underscore
|
|
1123
|
+
- Name has special characters
|
|
1124
|
+
- Name too long
|
|
1125
|
+
|
|
1126
|
+
Solution:
|
|
1127
|
+
1. Use lowercase: name must be lowercase
|
|
1128
|
+
2. No dots or underscores at start
|
|
1129
|
+
3. Only alphanumeric, hyphens allowed
|
|
1130
|
+
4. Keep under 214 characters
|
|
1131
|
+
5. Check npm package naming rules
|
|
1132
|
+
`.trim()
|
|
1133
|
+
},
|
|
1134
|
+
|
|
1135
|
+
// TypeScript Errors
|
|
1136
|
+
{
|
|
1137
|
+
name: "TS_COMPILATION_ERROR",
|
|
1138
|
+
match: /TypeScript|\.ts.*error|TS\d+|tsc/i,
|
|
1139
|
+
explain: (error) => `
|
|
1140
|
+
TypeScript compilation error - type checking failed.
|
|
1141
|
+
|
|
1142
|
+
Common causes:
|
|
1143
|
+
- Type mismatch
|
|
1144
|
+
- Missing type definitions
|
|
1145
|
+
- Incompatible types
|
|
1146
|
+
- Type inference failed
|
|
1147
|
+
|
|
1148
|
+
Solution:
|
|
1149
|
+
1. Check error code: TS2345, TS2304, etc.
|
|
1150
|
+
2. Install type definitions: npm install --save-dev @types/package
|
|
1151
|
+
3. Use type annotations correctly
|
|
1152
|
+
4. Check tsconfig.json settings
|
|
1153
|
+
5. Use 'any' type as temporary fix (not recommended)
|
|
1154
|
+
`.trim()
|
|
1155
|
+
},
|
|
1156
|
+
|
|
1157
|
+
{
|
|
1158
|
+
name: "TS_CANNOT_FIND_NAME",
|
|
1159
|
+
match: /Cannot find name|TS2304|not defined/i,
|
|
1160
|
+
explain: (error) => `
|
|
1161
|
+
TypeScript can't find a variable, function, or type name.
|
|
1162
|
+
|
|
1163
|
+
Common causes:
|
|
1164
|
+
- Type definitions not installed
|
|
1165
|
+
- Variable not imported
|
|
1166
|
+
- Typo in name
|
|
1167
|
+
- Wrong scope
|
|
1168
|
+
|
|
1169
|
+
Solution:
|
|
1170
|
+
1. Install types: npm install --save-dev @types/package-name
|
|
1171
|
+
2. Import the variable/function
|
|
1172
|
+
3. Check spelling
|
|
1173
|
+
4. Verify variable is in scope
|
|
1174
|
+
5. Use: declare let variable: any (as workaround)
|
|
1175
|
+
`.trim()
|
|
1176
|
+
},
|
|
1177
|
+
|
|
1178
|
+
{
|
|
1179
|
+
name: "TS_PROPERTY_DOES_NOT_EXIST",
|
|
1180
|
+
match: /has no property|TS2339|Property.*does not exist/i,
|
|
1181
|
+
explain: (error) => `
|
|
1182
|
+
Trying to access property that doesn't exist in type.
|
|
1183
|
+
|
|
1184
|
+
Common causes:
|
|
1185
|
+
- Property name typo
|
|
1186
|
+
- Property not in type definition
|
|
1187
|
+
- Using wrong object
|
|
1188
|
+
- Version mismatch of types
|
|
1189
|
+
|
|
1190
|
+
Solution:
|
|
1191
|
+
1. Check property spelling
|
|
1192
|
+
2. Verify type definition includes property
|
|
1193
|
+
3. Use type assertion: (obj as any).property
|
|
1194
|
+
4. Update type definitions
|
|
1195
|
+
5. Check documentation for correct property name
|
|
1196
|
+
`.trim()
|
|
1197
|
+
},
|
|
1198
|
+
|
|
1199
|
+
{
|
|
1200
|
+
name: "TS_ARGUMENT_MISMATCH",
|
|
1201
|
+
match: /Argument of type|TS2345|not assignable/i,
|
|
1202
|
+
explain: (error) => `
|
|
1203
|
+
Function argument type doesn't match expected type.
|
|
1204
|
+
|
|
1205
|
+
Common causes:
|
|
1206
|
+
- Wrong type passed
|
|
1207
|
+
- Incompatible types
|
|
1208
|
+
- Missing optional property
|
|
1209
|
+
- Extra properties not allowed
|
|
1210
|
+
|
|
1211
|
+
Solution:
|
|
1212
|
+
1. Check expected type in function signature
|
|
1213
|
+
2. Cast to correct type: myFunc(x as ExpectedType)
|
|
1214
|
+
3. Convert type: String(value) or parseInt()
|
|
1215
|
+
4. Use type assertion in function call
|
|
1216
|
+
5. Check library documentation for correct types
|
|
1217
|
+
`.trim()
|
|
1218
|
+
},
|
|
1219
|
+
|
|
1220
|
+
// Promise and Async Errors
|
|
1221
|
+
{
|
|
1222
|
+
name: "ASYNC_ITERATOR_ERROR",
|
|
1223
|
+
match: /async iterator|for await|Symbol\.asyncIterator/i,
|
|
1224
|
+
explain: (error) => `
|
|
1225
|
+
Error with async iterators or for-await loops.
|
|
1226
|
+
|
|
1227
|
+
Common causes:
|
|
1228
|
+
- Object doesn't implement async iterator
|
|
1229
|
+
- Using for-await on non-async iterable
|
|
1230
|
+
- Invalid async generator
|
|
1231
|
+
|
|
1232
|
+
Solution:
|
|
1233
|
+
1. Implement Symbol.asyncIterator
|
|
1234
|
+
2. Use proper async generator: async function*
|
|
1235
|
+
3. Use for-await only with async iterables
|
|
1236
|
+
4. Convert to Promise if needed
|
|
1237
|
+
`.trim()
|
|
1238
|
+
},
|
|
1239
|
+
|
|
1240
|
+
{
|
|
1241
|
+
name: "PROMISE_CONSTRUCTOR_EXECUTOR_ERROR",
|
|
1242
|
+
match: /Promise executor|executor threw/i,
|
|
1243
|
+
explain: (error) => `
|
|
1244
|
+
Error thrown in Promise constructor executor function.
|
|
1245
|
+
|
|
1246
|
+
Common causes:
|
|
1247
|
+
- Synchronous error in executor
|
|
1248
|
+
- resolve/reject called twice
|
|
1249
|
+
- Executor throws exception
|
|
1250
|
+
|
|
1251
|
+
Solution:
|
|
1252
|
+
1. Wrap executor in try/catch
|
|
1253
|
+
2. Call resolve/reject only once
|
|
1254
|
+
3. Ensure executor returns sync operation
|
|
1255
|
+
4. Use: new Promise((resolve, reject) => { })
|
|
1256
|
+
`.trim()
|
|
1257
|
+
},
|
|
1258
|
+
|
|
1259
|
+
{
|
|
1260
|
+
name: "CANNOT_USE_AWAIT_OUTSIDE_ASYNC",
|
|
1261
|
+
match: /await.*outside|not in async|TS1308|Unexpected.*await/i,
|
|
1262
|
+
explain: (error) => `
|
|
1263
|
+
Using await outside async function context.
|
|
1264
|
+
|
|
1265
|
+
Common causes:
|
|
1266
|
+
- await in non-async function
|
|
1267
|
+
- Top-level await without module type
|
|
1268
|
+
- Missing async keyword
|
|
1269
|
+
|
|
1270
|
+
Solution:
|
|
1271
|
+
1. Add async: async function myFunc() { await ... }
|
|
1272
|
+
2. For top-level await, set in tsconfig or package.json
|
|
1273
|
+
3. Use .then() instead of await if can't use async
|
|
1274
|
+
4. Wrap in async IIFE: (async () => { await ... })()
|
|
1275
|
+
`.trim()
|
|
1276
|
+
},
|
|
1277
|
+
|
|
1278
|
+
// Database Errors
|
|
1279
|
+
{
|
|
1280
|
+
name: "POSTGRES_CONNECTION_ERROR",
|
|
1281
|
+
match: /postgres|postgresql|ECONNREFUSED.*5432|pg error/i,
|
|
1282
|
+
explain: (error) => `
|
|
1283
|
+
Cannot connect to PostgreSQL database.
|
|
1284
|
+
|
|
1285
|
+
Common causes:
|
|
1286
|
+
- PostgreSQL server not running
|
|
1287
|
+
- Wrong host/port/credentials
|
|
1288
|
+
- Firewall blocking connection
|
|
1289
|
+
- Connection pool exhausted
|
|
1290
|
+
|
|
1291
|
+
Solution:
|
|
1292
|
+
1. Verify PostgreSQL running: brew services list
|
|
1293
|
+
2. Check connection string in env
|
|
1294
|
+
3. Default port is 5432
|
|
1295
|
+
4. Verify user/password correct
|
|
1296
|
+
5. Check firewall rules if remote
|
|
1297
|
+
`.trim()
|
|
1298
|
+
},
|
|
1299
|
+
|
|
1300
|
+
{
|
|
1301
|
+
name: "REDIS_CONNECTION_ERROR",
|
|
1302
|
+
match: /redis|ECONNREFUSED.*6379|redis error|ERR unknown command/i,
|
|
1303
|
+
explain: (error) => `
|
|
1304
|
+
Cannot connect to or communicate with Redis.
|
|
1305
|
+
|
|
1306
|
+
Common causes:
|
|
1307
|
+
- Redis server not running
|
|
1308
|
+
- Wrong host/port
|
|
1309
|
+
- Redis command syntax error
|
|
1310
|
+
- Version incompatibility
|
|
1311
|
+
|
|
1312
|
+
Solution:
|
|
1313
|
+
1. Start Redis: redis-server
|
|
1314
|
+
2. Check port 6379 is listening
|
|
1315
|
+
3. Verify Redis CLI works: redis-cli
|
|
1316
|
+
4. Check command syntax in docs
|
|
1317
|
+
5. Clear cache if corrupted: FLUSHALL
|
|
1318
|
+
`.trim()
|
|
1319
|
+
},
|
|
1320
|
+
|
|
1321
|
+
{
|
|
1322
|
+
name: "MYSQL_CONNECTION_ERROR",
|
|
1323
|
+
match: /mysql|PROTOCOL_CONNECTION_LOST|PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR/i,
|
|
1324
|
+
explain: (error) => `
|
|
1325
|
+
MySQL connection failed or lost.
|
|
1326
|
+
|
|
1327
|
+
Common causes:
|
|
1328
|
+
- MySQL server not running
|
|
1329
|
+
- Wrong host/port/user/password
|
|
1330
|
+
- Connection timeout
|
|
1331
|
+
- Too many connections
|
|
1332
|
+
|
|
1333
|
+
Solution:
|
|
1334
|
+
1. Start MySQL: brew services start mysql
|
|
1335
|
+
2. Check user/password in config
|
|
1336
|
+
3. Use connection pool: maxConnections: 10
|
|
1337
|
+
4. Add timeout: connectionTimeoutMillis: 5000
|
|
1338
|
+
5. Check MySQL is accessible
|
|
1339
|
+
`.trim()
|
|
1340
|
+
},
|
|
1341
|
+
|
|
1342
|
+
{
|
|
1343
|
+
name: "DYNAMODB_ERROR",
|
|
1344
|
+
match: /DynamoDB|ResourceNotFoundException|ValidationException|AWS|dynamodb/i,
|
|
1345
|
+
explain: (error) => `
|
|
1346
|
+
AWS DynamoDB operation failed.
|
|
1347
|
+
|
|
1348
|
+
Common causes:
|
|
1349
|
+
- Table doesn't exist
|
|
1350
|
+
- Invalid key/attribute
|
|
1351
|
+
- Wrong AWS credentials
|
|
1352
|
+
- Rate limiting
|
|
1353
|
+
|
|
1354
|
+
Solution:
|
|
1355
|
+
1. Verify table exists
|
|
1356
|
+
2. Check primary key format
|
|
1357
|
+
3. Verify AWS credentials configured
|
|
1358
|
+
4. Check IAM permissions
|
|
1359
|
+
5. Add exponential backoff for throttling
|
|
1360
|
+
`.trim()
|
|
1361
|
+
},
|
|
1362
|
+
|
|
1363
|
+
// Regex Errors
|
|
1364
|
+
{
|
|
1365
|
+
name: "REGEX_SYNTAX_ERROR",
|
|
1366
|
+
match: /Invalid regular expression|regex.*error|regex.*invalid|unterminated/i,
|
|
1367
|
+
explain: (error) => `
|
|
1368
|
+
Invalid regular expression pattern.
|
|
1369
|
+
|
|
1370
|
+
Common causes:
|
|
1371
|
+
- Unescaped special characters
|
|
1372
|
+
- Unclosed bracket or group
|
|
1373
|
+
- Invalid range in character class
|
|
1374
|
+
- Backslash not escaped
|
|
1375
|
+
|
|
1376
|
+
Solution:
|
|
1377
|
+
1. Escape special chars: \\(, \\), \\[, \\], \\.
|
|
1378
|
+
2. Check all brackets balanced
|
|
1379
|
+
3. Use regex validator: regexr.com
|
|
1380
|
+
4. Escape backslashes: \\\\ in string literals
|
|
1381
|
+
5. Test regex before use
|
|
1382
|
+
`.trim()
|
|
1383
|
+
},
|
|
1384
|
+
|
|
1385
|
+
{
|
|
1386
|
+
name: "REGEX_CATASTROPHIC_BACKTRACKING",
|
|
1387
|
+
match: /backtrack|catastrophic|hangs|freezes|regex.*slow/i,
|
|
1388
|
+
explain: (error) => `
|
|
1389
|
+
Regex pattern causes catastrophic backtracking - very slow.
|
|
1390
|
+
|
|
1391
|
+
Common causes:
|
|
1392
|
+
- Overlapping quantifiers: (a+)+
|
|
1393
|
+
- Complex nested quantifiers
|
|
1394
|
+
- Alternation with overlap: a|ab
|
|
1395
|
+
|
|
1396
|
+
Solution:
|
|
1397
|
+
1. Simplify regex pattern
|
|
1398
|
+
2. Avoid nested quantifiers
|
|
1399
|
+
3. Use atomic grouping: (?>...)
|
|
1400
|
+
4. Be specific with character classes
|
|
1401
|
+
5. Test performance: test on large strings
|
|
1402
|
+
`.trim()
|
|
1403
|
+
},
|
|
1404
|
+
|
|
1405
|
+
// Security Errors
|
|
1406
|
+
{
|
|
1407
|
+
name: "SQL_INJECTION_WARNING",
|
|
1408
|
+
match: /SQL injection|sql.*dangerous|unsafe sql|concatenat.*query/i,
|
|
1409
|
+
explain: (error) => `
|
|
1410
|
+
SQL injection vulnerability detected - using unsanitized user input in SQL.
|
|
1411
|
+
|
|
1412
|
+
Common causes:
|
|
1413
|
+
- Concatenating user input into SQL
|
|
1414
|
+
- Not using parameterized queries
|
|
1415
|
+
- Trusting user input
|
|
1416
|
+
|
|
1417
|
+
Solution:
|
|
1418
|
+
1. Use parameterized queries: db.query('SELECT * FROM users WHERE id = ?', [id])
|
|
1419
|
+
2. Use ORM: Sequelize, Knex, TypeORM
|
|
1420
|
+
3. Validate and sanitize input
|
|
1421
|
+
4. Use prepared statements
|
|
1422
|
+
5. Never concatenate user input
|
|
1423
|
+
`.trim()
|
|
1424
|
+
},
|
|
1425
|
+
|
|
1426
|
+
{
|
|
1427
|
+
name: "XSS_VULNERABILITY",
|
|
1428
|
+
match: /XSS|cross.?site.*scripting|innerHTML|dangerouslySetInnerHTML/i,
|
|
1429
|
+
explain: (error) => `
|
|
1430
|
+
Cross-site scripting (XSS) vulnerability - unsanitized HTML injection risk.
|
|
1431
|
+
|
|
1432
|
+
Common causes:
|
|
1433
|
+
- Setting innerHTML with user input
|
|
1434
|
+
- Not escaping user data
|
|
1435
|
+
- Using dangerouslySetInnerHTML
|
|
1436
|
+
- Reflected XSS in URL
|
|
1437
|
+
|
|
1438
|
+
Solution:
|
|
1439
|
+
1. Use textContent instead of innerHTML
|
|
1440
|
+
2. Escape HTML: use DOMPurify or similar
|
|
1441
|
+
3. Use templating safely
|
|
1442
|
+
4. Content Security Policy headers
|
|
1443
|
+
5. Validate and sanitize all inputs
|
|
1444
|
+
`.trim()
|
|
1445
|
+
},
|
|
1446
|
+
|
|
1447
|
+
{
|
|
1448
|
+
name: "SENSITIVE_DATA_EXPOSURE",
|
|
1449
|
+
match: /password|api.?key|secret|token.*log|hardcoded|credentials/i,
|
|
1450
|
+
explain: (error) => `
|
|
1451
|
+
Sensitive data exposed in logs or code.
|
|
1452
|
+
|
|
1453
|
+
Common causes:
|
|
1454
|
+
- Passwords/keys in source code
|
|
1455
|
+
- Logging sensitive data
|
|
1456
|
+
- Committing .env files
|
|
1457
|
+
- Hardcoded credentials
|
|
1458
|
+
|
|
1459
|
+
Solution:
|
|
1460
|
+
1. Use environment variables
|
|
1461
|
+
2. Add .env to .gitignore
|
|
1462
|
+
3. Use dotenv package
|
|
1463
|
+
4. Don't log passwords/tokens
|
|
1464
|
+
5. Use secrets management (AWS Secrets, Vault)
|
|
1465
|
+
`.trim()
|
|
1466
|
+
},
|
|
1467
|
+
|
|
1468
|
+
// Express/Web Framework Errors
|
|
1469
|
+
{
|
|
1470
|
+
name: "EXPRESS_MIDDLEWARE_ERROR",
|
|
1471
|
+
match: /middleware|app\.use|Express.*middleware|next.*not.*called/i,
|
|
1472
|
+
explain: (error) => `
|
|
1473
|
+
Express middleware error - typically not calling next().
|
|
1474
|
+
|
|
1475
|
+
Common causes:
|
|
1476
|
+
- Forgot to call next() in middleware
|
|
1477
|
+
- next() called multiple times
|
|
1478
|
+
- Error in middleware execution
|
|
1479
|
+
- Middleware not registered
|
|
1480
|
+
|
|
1481
|
+
Solution:
|
|
1482
|
+
1. Call next() to continue chain: next()
|
|
1483
|
+
2. Or send response: res.send()
|
|
1484
|
+
3. Add error handling: (err, req, res, next) => {}
|
|
1485
|
+
4. Register middleware early: app.use(middleware)
|
|
1486
|
+
5. Order matters - put error handlers last
|
|
1487
|
+
`.trim()
|
|
1488
|
+
},
|
|
1489
|
+
|
|
1490
|
+
{
|
|
1491
|
+
name: "NEXT_JS_HYDRATION_ERROR",
|
|
1492
|
+
match: /hydration|hydratation.*mismatch|useEffect|window.*undefined/i,
|
|
1493
|
+
explain: (error) => `
|
|
1494
|
+
Next.js hydration mismatch - server and client render different HTML.
|
|
1495
|
+
|
|
1496
|
+
Common causes:
|
|
1497
|
+
- Using window object in render (no SSR)
|
|
1498
|
+
- Date/random values differ between renders
|
|
1499
|
+
- Conditional rendering based on client state
|
|
1500
|
+
- CSS-in-JS not applied on server
|
|
1501
|
+
|
|
1502
|
+
Solution:
|
|
1503
|
+
1. Move window access to useEffect
|
|
1504
|
+
2. Use dynamic imports: dynamic(() => import(...), { ssr: false })
|
|
1505
|
+
3. Generate same value on server and client
|
|
1506
|
+
4. Use Date/Math.random consistently
|
|
1507
|
+
5. Ensure CSS is applied on both server and client
|
|
1508
|
+
`.trim()
|
|
1509
|
+
},
|
|
1510
|
+
|
|
1511
|
+
{
|
|
1512
|
+
name: "NEST_JS_DEPENDENCY_ERROR",
|
|
1513
|
+
match: /NestJS|Cannot resolve dependency|Nest.*error|@Injectable/i,
|
|
1514
|
+
explain: (error) => `
|
|
1515
|
+
NestJS dependency injection failed - can't resolve a dependency.
|
|
1516
|
+
|
|
1517
|
+
Common causes:
|
|
1518
|
+
- Service not provided
|
|
1519
|
+
- Circular dependency
|
|
1520
|
+
- Service not decorated with @Injectable()
|
|
1521
|
+
- Wrong module import
|
|
1522
|
+
|
|
1523
|
+
Solution:
|
|
1524
|
+
1. Add @Injectable() decorator to service
|
|
1525
|
+
2. Provide in module: providers: [MyService]
|
|
1526
|
+
3. Import module in imports: []
|
|
1527
|
+
4. Check for circular dependencies
|
|
1528
|
+
5. Use forwardRef() if circular: forwardRef(() => MyService)
|
|
1529
|
+
`.trim()
|
|
1530
|
+
},
|
|
1531
|
+
|
|
1532
|
+
// Encoding Errors
|
|
1533
|
+
{
|
|
1534
|
+
name: "ICONV_ENCODING_ERROR",
|
|
1535
|
+
match: /iconv|encoding.*fail|decode.*error|encode.*error/i,
|
|
1536
|
+
explain: (error) => `
|
|
1537
|
+
Character encoding conversion failed.
|
|
1538
|
+
|
|
1539
|
+
Common causes:
|
|
1540
|
+
- Unsupported encoding
|
|
1541
|
+
- Corrupted encoded data
|
|
1542
|
+
- Encoding mismatch
|
|
1543
|
+
|
|
1544
|
+
Solution:
|
|
1545
|
+
1. Use correct encoding name
|
|
1546
|
+
2. Validate encoding before conversion
|
|
1547
|
+
3. Use try/catch for encoding operations
|
|
1548
|
+
4. Use Buffer for binary data
|
|
1549
|
+
5. Check data integrity
|
|
1550
|
+
`.trim()
|
|
1551
|
+
},
|
|
1552
|
+
|
|
1553
|
+
{
|
|
1554
|
+
name: "UTF8_SURROGATE_ERROR",
|
|
1555
|
+
match: /surrogate|UTF-16.*surrogate|encoded.*invalid/i,
|
|
1556
|
+
explain: (error) => `
|
|
1557
|
+
Invalid UTF-8 surrogate pair in text encoding.
|
|
1558
|
+
|
|
1559
|
+
Common causes:
|
|
1560
|
+
- Mixing UTF-8 and UTF-16
|
|
1561
|
+
- Invalid surrogate handling
|
|
1562
|
+
- Corrupt file encoding
|
|
1563
|
+
|
|
1564
|
+
Solution:
|
|
1565
|
+
1. Validate UTF-8 data
|
|
1566
|
+
2. Use Buffer.toString('utf8')
|
|
1567
|
+
3. Check file encoding in editor
|
|
1568
|
+
4. Convert consistently: iconv-lite
|
|
1569
|
+
5. Handle invalid sequences: replace with replacement char
|
|
1570
|
+
`.trim()
|
|
1571
|
+
},
|
|
1572
|
+
|
|
1573
|
+
// Performance Errors
|
|
1574
|
+
{
|
|
1575
|
+
name: "PERFORMANCE_MEMORY_WARNING",
|
|
1576
|
+
match: /memory usage|heap|garbage collection|V8|memory pressure/i,
|
|
1577
|
+
explain: (error) => `
|
|
1578
|
+
Memory usage warning - application using too much heap.
|
|
1579
|
+
|
|
1580
|
+
Common causes:
|
|
1581
|
+
- Memory leak accumulating
|
|
1582
|
+
- Large objects not released
|
|
1583
|
+
- Too many event listeners
|
|
1584
|
+
- Cache growing unbounded
|
|
1585
|
+
|
|
1586
|
+
Solution:
|
|
1587
|
+
1. Profile memory: node --inspect app.js
|
|
1588
|
+
2. Check for event listener leaks
|
|
1589
|
+
3. Implement cache size limits
|
|
1590
|
+
4. Use WeakMap/WeakSet for object references
|
|
1591
|
+
5. Monitor with process.memoryUsage()
|
|
1592
|
+
`.trim()
|
|
1593
|
+
},
|
|
1594
|
+
|
|
1595
|
+
{
|
|
1596
|
+
name: "SLOW_QUERY_WARNING",
|
|
1597
|
+
match: /slow query|query.*slow|milliseconds.*exceeded|threshold/i,
|
|
1598
|
+
explain: (error) => `
|
|
1599
|
+
Database query is slow and exceeds threshold.
|
|
1600
|
+
|
|
1601
|
+
Common causes:
|
|
1602
|
+
- Missing database index
|
|
1603
|
+
- Full table scan
|
|
1604
|
+
- Complex JOIN
|
|
1605
|
+
- Large result set
|
|
1606
|
+
|
|
1607
|
+
Solution:
|
|
1608
|
+
1. Add database index on queried columns
|
|
1609
|
+
2. Use EXPLAIN to analyze query
|
|
1610
|
+
3. Limit result set: LIMIT, OFFSET
|
|
1611
|
+
4. Use better queries, avoid N+1
|
|
1612
|
+
5. Consider caching frequently accessed data
|
|
1613
|
+
`.trim()
|
|
1614
|
+
},
|
|
1615
|
+
|
|
1616
|
+
{
|
|
1617
|
+
name: "EVENT_EMITTER_MEMORY_LEAK",
|
|
1618
|
+
match: /EventEmitter|memory leak|listener.*leak|removeListener|maxListeners/i,
|
|
1619
|
+
explain: (error) => `
|
|
1620
|
+
Event emitter accumulating listeners causing memory leak.
|
|
1621
|
+
|
|
1622
|
+
Common causes:
|
|
1623
|
+
- Not removing event listeners
|
|
1624
|
+
- Listeners added repeatedly
|
|
1625
|
+
- Circular references in listeners
|
|
1626
|
+
|
|
1627
|
+
Solution:
|
|
1628
|
+
1. Remove listeners: emitter.removeListener('event', handler)
|
|
1629
|
+
2. Use once instead of on: emitter.once('event', handler)
|
|
1630
|
+
3. Increase if needed: emitter.setMaxListeners(100)
|
|
1631
|
+
4. Check for circular references
|
|
1632
|
+
5. Use .removeAllListeners() carefully
|
|
1633
|
+
`.trim()
|
|
1634
|
+
},
|
|
1635
|
+
|
|
1636
|
+
// Stream Errors
|
|
1637
|
+
{
|
|
1638
|
+
name: "STREAM_BACKPRESSURE_ERROR",
|
|
1639
|
+
match: /stream.*backpressure|pipe.*drain|writable.*end|high water mark/i,
|
|
1640
|
+
explain: (error) => `
|
|
1641
|
+
Stream backpressure not handled - writing faster than reading.
|
|
1642
|
+
|
|
1643
|
+
Common causes:
|
|
1644
|
+
- Not checking write return value
|
|
1645
|
+
- Not listening to drain event
|
|
1646
|
+
- Writing to slow stream too fast
|
|
1647
|
+
|
|
1648
|
+
Solution:
|
|
1649
|
+
1. Check write() return value
|
|
1650
|
+
2. Listen to drain event: stream.on('drain', ...)
|
|
1651
|
+
3. Pause reading: readable.pause()
|
|
1652
|
+
4. Use pipe(): readStream.pipe(writeStream)
|
|
1653
|
+
5. Respect high water mark
|
|
1654
|
+
`.trim()
|
|
1655
|
+
},
|
|
1656
|
+
|
|
1657
|
+
{
|
|
1658
|
+
name: "STREAM_ENCODING_ERROR",
|
|
1659
|
+
match: /stream.*encoding|setEncoding|encoding.*stream/i,
|
|
1660
|
+
explain: (error) => `
|
|
1661
|
+
Stream encoding configuration error.
|
|
1662
|
+
|
|
1663
|
+
Common causes:
|
|
1664
|
+
- Invalid encoding name
|
|
1665
|
+
- setEncoding called after data event
|
|
1666
|
+
- Encoding mismatch
|
|
1667
|
+
|
|
1668
|
+
Solution:
|
|
1669
|
+
1. Call setEncoding before reading: stream.setEncoding('utf8')
|
|
1670
|
+
2. Use valid encoding names
|
|
1671
|
+
3. Avoid setEncoding with binary data
|
|
1672
|
+
4. Handle encoding consistently
|
|
1673
|
+
`.trim()
|
|
1674
|
+
},
|
|
1675
|
+
|
|
1676
|
+
// OS and System Errors
|
|
1677
|
+
{
|
|
1678
|
+
name: "ESRCH_PROCESS_NOT_FOUND",
|
|
1679
|
+
match: /ESRCH|no such process|process.*not.*found/i,
|
|
1680
|
+
explain: (error) => `
|
|
1681
|
+
Process specified doesn't exist or has already exited.
|
|
1682
|
+
|
|
1683
|
+
Common causes:
|
|
1684
|
+
- Process ID no longer valid
|
|
1685
|
+
- Process exited
|
|
1686
|
+
- Trying to kill non-existent process
|
|
1687
|
+
|
|
1688
|
+
Solution:
|
|
1689
|
+
1. Check process exists before operation
|
|
1690
|
+
2. Try/catch around process operations
|
|
1691
|
+
3. Use process manager: PM2, Forever
|
|
1692
|
+
4. Check PID validity
|
|
1693
|
+
`.trim()
|
|
1694
|
+
},
|
|
1695
|
+
|
|
1696
|
+
{
|
|
1697
|
+
name: "EAGAIN_TRY_AGAIN",
|
|
1698
|
+
match: /EAGAIN|try again|temporarily unavailable|resource temporarily/i,
|
|
1699
|
+
explain: (error) => `
|
|
1700
|
+
Operation temporarily unavailable - try again later.
|
|
1701
|
+
|
|
1702
|
+
Common causes:
|
|
1703
|
+
- System resource temporarily unavailable
|
|
1704
|
+
- Rate limited
|
|
1705
|
+
- Resource contention
|
|
1706
|
+
|
|
1707
|
+
Solution:
|
|
1708
|
+
1. Implement retry with exponential backoff
|
|
1709
|
+
2. Wait and try again: setTimeout(() => retry(), 100)
|
|
1710
|
+
3. Check system resources
|
|
1711
|
+
4. Reduce concurrent operations
|
|
1712
|
+
`.trim()
|
|
1713
|
+
},
|
|
1714
|
+
|
|
1715
|
+
// File System Advanced Errors
|
|
1716
|
+
{
|
|
1717
|
+
name: "FILE_DESCRIPTOR_LIMIT",
|
|
1718
|
+
match: /EMFILE|too many open files|ulimit/i,
|
|
1719
|
+
explain: (error) => `
|
|
1720
|
+
Hit system limit for open file descriptors.
|
|
1721
|
+
|
|
1722
|
+
Common causes:
|
|
1723
|
+
- Too many files open simultaneously
|
|
1724
|
+
- File handles not closed
|
|
1725
|
+
- Process needs more file descriptors
|
|
1726
|
+
|
|
1727
|
+
Solution:
|
|
1728
|
+
1. Close files after use: stream.end()
|
|
1729
|
+
2. Increase limit: ulimit -n 4096 (Mac/Linux)
|
|
1730
|
+
3. Use connection pooling
|
|
1731
|
+
4. Implement file descriptor management
|
|
1732
|
+
5. Monitor: lsof -p PID
|
|
1733
|
+
`.trim()
|
|
1734
|
+
},
|
|
1735
|
+
|
|
1736
|
+
{
|
|
1737
|
+
name: "SYMBOLIC_LINK_ERROR",
|
|
1738
|
+
match: /symbolic link|symlink|ELOOP|too many.*link|circular.*link/i,
|
|
1739
|
+
explain: (error) => `
|
|
1740
|
+
Error with symbolic links - circular reference or too many levels.
|
|
1741
|
+
|
|
1742
|
+
Common causes:
|
|
1743
|
+
- Circular symbolic link
|
|
1744
|
+
- Too many symlink levels
|
|
1745
|
+
- Following symlink not allowed
|
|
1746
|
+
|
|
1747
|
+
Solution:
|
|
1748
|
+
1. Check for circular references
|
|
1749
|
+
2. Limit symlink following depth
|
|
1750
|
+
3. Use realpath to resolve: fs.realpathSync()
|
|
1751
|
+
4. Avoid symlinks across boundaries
|
|
1752
|
+
5. Break circular references
|
|
1753
|
+
`.trim()
|
|
1754
|
+
},
|
|
1755
|
+
|
|
1756
|
+
{
|
|
1757
|
+
name: "FILE_ALREADY_IN_USE",
|
|
1758
|
+
match: /EBUSY|file.*in use|already.*use|busy|open by another/i,
|
|
1759
|
+
explain: (error) => `
|
|
1760
|
+
File is currently in use by another process.
|
|
1761
|
+
|
|
1762
|
+
Common causes:
|
|
1763
|
+
- File locked by another process
|
|
1764
|
+
- Still being written by editor
|
|
1765
|
+
- Haven't closed handle properly
|
|
1766
|
+
|
|
1767
|
+
Solution:
|
|
1768
|
+
1. Close file handles explicitly
|
|
1769
|
+
2. Wait before accessing: setTimeout(..., 100)
|
|
1770
|
+
3. Use file locking library
|
|
1771
|
+
4. Close editor if editing file
|
|
1772
|
+
5. Use exclusive locks when needed
|
|
1773
|
+
`.trim()
|
|
1774
|
+
},
|
|
1775
|
+
|
|
1776
|
+
// Buffer Errors
|
|
1777
|
+
{
|
|
1778
|
+
name: "BUFFER_OUT_OF_BOUNDS",
|
|
1779
|
+
match: /Buffer.*out of bounds|offset.*out|Buffer overflow|offset is out/i,
|
|
1780
|
+
explain: (error) => `
|
|
1781
|
+
Buffer operation attempted outside valid range.
|
|
1782
|
+
|
|
1783
|
+
Common causes:
|
|
1784
|
+
- Offset exceeds buffer length
|
|
1785
|
+
- Write beyond buffer size
|
|
1786
|
+
- Invalid buffer size
|
|
1787
|
+
|
|
1788
|
+
Solution:
|
|
1789
|
+
1. Check offset < buffer.length
|
|
1790
|
+
2. Allocate sufficient buffer size
|
|
1791
|
+
3. Use: Buffer.alloc(size) for safe allocation
|
|
1792
|
+
4. Validate offset before operations
|
|
1793
|
+
5. Use Buffer.allocUnsafe() carefully
|
|
1794
|
+
`.trim()
|
|
1795
|
+
},
|
|
1796
|
+
|
|
1797
|
+
{
|
|
1798
|
+
name: "BUFFER_ENCODING_WRITE_ERROR",
|
|
1799
|
+
match: /write.*encoding|encoding.*write|invalid.*encoding.*buffer/i,
|
|
1800
|
+
explain: (error) => `
|
|
1801
|
+
Buffer write failed due to encoding issue.
|
|
1802
|
+
|
|
1803
|
+
Common causes:
|
|
1804
|
+
- Invalid encoding for write
|
|
1805
|
+
- Data not compatible with encoding
|
|
1806
|
+
- Offset calculation error
|
|
1807
|
+
|
|
1808
|
+
Solution:
|
|
1809
|
+
1. Use valid encoding: utf8, base64, hex, ascii
|
|
1810
|
+
2. Ensure data matches encoding
|
|
1811
|
+
3. Calculate offset correctly
|
|
1812
|
+
4. Use Buffer.from() with encoding parameter
|
|
1813
|
+
5. Verify data format
|
|
1814
|
+
`.trim()
|
|
1815
|
+
},
|
|
1816
|
+
|
|
1817
|
+
// Crypto Errors
|
|
1818
|
+
{
|
|
1819
|
+
name: "CRYPTO_ALGORITHM_ERROR",
|
|
1820
|
+
match: /crypto|cipher.*unknown|algorithm.*unknown|invalid.*algorithm/i,
|
|
1821
|
+
explain: (error) => `
|
|
1822
|
+
Invalid or unsupported cryptographic algorithm.
|
|
1823
|
+
|
|
1824
|
+
Common causes:
|
|
1825
|
+
- Unknown cipher name
|
|
1826
|
+
- Algorithm not available
|
|
1827
|
+
- Wrong algorithm name
|
|
1828
|
+
|
|
1829
|
+
Solution:
|
|
1830
|
+
1. Use supported algorithms: crypto.getCiphers()
|
|
1831
|
+
2. Common: aes-256-cbc, sha256
|
|
1832
|
+
3. Check Node.js crypto support
|
|
1833
|
+
4. Use correct algorithm names
|
|
1834
|
+
5. Update Node.js if algorithm missing
|
|
1835
|
+
`.trim()
|
|
1836
|
+
},
|
|
1837
|
+
|
|
1838
|
+
{
|
|
1839
|
+
name: "CRYPTO_KEY_ERROR",
|
|
1840
|
+
match: /key.*invalid|key.*error|EVP_.*error|private key|public key/i,
|
|
1841
|
+
explain: (error) => `
|
|
1842
|
+
Cryptographic key is invalid or incorrectly formatted.
|
|
1843
|
+
|
|
1844
|
+
Common causes:
|
|
1845
|
+
- Key wrong length
|
|
1846
|
+
- Key wrong format
|
|
1847
|
+
- Corrupted key
|
|
1848
|
+
- Wrong key type
|
|
1849
|
+
|
|
1850
|
+
Solution:
|
|
1851
|
+
1. Verify key length matches algorithm
|
|
1852
|
+
2. Ensure PEM format if using files
|
|
1853
|
+
3. Check key generation: crypto.generateKeyPairSync()
|
|
1854
|
+
4. Validate key format before use
|
|
1855
|
+
5. Use crypto libraries: node-rsa, libsodium
|
|
1856
|
+
`.trim()
|
|
1857
|
+
},
|
|
1858
|
+
|
|
1859
|
+
// Cluster Errors
|
|
1860
|
+
{
|
|
1861
|
+
name: "CLUSTER_FORK_ERROR",
|
|
1862
|
+
match: /cluster|fork.*failed|worker.*failed|clusters/i,
|
|
1863
|
+
explain: (error) => `
|
|
1864
|
+
Node.js cluster worker failed to fork or initialize.
|
|
1865
|
+
|
|
1866
|
+
Common causes:
|
|
1867
|
+
- Resource limit exceeded
|
|
1868
|
+
- Worker code has error
|
|
1869
|
+
- Memory insufficient
|
|
1870
|
+
|
|
1871
|
+
Solution:
|
|
1872
|
+
1. Check ulimit for process limits
|
|
1873
|
+
2. Validate worker code runs standalone
|
|
1874
|
+
3. Handle worker crashes: cluster.on('exit')
|
|
1875
|
+
4. Add graceful shutdown
|
|
1876
|
+
5. Use process manager: PM2, systemd
|
|
1877
|
+
`.trim()
|
|
1878
|
+
},
|
|
1879
|
+
|
|
1880
|
+
// Worker Threads Errors
|
|
1881
|
+
{
|
|
1882
|
+
name: "WORKER_THREAD_ERROR",
|
|
1883
|
+
match: /Worker|worker.*thread|ERR_WORKER_INVALID_EXEC_ARGV/i,
|
|
1884
|
+
explain: (error) => `
|
|
1885
|
+
Error in worker thread creation or execution.
|
|
1886
|
+
|
|
1887
|
+
Common causes:
|
|
1888
|
+
- Worker file has syntax error
|
|
1889
|
+
- Invalid worker options
|
|
1890
|
+
- Resource limit hit
|
|
1891
|
+
|
|
1892
|
+
Solution:
|
|
1893
|
+
1. Ensure worker file runs standalone
|
|
1894
|
+
2. Use correct API: new Worker(filename)
|
|
1895
|
+
3. Handle worker errors: worker.on('error')
|
|
1896
|
+
4. Properly initialize worker
|
|
1897
|
+
5. Clean up workers: worker.terminate()
|
|
1898
|
+
`.trim()
|
|
1899
|
+
},
|
|
1900
|
+
|
|
1901
|
+
// Crypto Key Pair Errors
|
|
1902
|
+
{
|
|
1903
|
+
name: "RSA_KEY_GENERATION_ERROR",
|
|
1904
|
+
match: /RSA|key pair|generation.*error|bits.*invalid/i,
|
|
1905
|
+
explain: (error) => `
|
|
1906
|
+
RSA key pair generation failed.
|
|
1907
|
+
|
|
1908
|
+
Common causes:
|
|
1909
|
+
- Invalid bit size (too small)
|
|
1910
|
+
- System resource unavailable
|
|
1911
|
+
- Invalid options
|
|
1912
|
+
|
|
1913
|
+
Solution:
|
|
1914
|
+
1. Use supported key sizes: 2048, 4096
|
|
1915
|
+
2. Increase timeout for generation
|
|
1916
|
+
3. Check system has enough entropy
|
|
1917
|
+
4. Use async generation: generateKeyPair()
|
|
1918
|
+
5. Verify options object format
|
|
1919
|
+
`.trim()
|
|
1920
|
+
},
|
|
1921
|
+
|
|
1922
|
+
// HTTP2 Errors
|
|
1923
|
+
{
|
|
1924
|
+
name: "HTTP2_ERROR",
|
|
1925
|
+
match: /HTTP\/2|http2|ERR_HTTP2.*|h2 error/i,
|
|
1926
|
+
explain: (error) => `
|
|
1927
|
+
HTTP/2 protocol error.
|
|
1928
|
+
|
|
1929
|
+
Common causes:
|
|
1930
|
+
- HTTP/2 not fully supported
|
|
1931
|
+
- Stream issues
|
|
1932
|
+
- Connection error
|
|
1933
|
+
|
|
1934
|
+
Solution:
|
|
1935
|
+
1. Ensure Node.js version supports HTTP/2
|
|
1936
|
+
2. Check HTTP/2 enabled
|
|
1937
|
+
3. Handle stream errors: stream.on('error')
|
|
1938
|
+
4. Verify TLS certificate for HTTP/2
|
|
1939
|
+
5. Check server configuration
|
|
1940
|
+
`.trim()
|
|
1941
|
+
},
|
|
1942
|
+
|
|
1943
|
+
// DNS Errors
|
|
1944
|
+
{
|
|
1945
|
+
name: "DNS_LOOKUP_ERROR",
|
|
1946
|
+
match: /DNS|ENOTFOUND|getaddrinfo|ENETUNREACH|EHOSTUNREACH/i,
|
|
1947
|
+
explain: (error) => `
|
|
1948
|
+
DNS lookup failed - cannot resolve hostname.
|
|
1949
|
+
|
|
1950
|
+
Common causes:
|
|
1951
|
+
- Hostname doesn't exist
|
|
1952
|
+
- Network unreachable
|
|
1953
|
+
- DNS server unavailable
|
|
1954
|
+
- Wrong hostname
|
|
1955
|
+
|
|
1956
|
+
Solution:
|
|
1957
|
+
1. Check hostname spelling
|
|
1958
|
+
2. Verify DNS is working: nslookup
|
|
1959
|
+
3. Add error handling: dns.lookup(...)
|
|
1960
|
+
4. Use fallback DNS: 8.8.8.8
|
|
1961
|
+
5. Check network connectivity
|
|
1962
|
+
`.trim()
|
|
1963
|
+
},
|
|
1964
|
+
|
|
1965
|
+
// Child Process Errors
|
|
1966
|
+
{
|
|
1967
|
+
name: "CHILD_PROCESS_TIMEOUT",
|
|
1968
|
+
match: /child.*timeout|spawn.*error|exec.*timeout|timeout.*process/i,
|
|
1969
|
+
explain: (error) => `
|
|
1970
|
+
Child process operation timed out.
|
|
1971
|
+
|
|
1972
|
+
Common causes:
|
|
1973
|
+
- Process taking too long
|
|
1974
|
+
- Timeout value too short
|
|
1975
|
+
- Process hanging/deadlock
|
|
1976
|
+
|
|
1977
|
+
Solution:
|
|
1978
|
+
1. Increase timeout: { timeout: 30000 }
|
|
1979
|
+
2. Implement timeout: setTimeout(..., timeout)
|
|
1980
|
+
3. Kill after timeout: child.kill('SIGTERM')
|
|
1981
|
+
4. Debug process: check what it's doing
|
|
1982
|
+
5. Use '--timeout' flag if needed
|
|
1983
|
+
`.trim()
|
|
1984
|
+
},
|
|
1985
|
+
|
|
1986
|
+
// Array/Object Errors
|
|
1987
|
+
{
|
|
1988
|
+
name: "SPREAD_OPERATOR_ERROR",
|
|
1989
|
+
match: /spread|\.\.\.|\.\.\.|spread.*iterable|not iterable/i,
|
|
1990
|
+
explain: (error) => `
|
|
1991
|
+
Spread operator error - trying to spread non-iterable.
|
|
1992
|
+
|
|
1993
|
+
Common causes:
|
|
1994
|
+
- Spreading null/undefined
|
|
1995
|
+
- Spreading non-iterable object
|
|
1996
|
+
- Using spread on wrong type
|
|
1997
|
+
|
|
1998
|
+
Solution:
|
|
1999
|
+
1. Check value is iterable before spread
|
|
2000
|
+
2. Convert to array: Array.from(obj)
|
|
2001
|
+
3. Use optional: ...obj || []
|
|
2002
|
+
4. Verify object is iterable
|
|
2003
|
+
5. Use for-of if not spreadable
|
|
2004
|
+
`.trim()
|
|
2005
|
+
},
|
|
2006
|
+
|
|
2007
|
+
{
|
|
2008
|
+
name: "DESTRUCTURING_ERROR",
|
|
2009
|
+
match: /destructuring|destructur.*error|cannot destructure|destructure.*null/i,
|
|
2010
|
+
explain: (error) => `
|
|
2011
|
+
Object/array destructuring failed.
|
|
2012
|
+
|
|
2013
|
+
Common causes:
|
|
2014
|
+
- Destructuring null/undefined
|
|
2015
|
+
- Property doesn't exist
|
|
2016
|
+
- Wrong destructuring syntax
|
|
2017
|
+
|
|
2018
|
+
Solution:
|
|
2019
|
+
1. Add null checks: const { prop } = obj || {}
|
|
2020
|
+
2. Use default values: const { prop = default } = obj
|
|
2021
|
+
3. Verify property exists
|
|
2022
|
+
4. Check destructuring syntax
|
|
2023
|
+
5. Use optional chaining: obj?.prop
|
|
2024
|
+
`.trim()
|
|
2025
|
+
},
|
|
2026
|
+
|
|
2027
|
+
// WeakMap/WeakSet Errors
|
|
2028
|
+
{
|
|
2029
|
+
name: "WEAKMAP_ERROR",
|
|
2030
|
+
match: /WeakMap|WeakSet|weak.*map|weak.*set|Invalid.*value/i,
|
|
2031
|
+
explain: (error) => `
|
|
2032
|
+
WeakMap or WeakSet operation error.
|
|
2033
|
+
|
|
2034
|
+
Common causes:
|
|
2035
|
+
- Using non-object as key in WeakMap
|
|
2036
|
+
- Using primitives instead of objects
|
|
2037
|
+
- Incorrect WeakMap/WeakSet usage
|
|
2038
|
+
|
|
2039
|
+
Solution:
|
|
2040
|
+
1. Only use objects as WeakMap keys
|
|
2041
|
+
2. Don't use primitives: use Map for those
|
|
2042
|
+
3. Check value type before adding
|
|
2043
|
+
4. Use Map for primitives: new Map()
|
|
2044
|
+
5. WeakMap keys must be objects
|
|
2045
|
+
`.trim()
|
|
2046
|
+
},
|
|
2047
|
+
|
|
2048
|
+
// Proxy Errors
|
|
2049
|
+
{
|
|
2050
|
+
name: "PROXY_ERROR",
|
|
2051
|
+
match: /Proxy|trap.*invalid|proxy.*invalid|invariant violation/i,
|
|
2052
|
+
explain: (error) => `
|
|
2053
|
+
Proxy trap or Proxy invariant validation failed.
|
|
2054
|
+
|
|
2055
|
+
Common causes:
|
|
2056
|
+
- Trap returning invalid value
|
|
2057
|
+
- Trap not respecting invariants
|
|
2058
|
+
- Proxy configuration error
|
|
2059
|
+
|
|
2060
|
+
Solution:
|
|
2061
|
+
1. Check trap returns correct type
|
|
2062
|
+
2. Respect proxy invariants
|
|
2063
|
+
3. Return from get trap: return value
|
|
2064
|
+
4. Validate trap implementation
|
|
2065
|
+
5. Use Proxy carefully - test thoroughly
|
|
2066
|
+
`.trim()
|
|
2067
|
+
},
|
|
2068
|
+
|
|
2069
|
+
// Generator Errors
|
|
2070
|
+
{
|
|
2071
|
+
name: "GENERATOR_ERROR",
|
|
2072
|
+
match: /generator|function\*|yield|next\(\)|generator.*ended/i,
|
|
2073
|
+
explain: (error) => `
|
|
2074
|
+
Error in generator function or generator iteration.
|
|
2075
|
+
|
|
2076
|
+
Common causes:
|
|
2077
|
+
- Calling next() after done
|
|
2078
|
+
- Invalid yield statement
|
|
2079
|
+
- Not properly initializing generator
|
|
2080
|
+
|
|
2081
|
+
Solution:
|
|
2082
|
+
1. Check { done } flag before using value
|
|
2083
|
+
2. Use for-of for generators: for (const val of gen)
|
|
2084
|
+
3. Properly create generator: const gen = genFunc()
|
|
2085
|
+
4. Handle StopIteration properly
|
|
2086
|
+
5. Verify generator function syntax: function*
|
|
2087
|
+
`.trim()
|
|
2088
|
+
},
|
|
2089
|
+
|
|
2090
|
+
// JSON Schema Errors
|
|
2091
|
+
{
|
|
2092
|
+
name: "JSON_SCHEMA_VALIDATION_ERROR",
|
|
2093
|
+
match: /schema|validation.*failed|schema.*error|ajv|not valid/i,
|
|
2094
|
+
explain: (error) => `
|
|
2095
|
+
JSON schema validation failed.
|
|
2096
|
+
|
|
2097
|
+
Common causes:
|
|
2098
|
+
- Data doesn't match schema
|
|
2099
|
+
- Required field missing
|
|
2100
|
+
- Type mismatch with schema
|
|
2101
|
+
- Pattern validation failed
|
|
2102
|
+
|
|
2103
|
+
Solution:
|
|
2104
|
+
1. Check error.dataPath for which property
|
|
2105
|
+
2. Verify all required fields present
|
|
2106
|
+
3. Check data types match schema
|
|
2107
|
+
4. Review schema definition
|
|
2108
|
+
5. Use schema validator: ajv, joi
|
|
2109
|
+
`.trim()
|
|
2110
|
+
},
|
|
2111
|
+
|
|
2112
|
+
// Certificate Chain Errors
|
|
2113
|
+
{
|
|
2114
|
+
name: "CERTIFICATE_CHAIN_ERROR",
|
|
2115
|
+
match: /certificate.*chain|unable to verify.*chain|depth zero|cert.*chain/i,
|
|
2116
|
+
explain: (error) => `
|
|
2117
|
+
SSL certificate chain validation failed.
|
|
2118
|
+
|
|
2119
|
+
Common causes:
|
|
2120
|
+
- Intermediate cert missing
|
|
2121
|
+
- Self-signed certificate
|
|
2122
|
+
- Cert expired
|
|
2123
|
+
- Wrong chain order
|
|
2124
|
+
|
|
2125
|
+
Solution:
|
|
2126
|
+
1. Ensure full chain is provided
|
|
2127
|
+
2. For self-signed: NODE_TLS_REJECT_UNAUTHORIZED=0 (dev only)
|
|
2128
|
+
3. Update cert to valid one
|
|
2129
|
+
4. Check cert isn't expired: openssl x509 -in cert.pem -text
|
|
2130
|
+
5. Proper order: leaf, intermediate, root
|
|
2131
|
+
`.trim()
|
|
2132
|
+
},
|
|
2133
|
+
|
|
2134
|
+
// International Domain Names
|
|
2135
|
+
{
|
|
2136
|
+
name: "IDNA_ERROR",
|
|
2137
|
+
match: /IDNA|punycode|domain.*format|internationalized.*domain/i,
|
|
2138
|
+
explain: (error) => `
|
|
2139
|
+
International domain name (IDN) encoding error.
|
|
2140
|
+
|
|
2141
|
+
Common causes:
|
|
2142
|
+
- Invalid Unicode domain name
|
|
2143
|
+
- Punycode conversion failed
|
|
2144
|
+
- Invalid domain format
|
|
2145
|
+
|
|
2146
|
+
Solution:
|
|
2147
|
+
1. Use proper IDN format
|
|
2148
|
+
2. Use punycode library: install 'punycode'
|
|
2149
|
+
3. Encode domain: require('punycode').toASCII(domain)
|
|
2150
|
+
4. Verify domain format
|
|
2151
|
+
5. Check URL encoding
|
|
2152
|
+
`.trim()
|
|
2153
|
+
},
|
|
2154
|
+
|
|
2155
|
+
// Path Traversal Errors
|
|
2156
|
+
{
|
|
2157
|
+
name: "PATH_TRAVERSAL_ATTEMPT",
|
|
2158
|
+
match: /path.*traversal|\.\.\/|directory traversal|path.*escape|sanitize/i,
|
|
2159
|
+
explain: (error) => `
|
|
2160
|
+
Path traversal attack or suspicious path detected.
|
|
2161
|
+
|
|
2162
|
+
Common causes:
|
|
2163
|
+
- Using unsanitized user input in paths
|
|
2164
|
+
- Not validating file path
|
|
2165
|
+
- Allowing ../
|
|
2166
|
+
|
|
2167
|
+
Solution:
|
|
2168
|
+
1. Validate paths: path.resolve() and check inside base
|
|
2169
|
+
2. Use path.join() and validate result
|
|
2170
|
+
3. Never concatenate user input directly
|
|
2171
|
+
4. Whitelist allowed paths
|
|
2172
|
+
5. Use path.normalize() and validate
|
|
2173
|
+
`.trim()
|
|
2174
|
+
},
|
|
2175
|
+
|
|
2176
|
+
// Date/Time Errors
|
|
2177
|
+
{
|
|
2178
|
+
name: "DATE_TIMEZONE_ERROR",
|
|
2179
|
+
match: /timezone|time.?zone|offset.*invalid|IANA.*timezone/i,
|
|
2180
|
+
explain: (error) => `
|
|
2181
|
+
Date or timezone conversion error.
|
|
2182
|
+
|
|
2183
|
+
Common causes:
|
|
2184
|
+
- Invalid timezone ID
|
|
2185
|
+
- Timezone not recognized
|
|
2186
|
+
- Daylight savings issue
|
|
2187
|
+
|
|
2188
|
+
Solution:
|
|
2189
|
+
1. Use IANA timezone names: America/New_York
|
|
2190
|
+
2. Use moment-timezone or date-fns
|
|
2191
|
+
3. Avoid manual offset calculations
|
|
2192
|
+
4. Verify timezone ID exists
|
|
2193
|
+
5. Account for daylight savings
|
|
2194
|
+
`.trim()
|
|
2195
|
+
},
|
|
2196
|
+
|
|
2197
|
+
// Atomicity/Transaction Errors
|
|
2198
|
+
{
|
|
2199
|
+
name: "TRANSACTION_ERROR",
|
|
2200
|
+
match: /transaction|commit.*failed|rollback|ACID|isolation/i,
|
|
2201
|
+
explain: (error) => `
|
|
2202
|
+
Database transaction failed or rolled back.
|
|
2203
|
+
|
|
2204
|
+
Common causes:
|
|
2205
|
+
- Constraint violation
|
|
2206
|
+
- Deadlock detected
|
|
2207
|
+
- Transaction timeout
|
|
2208
|
+
- Isolation level conflict
|
|
2209
|
+
|
|
2210
|
+
Solution:
|
|
2211
|
+
1. Check constraint violations
|
|
2212
|
+
2. Implement retry logic for deadlocks
|
|
2213
|
+
3. Increase transaction timeout if needed
|
|
2214
|
+
4. Review isolation levels
|
|
2215
|
+
5. Use connection pool for concurrency
|
|
2216
|
+
`.trim()
|
|
2217
|
+
},
|
|
2218
|
+
|
|
2219
|
+
// Compression Errors
|
|
2220
|
+
{
|
|
2221
|
+
name: "COMPRESSION_ERROR",
|
|
2222
|
+
match: /gzip|deflate|brotli|compress.*error|decompress.*error|zlib/i,
|
|
2223
|
+
explain: (error) => `
|
|
2224
|
+
Compression or decompression failed.
|
|
2225
|
+
|
|
2226
|
+
Common causes:
|
|
2227
|
+
- Corrupted compressed data
|
|
2228
|
+
- Wrong decompression codec
|
|
2229
|
+
- Incomplete data
|
|
2230
|
+
- Memory error
|
|
2231
|
+
|
|
2232
|
+
Solution:
|
|
2233
|
+
1. Check data isn't corrupted
|
|
2234
|
+
2. Use correct decompression: zlib.gunzip()
|
|
2235
|
+
3. Handle incomplete data
|
|
2236
|
+
4. Catch errors: stream.on('error')
|
|
2237
|
+
5. Use compression headers correctly
|
|
2238
|
+
`.trim()
|
|
2239
|
+
},
|
|
2240
|
+
|
|
2241
|
+
// OpenSSL Errors
|
|
2242
|
+
{
|
|
2243
|
+
name: "OPENSSL_ERROR",
|
|
2244
|
+
match: /OpenSSL|libssl|error in.*library|engine|OPENSSLDIR/i,
|
|
2245
|
+
explain: (error) => `
|
|
2246
|
+
OpenSSL library error - usually cryptographic operation failed.
|
|
2247
|
+
|
|
2248
|
+
Common causes:
|
|
2249
|
+
- OpenSSL not installed
|
|
2250
|
+
- Version mismatch
|
|
2251
|
+
- Cryptographic operation error
|
|
2252
|
+
|
|
2253
|
+
Solution:
|
|
2254
|
+
1. Verify OpenSSL installed: openssl version
|
|
2255
|
+
2. Check Node version uses compatible OpenSSL
|
|
2256
|
+
3. Rebuild Node if needed
|
|
2257
|
+
4. Check OpenSSL permissions
|
|
2258
|
+
5. Update OpenSSL to latest
|
|
2259
|
+
`.trim()
|
|
2260
|
+
},
|
|
2261
|
+
|
|
2262
|
+
// Memory Safety Errors
|
|
2263
|
+
{
|
|
2264
|
+
name: "MEMORY_ACCESS_VIOLATION",
|
|
2265
|
+
match: /segmentation fault|SIGSEGV|access violation|crash/i,
|
|
2266
|
+
explain: (error) => `
|
|
2267
|
+
Segmentation fault - memory access violation.
|
|
2268
|
+
|
|
2269
|
+
Common causes:
|
|
2270
|
+
- Native module bug
|
|
2271
|
+
- Buffer overflow
|
|
2272
|
+
- Use-after-free
|
|
2273
|
+
- Out of bounds access
|
|
2274
|
+
|
|
2275
|
+
Solution:
|
|
2276
|
+
1. Update native modules
|
|
2277
|
+
2. Check for vulnerabilities in modules
|
|
2278
|
+
3. Use bounds checking
|
|
2279
|
+
4. Avoid direct memory access
|
|
2280
|
+
5. Use valgrind for debugging (advanced)
|
|
2281
|
+
`.trim()
|
|
2282
|
+
},
|
|
2283
|
+
|
|
2284
|
+
// WASM Errors
|
|
2285
|
+
{
|
|
2286
|
+
name: "WASM_ERROR",
|
|
2287
|
+
match: /WASM|WebAssembly|wasm.*error|compiled code|table.*element/i,
|
|
2288
|
+
explain: (error) => `
|
|
2289
|
+
WebAssembly execution error.
|
|
2290
|
+
|
|
2291
|
+
Common causes:
|
|
2292
|
+
- Invalid WASM module
|
|
2293
|
+
- Function not found in WASM
|
|
2294
|
+
- Memory access error
|
|
2295
|
+
- Type mismatch
|
|
2296
|
+
|
|
2297
|
+
Solution:
|
|
2298
|
+
1. Validate WASM module format
|
|
2299
|
+
2. Check exported functions exist
|
|
2300
|
+
3. Verify memory page size
|
|
2301
|
+
4. Use WASM debugging tools
|
|
2302
|
+
5. Check WASM version compatibility
|
|
2303
|
+
`.trim()
|
|
2304
|
+
},
|
|
2305
|
+
|
|
2306
|
+
// V8 Snapshot Errors
|
|
2307
|
+
{
|
|
2308
|
+
name: "SNAPSHOT_ERROR",
|
|
2309
|
+
match: /snapshot|v8.*snapshot|serialize|binary.*snapshot/i,
|
|
2310
|
+
explain: (error) => `
|
|
2311
|
+
V8 snapshot creation or loading failed.
|
|
2312
|
+
|
|
2313
|
+
Common causes:
|
|
2314
|
+
- Snapshot incompatible with Node version
|
|
2315
|
+
- Snapshot corrupted
|
|
2316
|
+
- Invalid snapshot format
|
|
2317
|
+
|
|
2318
|
+
Solution:
|
|
2319
|
+
1. Regenerate snapshot for current Node version
|
|
2320
|
+
2. Ensure snapshot is valid binary
|
|
2321
|
+
3. Check snapshot compatibility
|
|
2322
|
+
4. Use snapshot feature correctly
|
|
2323
|
+
5. Clean snapshots and rebuild
|
|
2324
|
+
`.trim()
|
|
2325
|
+
},
|
|
2326
|
+
|
|
2327
|
+
// Intl Errors
|
|
2328
|
+
{
|
|
2329
|
+
name: "INTL_ERROR",
|
|
2330
|
+
match: /Intl|internationalization|locale|collation|intl.*error/i,
|
|
2331
|
+
explain: (error) => `
|
|
2332
|
+
Internationalization (Intl) API error.
|
|
2333
|
+
|
|
2334
|
+
Common causes:
|
|
2335
|
+
- Invalid locale code
|
|
2336
|
+
- Feature not supported
|
|
2337
|
+
- Unsupported operation
|
|
2338
|
+
|
|
2339
|
+
Solution:
|
|
2340
|
+
1. Use valid locale: en-US, fr-FR
|
|
2341
|
+
2. Check platform Intl support
|
|
2342
|
+
3. Use Intl.DateTimeFormat, Intl.NumberFormat
|
|
2343
|
+
4. Handle unsupported locales
|
|
2344
|
+
5. Fallback to default locale
|
|
2345
|
+
`.trim()
|
|
2346
|
+
},
|
|
2347
|
+
|
|
2348
|
+
// Express.js Specific Errors
|
|
2349
|
+
{
|
|
2350
|
+
name: "EXPRESS_INVALID_STATUS_CODE",
|
|
2351
|
+
match: /invalid status code|status.*not.*number|ERR_HTTP_INVALID_STATUS_CODE/i,
|
|
2352
|
+
explain: (error) => `
|
|
2353
|
+
Express status code is invalid - must be a number between 100-599.
|
|
2354
|
+
|
|
2355
|
+
Common causes:
|
|
2356
|
+
- Non-numeric status code
|
|
2357
|
+
- Status code out of range
|
|
2358
|
+
- res.status() called with string
|
|
2359
|
+
|
|
2360
|
+
Solution:
|
|
2361
|
+
1. Use valid HTTP codes: 200, 404, 500, etc.
|
|
2362
|
+
2. Ensure status is number: res.status(200)
|
|
2363
|
+
3. Check valid range: 100-599
|
|
2364
|
+
4. Don't pass string: res.status('200') ❌ res.status(200) ✓
|
|
2365
|
+
`.trim()
|
|
2366
|
+
},
|
|
2367
|
+
|
|
2368
|
+
{
|
|
2369
|
+
name: "EXPRESS_RESPONSE_ALREADY_SENT",
|
|
2370
|
+
match: /response already.*sent|Cannot.*headers after sent|res\.send.*twice/i,
|
|
2371
|
+
explain: (error) => `
|
|
2372
|
+
Trying to send response twice or set headers after response started.
|
|
2373
|
+
|
|
2374
|
+
Common causes:
|
|
2375
|
+
- res.send() called multiple times
|
|
2376
|
+
- res.json() then res.send()
|
|
2377
|
+
- Setting headers after res.write()
|
|
2378
|
+
- Missing return statement
|
|
2379
|
+
|
|
2380
|
+
Solution:
|
|
2381
|
+
1. Use return: return res.send(data)
|
|
2382
|
+
2. Use if/else, not multiple sends
|
|
2383
|
+
3. Set headers before writing: res.set('X-Header', val)
|
|
2384
|
+
4. Structure: headers → write → end
|
|
2385
|
+
`.trim()
|
|
2386
|
+
},
|
|
2387
|
+
|
|
2388
|
+
{
|
|
2389
|
+
name: "EXPRESS_ROUTE_NOT_FOUND",
|
|
2390
|
+
match: /Cannot GET|Cannot POST|Cannot PUT|Cannot DELETE|Cannot PATCH|404.*not found/i,
|
|
2391
|
+
explain: (error) => `
|
|
2392
|
+
Express route handler not found - no matching route defined.
|
|
2393
|
+
|
|
2394
|
+
Common causes:
|
|
2395
|
+
- Route path doesn't exist
|
|
2396
|
+
- Wrong HTTP method (GET vs POST)
|
|
2397
|
+
- Route path typo
|
|
2398
|
+
- Route registered after error middleware
|
|
2399
|
+
|
|
2400
|
+
Solution:
|
|
2401
|
+
1. Verify route exists: app.get('/path', ...)
|
|
2402
|
+
2. Check HTTP method matches request
|
|
2403
|
+
3. Use app.all('*') for catch-all 404
|
|
2404
|
+
4. Place 404 handler last in middleware chain
|
|
2405
|
+
5. Check route path spelling
|
|
2406
|
+
`.trim()
|
|
2407
|
+
},
|
|
2408
|
+
|
|
2409
|
+
{
|
|
2410
|
+
name: "EXPRESS_MIDDLEWARE_NOT_CALLED_NEXT",
|
|
2411
|
+
match: /middleware.*next|hanging request|request.*timeout.*middleware|next.*not.*called/i,
|
|
2412
|
+
explain: (error) => `
|
|
2413
|
+
Middleware didn't call next() and didn't send response.
|
|
2414
|
+
|
|
2415
|
+
Common causes:
|
|
2416
|
+
- Forgot to call next() in middleware
|
|
2417
|
+
- Forgot to send response (res.send)
|
|
2418
|
+
- Middleware code throwing error
|
|
2419
|
+
- Async middleware promise not awaited
|
|
2420
|
+
|
|
2421
|
+
Solution:
|
|
2422
|
+
1. Call next() to pass to next middleware
|
|
2423
|
+
2. OR send response: res.send() or res.json()
|
|
2424
|
+
3. Async middleware: make handler async and use try/catch
|
|
2425
|
+
4. Use: app.use((req, res, next) => { next() })
|
|
2426
|
+
`.trim()
|
|
2427
|
+
},
|
|
2428
|
+
|
|
2429
|
+
{
|
|
2430
|
+
name: "EXPRESS_INVALID_MIDDLEWARE",
|
|
2431
|
+
match: /middleware.*not.*function|middleware.*must.*function|app\.use.*function/i,
|
|
2432
|
+
explain: (error) => `
|
|
2433
|
+
Middleware is not a function - must be a valid function.
|
|
2434
|
+
|
|
2435
|
+
Common causes:
|
|
2436
|
+
- Passing non-function to app.use()
|
|
2437
|
+
- Middleware incorrectly defined
|
|
2438
|
+
- Import error returning undefined
|
|
2439
|
+
|
|
2440
|
+
Solution:
|
|
2441
|
+
1. Ensure middleware is function: app.use((req, res, next) => {})
|
|
2442
|
+
2. Check import: const middleware = require('./middleware')
|
|
2443
|
+
3. Verify file exports function
|
|
2444
|
+
4. Check middleware definition syntax
|
|
2445
|
+
`.trim()
|
|
2446
|
+
},
|
|
2447
|
+
|
|
2448
|
+
{
|
|
2449
|
+
name: "EXPRESS_BODY_PARSER_ERROR",
|
|
2450
|
+
match: /body.?parser|payload.*too.*large|request.*entity.*too.*large|413/i,
|
|
2451
|
+
explain: (error) => `
|
|
2452
|
+
Request body exceeds size limit set in body parser.
|
|
2453
|
+
|
|
2454
|
+
Common causes:
|
|
2455
|
+
- Request body too large
|
|
2456
|
+
- Body parser limit too small
|
|
2457
|
+
- Sending large file without multipart
|
|
2458
|
+
|
|
2459
|
+
Solution:
|
|
2460
|
+
1. Increase limit: express.json({ limit: '50mb' })
|
|
2461
|
+
2. Use 'large' for big bodies: { limit: '100mb' }
|
|
2462
|
+
3. Use multipart for files: multer middleware
|
|
2463
|
+
4. Configure before routes:
|
|
2464
|
+
app.use(express.json({ limit: '50mb' }))
|
|
2465
|
+
`.trim()
|
|
2466
|
+
},
|
|
2467
|
+
|
|
2468
|
+
{
|
|
2469
|
+
name: "EXPRESS_INVALID_JSON",
|
|
2470
|
+
match: /invalid json|malformed.*json|body.*parser.*json|SyntaxError.*JSON/i,
|
|
2471
|
+
explain: (error) => `
|
|
2472
|
+
Request body contains invalid JSON.
|
|
2473
|
+
|
|
2474
|
+
Common causes:
|
|
2475
|
+
- Client sends malformed JSON
|
|
2476
|
+
- Missing quotes on strings
|
|
2477
|
+
- Trailing comma
|
|
2478
|
+
- Invalid escape sequences
|
|
2479
|
+
|
|
2480
|
+
Solution:
|
|
2481
|
+
1. Validate JSON on client before sending
|
|
2482
|
+
2. Add error handler: app.use((err, req, res, next) => {})
|
|
2483
|
+
3. Log invalid JSON for debugging
|
|
2484
|
+
4. Return 400 status for invalid JSON
|
|
2485
|
+
5. Check Content-Type header is application/json
|
|
2486
|
+
`.trim()
|
|
2487
|
+
},
|
|
2488
|
+
|
|
2489
|
+
{
|
|
2490
|
+
name: "EXPRESS_CORS_DISABLED",
|
|
2491
|
+
match: /CORS.*not.*enabled|no access.*control.*allow.*origin|can't access|cross.?origin/i,
|
|
2492
|
+
explain: (error) => `
|
|
2493
|
+
CORS headers not sent - cross-origin request blocked.
|
|
2494
|
+
|
|
2495
|
+
Common causes:
|
|
2496
|
+
- CORS not enabled
|
|
2497
|
+
- Access-Control-Allow-Origin not set
|
|
2498
|
+
- Requesting from different origin
|
|
2499
|
+
- Browser enforces CORS policy
|
|
2500
|
+
|
|
2501
|
+
Solution:
|
|
2502
|
+
1. Install cors: npm install cors
|
|
2503
|
+
2. Use middleware: const cors = require('cors'); app.use(cors())
|
|
2504
|
+
3. Or configure: app.use(cors({ origin: 'http://localhost:3000' }))
|
|
2505
|
+
4. For credentials: credentials: true in CORS config
|
|
2506
|
+
5. Allow specific methods: methods: ['GET', 'POST']
|
|
2507
|
+
`.trim()
|
|
2508
|
+
},
|
|
2509
|
+
|
|
2510
|
+
{
|
|
2511
|
+
name: "EXPRESS_TRUST_PROXY_ERROR",
|
|
2512
|
+
match: /trust proxy|X-Forwarded|req\.ip|X-Real-IP|behind.*proxy/i,
|
|
2513
|
+
explain: (error) => `
|
|
2514
|
+
Trust proxy not configured properly - IP address wrong or headers not trusted.
|
|
2515
|
+
|
|
2516
|
+
Common causes:
|
|
2517
|
+
- Behind reverse proxy but trust proxy not set
|
|
2518
|
+
- Wrong remote address gotten
|
|
2519
|
+
- Can't access real client IP
|
|
2520
|
+
|
|
2521
|
+
Solution:
|
|
2522
|
+
1. Set trust proxy if behind proxy: app.set('trust proxy', 1)
|
|
2523
|
+
2. Trust specific proxy: app.set('trust proxy', 'loopback')
|
|
2524
|
+
3. Get correct IP: req.ip (not req.connection.remoteAddress)
|
|
2525
|
+
4. Check X-Forwarded-For headers
|
|
2526
|
+
5. For AWS/Heroku: app.set('trust proxy', true)
|
|
2527
|
+
`.trim()
|
|
2528
|
+
},
|
|
2529
|
+
|
|
2530
|
+
{
|
|
2531
|
+
name: "EXPRESS_RENDER_ERROR",
|
|
2532
|
+
match: /render.*not.*function|res\.render|view.*not.*found|template.*error/i,
|
|
2533
|
+
explain: (error) => `
|
|
2534
|
+
View rendering failed - template engine issue.
|
|
2535
|
+
|
|
2536
|
+
Common causes:
|
|
2537
|
+
- View engine not set: app.set('view engine')
|
|
2538
|
+
- Template file not found
|
|
2539
|
+
- Template syntax error
|
|
2540
|
+
- View directory wrong
|
|
2541
|
+
|
|
2542
|
+
Solution:
|
|
2543
|
+
1. Set view engine: app.set('view engine', 'ejs')
|
|
2544
|
+
2. Set views directory: app.set('views', './views')
|
|
2545
|
+
3. Ensure template file exists
|
|
2546
|
+
4. Check template syntax for errors
|
|
2547
|
+
5. Use: res.render('template', { data })
|
|
2548
|
+
`.trim()
|
|
2549
|
+
},
|
|
2550
|
+
|
|
2551
|
+
{
|
|
2552
|
+
name: "EXPRESS_INVALID_REDIRECT",
|
|
2553
|
+
match: /invalid redirect|res\.redirect.*not.*url|redirect.*malformed|location.*header/i,
|
|
2554
|
+
explain: (error) => `
|
|
2555
|
+
Invalid redirect URL provided to res.redirect().
|
|
2556
|
+
|
|
2557
|
+
Common causes:
|
|
2558
|
+
- URL not valid
|
|
2559
|
+
- Redirect URL has spaces
|
|
2560
|
+
- Invalid characters in URL
|
|
2561
|
+
|
|
2562
|
+
Solution:
|
|
2563
|
+
1. Use valid URL: res.redirect('/path')
|
|
2564
|
+
2. Use full URL: res.redirect('http://example.com')
|
|
2565
|
+
3. Encode URL: encodeURI() if needed
|
|
2566
|
+
4. Validate URL format before redirect
|
|
2567
|
+
5. Use 301 for permanent: res.redirect(301, '/path')
|
|
2568
|
+
`.trim()
|
|
2569
|
+
},
|
|
2570
|
+
|
|
2571
|
+
{
|
|
2572
|
+
name: "EXPRESS_CONTENT_TYPE_MISMATCH",
|
|
2573
|
+
match: /content.?type|charset|media.*type|accepts/i,
|
|
2574
|
+
explain: (error) => `
|
|
2575
|
+
Content-Type mismatch or incompatible accept header.
|
|
2576
|
+
|
|
2577
|
+
Common causes:
|
|
2578
|
+
- Content-Type header wrong
|
|
2579
|
+
- Charset encoding mismatch
|
|
2580
|
+
- Client doesn't accept response format
|
|
2581
|
+
- res.type() set incorrectly
|
|
2582
|
+
|
|
2583
|
+
Solution:
|
|
2584
|
+
1. Set content-type: res.type('application/json')
|
|
2585
|
+
2. Use res.json() for JSON (sets correct type)
|
|
2586
|
+
3. Set charset: res.type('text/html; charset=utf-8')
|
|
2587
|
+
4. Check client accepts format
|
|
2588
|
+
5. Use res.set('Content-Type', 'application/json')
|
|
2589
|
+
`.trim()
|
|
2590
|
+
},
|
|
2591
|
+
|
|
2592
|
+
{
|
|
2593
|
+
name: "EXPRESS_COOKIE_ERROR",
|
|
2594
|
+
match: /cookie|res\.cookie|Set-Cookie|cookie.*parser|signed.*cookie/i,
|
|
2595
|
+
explain: (error) => `
|
|
2596
|
+
Cookie operation failed - parsing or setting cookie error.
|
|
2597
|
+
|
|
2598
|
+
Common causes:
|
|
2599
|
+
- Cookie size too large
|
|
2600
|
+
- Invalid cookie name/value
|
|
2601
|
+
- Cookie middleware not loaded
|
|
2602
|
+
- Signed cookie key not set
|
|
2603
|
+
|
|
2604
|
+
Solution:
|
|
2605
|
+
1. Use cookie-parser middleware: app.use(cookieParser('secret'))
|
|
2606
|
+
2. Set cookie: res.cookie('name', 'value')
|
|
2607
|
+
3. Get cookie: req.cookies.name or req.signedCookies.name
|
|
2608
|
+
4. Keep cookie size small
|
|
2609
|
+
5. Use secure/httpOnly for security: { secure: true, httpOnly: true }
|
|
2610
|
+
`.trim()
|
|
2611
|
+
},
|
|
2612
|
+
|
|
2613
|
+
{
|
|
2614
|
+
name: "EXPRESS_SESSION_ERROR",
|
|
2615
|
+
match: /session|req\.session|session.*middleware|express.?session/i,
|
|
2616
|
+
explain: (error) => `
|
|
2617
|
+
Session middleware error - configuration or storage issue.
|
|
2618
|
+
|
|
2619
|
+
Common causes:
|
|
2620
|
+
- express-session not installed
|
|
2621
|
+
- Session store not configured
|
|
2622
|
+
- Session middleware not loaded
|
|
2623
|
+
- Session data corrupted
|
|
2624
|
+
|
|
2625
|
+
Solution:
|
|
2626
|
+
1. Install: npm install express-session
|
|
2627
|
+
2. Configure store (Redis, MongoDB): new RedisStore()
|
|
2628
|
+
3. Use middleware: app.use(session({ secret: 'key', store: ... }))
|
|
2629
|
+
4. Load before routes
|
|
2630
|
+
5. Access: req.session.userId = value
|
|
2631
|
+
`.trim()
|
|
2632
|
+
},
|
|
2633
|
+
|
|
2634
|
+
{
|
|
2635
|
+
name: "EXPRESS_AUTH_HEADER_ERROR",
|
|
2636
|
+
match: /authorization|auth.*header|Bearer.*token|unauthorized.*header/i,
|
|
2637
|
+
explain: (error) => `
|
|
2638
|
+
Authorization header missing or malformed.
|
|
2639
|
+
|
|
2640
|
+
Common causes:
|
|
2641
|
+
- No Authorization header sent
|
|
2642
|
+
- Wrong format: should be "Bearer <token>"
|
|
2643
|
+
- Token not included
|
|
2644
|
+
- Bearer prefix missing
|
|
2645
|
+
|
|
2646
|
+
Solution:
|
|
2647
|
+
1. Client sends: Authorization: Bearer <token>
|
|
2648
|
+
2. Parse in middleware: const token = req.headers.authorization?.split(' ')[1]
|
|
2649
|
+
3. Verify token exists before using
|
|
2650
|
+
4. Handle missing auth: return res.status(401).send('Unauthorized')
|
|
2651
|
+
5. Use passport or jwt middleware for auth
|
|
2652
|
+
`.trim()
|
|
2653
|
+
},
|
|
2654
|
+
|
|
2655
|
+
{
|
|
2656
|
+
name: "EXPRESS_MULTER_ERROR",
|
|
2657
|
+
match: /multer|file.*upload|multipart.*form|upload.*error|field.*too.*large/i,
|
|
2658
|
+
explain: (error) => `
|
|
2659
|
+
File upload error - multer middleware issue.
|
|
2660
|
+
|
|
2661
|
+
Common causes:
|
|
2662
|
+
- File size exceeds limit
|
|
2663
|
+
- Field count exceeds limit
|
|
2664
|
+
- Wrong field name
|
|
2665
|
+
- Multer not configured
|
|
2666
|
+
|
|
2667
|
+
Solution:
|
|
2668
|
+
1. Install: npm install multer
|
|
2669
|
+
2. Configure: const multer = require('multer'); const upload = multer({ dest: 'uploads/' })
|
|
2670
|
+
3. Use on route: app.post('/upload', upload.single('file'), ...)
|
|
2671
|
+
4. Access file: req.file
|
|
2672
|
+
5. Set limits: { fileSize: 1024 * 1024 * 10 } for 10MB
|
|
2673
|
+
`.trim()
|
|
2674
|
+
},
|
|
2675
|
+
|
|
2676
|
+
{
|
|
2677
|
+
name: "EXPRESS_RATE_LIMIT_EXCEEDED",
|
|
2678
|
+
match: /rate.*limit|too.*many.*request|429|throttle|limit.*exceeded/i,
|
|
2679
|
+
explain: (error) => `
|
|
2680
|
+
Rate limit exceeded - too many requests.
|
|
2681
|
+
|
|
2682
|
+
Common causes:
|
|
2683
|
+
- Rate limit middleware active
|
|
2684
|
+
- IP exceeded request quota
|
|
2685
|
+
- Time window limit reached
|
|
2686
|
+
|
|
2687
|
+
Solution:
|
|
2688
|
+
1. Install: npm install express-rate-limit
|
|
2689
|
+
2. Create limiter:
|
|
2690
|
+
const limiter = rateLimit({ windowMs: 15*60*1000, max: 100 })
|
|
2691
|
+
3. Use on routes: app.use(limiter)
|
|
2692
|
+
4. Implement backoff on client
|
|
2693
|
+
5. Different limits for different endpoints
|
|
2694
|
+
`.trim()
|
|
2695
|
+
},
|
|
2696
|
+
|
|
2697
|
+
{
|
|
2698
|
+
name: "EXPRESS_HELMET_ERROR",
|
|
2699
|
+
match: /helmet|security.*header|X-Frame-Options|CSP|content.*security/i,
|
|
2700
|
+
explain: (error) => `
|
|
2701
|
+
Helmet security middleware blocked request or header issue.
|
|
2702
|
+
|
|
2703
|
+
Common causes:
|
|
2704
|
+
- CSP (Content Security Policy) violated
|
|
2705
|
+
- Frame embedding not allowed
|
|
2706
|
+
- Security header misconfigured
|
|
2707
|
+
|
|
2708
|
+
Solution:
|
|
2709
|
+
1. Install: npm install helmet
|
|
2710
|
+
2. Use: app.use(helmet())
|
|
2711
|
+
3. Configure CSP: helmet.contentSecurityPolicy({ directives: { ... } })
|
|
2712
|
+
4. Allow specific sources in CSP
|
|
2713
|
+
5. Check browser console for CSP violations
|
|
2714
|
+
`.trim()
|
|
2715
|
+
},
|
|
2716
|
+
|
|
2717
|
+
{
|
|
2718
|
+
name: "EXPRESS_COMPRESSION_ENABLED_WRONG",
|
|
2719
|
+
match: /compression|compress|gzip|deflate|compression.*error/i,
|
|
2720
|
+
explain: (error) => `
|
|
2721
|
+
Compression middleware issue - response compression error.
|
|
2722
|
+
|
|
2723
|
+
Common causes:
|
|
2724
|
+
- Compression not working
|
|
2725
|
+
- Already compressed content
|
|
2726
|
+
- Unsupported encoding
|
|
2727
|
+
- Wrong middleware order
|
|
2728
|
+
|
|
2729
|
+
Solution:
|
|
2730
|
+
1. Install: npm install compression
|
|
2731
|
+
2. Use early: app.use(compression())
|
|
2732
|
+
3. Place before routes
|
|
2733
|
+
4. Check if response already compressed
|
|
2734
|
+
5. Set quality: compression({ level: 6 })
|
|
2735
|
+
`.trim()
|
|
2736
|
+
},
|
|
2737
|
+
|
|
2738
|
+
{
|
|
2739
|
+
name: "EXPRESS_MORGAN_LOG_ERROR",
|
|
2740
|
+
match: /morgan|logging.*error|morgan.*format|log.*format/i,
|
|
2741
|
+
explain: (error) => `
|
|
2742
|
+
Morgan logging middleware error or misconfiguration.
|
|
2743
|
+
|
|
2744
|
+
Common causes:
|
|
2745
|
+
- Morgan not installed
|
|
2746
|
+
- Invalid format string
|
|
2747
|
+
- Wrong middleware order
|
|
2748
|
+
- Stream error
|
|
2749
|
+
|
|
2750
|
+
Solution:
|
|
2751
|
+
1. Install: npm install morgan
|
|
2752
|
+
2. Use: app.use(morgan('combined'))
|
|
2753
|
+
3. Place early in middleware
|
|
2754
|
+
4. Use format: combined, common, short, tiny
|
|
2755
|
+
5. Custom: morgan(':method :url :status')
|
|
2756
|
+
`.trim()
|
|
2757
|
+
},
|
|
2758
|
+
|
|
2759
|
+
{
|
|
2760
|
+
name: "EXPRESS_VALIDATOR_ERROR",
|
|
2761
|
+
match: /express.?validator|validation.*failed|validationResult|check.*validation/i,
|
|
2762
|
+
explain: (error) => `
|
|
2763
|
+
express-validator validation error or misconfiguration.
|
|
2764
|
+
|
|
2765
|
+
Common causes:
|
|
2766
|
+
- Validators not run
|
|
2767
|
+
- Validation rules incorrect
|
|
2768
|
+
- validationResult not checked
|
|
2769
|
+
- Error not propagated
|
|
2770
|
+
|
|
2771
|
+
Solution:
|
|
2772
|
+
1. Install: npm install express-validator
|
|
2773
|
+
2. Import: const { body, validationResult } = require('express-validator')
|
|
2774
|
+
3. Add validators: body('email').isEmail()
|
|
2775
|
+
4. Check results: const errors = validationResult(req)
|
|
2776
|
+
5. Return errors: res.status(400).send(errors.array())
|
|
2777
|
+
`.trim()
|
|
2778
|
+
},
|
|
2779
|
+
|
|
2780
|
+
{
|
|
2781
|
+
name: "EXPRESS_PASSPORT_ERROR",
|
|
2782
|
+
match: /passport|authentication.*failed|user.*not.*found|auth.*error/i,
|
|
2783
|
+
explain: (error) => `
|
|
2784
|
+
Passport authentication middleware error.
|
|
2785
|
+
|
|
2786
|
+
Common causes:
|
|
2787
|
+
- Strategy not configured
|
|
2788
|
+
- User not found
|
|
2789
|
+
- Password incorrect
|
|
2790
|
+
- Session not set up
|
|
2791
|
+
|
|
2792
|
+
Solution:
|
|
2793
|
+
1. Install: npm install passport passport-local
|
|
2794
|
+
2. Configure strategy: passport.use(new LocalStrategy(...))
|
|
2795
|
+
3. Use middleware: app.use(passport.initialize())
|
|
2796
|
+
4. Serialize user: passport.serializeUser(...)
|
|
2797
|
+
5. Request authentication: req.login(user, callback)
|
|
2798
|
+
`.trim()
|
|
2799
|
+
},
|
|
2800
|
+
|
|
2801
|
+
{
|
|
2802
|
+
name: "EXPRESS_JSONP_ERROR",
|
|
2803
|
+
match: /JSONP|jsonp|callback|padding/i,
|
|
2804
|
+
explain: (error) => `
|
|
2805
|
+
JSONP response error or misconfiguration.
|
|
2806
|
+
|
|
2807
|
+
Common causes:
|
|
2808
|
+
- JSONP not enabled
|
|
2809
|
+
- Invalid callback parameter
|
|
2810
|
+
- Wrong response format
|
|
2811
|
+
|
|
2812
|
+
Solution:
|
|
2813
|
+
1. Enable: app.set('jsonp callback name', 'callback')
|
|
2814
|
+
2. Use res.jsonp(): res.jsonp({ data })
|
|
2815
|
+
3. Client adds callback: ?callback=myFunc
|
|
2816
|
+
4. Server wraps: myFunc({data})
|
|
2817
|
+
5. Validate callback name (security)
|
|
2818
|
+
`.trim()
|
|
2819
|
+
},
|
|
2820
|
+
|
|
2821
|
+
{
|
|
2822
|
+
name: "EXPRESS_STATIC_FILES_ERROR",
|
|
2823
|
+
match: /static.*file|send.*file|res\.sendFile|404.*file|Cannot GET.*\.js/i,
|
|
2824
|
+
explain: (error) => `
|
|
2825
|
+
Static file serving error - file not found or access denied.
|
|
2826
|
+
|
|
2827
|
+
Common causes:
|
|
2828
|
+
- File not in static directory
|
|
2829
|
+
- Wrong path
|
|
2830
|
+
- Path traversal attempt blocked
|
|
2831
|
+
- Permission denied
|
|
2832
|
+
|
|
2833
|
+
Solution:
|
|
2834
|
+
1. Serve static files: app.use(express.static('public'))
|
|
2835
|
+
2. For sendFile: res.sendFile('/path/to/file')
|
|
2836
|
+
3. Use absolute path: path.join(__dirname, 'public/file')
|
|
2837
|
+
4. Check file exists before sendFile
|
|
2838
|
+
5. Security: validate paths, prevent traversal
|
|
2839
|
+
`.trim()
|
|
2840
|
+
},
|
|
2841
|
+
|
|
2842
|
+
{
|
|
2843
|
+
name: "EXPRESS_METHOD_OVERRIDE_ERROR",
|
|
2844
|
+
match: /method.?override|_method|X-HTTP-Method-Override|PUT.*not.*allowed/i,
|
|
2845
|
+
explain: (error) => `
|
|
2846
|
+
Method override not working - HTTP method not overridden.
|
|
2847
|
+
|
|
2848
|
+
Common causes:
|
|
2849
|
+
- method-override not installed
|
|
2850
|
+
- Middleware not loaded
|
|
2851
|
+
- Wrong override header/param
|
|
2852
|
+
- PUT/DELETE not intended
|
|
2853
|
+
|
|
2854
|
+
Solution:
|
|
2855
|
+
1. Install: npm install method-override
|
|
2856
|
+
2. Use: app.use(methodOverride('_method'))
|
|
2857
|
+
3. Client sends: <input name="_method" value="PUT">
|
|
2858
|
+
4. Or header: X-HTTP-Method-Override: PUT
|
|
2859
|
+
5. Place before routes
|
|
2860
|
+
`.trim()
|
|
2861
|
+
},
|
|
2862
|
+
|
|
2863
|
+
{
|
|
2864
|
+
name: "EXPRESS_REQUEST_TIMEOUT",
|
|
2865
|
+
match: /request.*timeout|ETIMEDOUT|socket.*timeout|timeout.*request/i,
|
|
2866
|
+
explain: (error) => `
|
|
2867
|
+
Express request timed out - took too long to complete.
|
|
2868
|
+
|
|
2869
|
+
Common causes:
|
|
2870
|
+
- Handler taking too long
|
|
2871
|
+
- Database query slow
|
|
2872
|
+
- External API hanging
|
|
2873
|
+
- No response sent
|
|
2874
|
+
|
|
2875
|
+
Solution:
|
|
2876
|
+
1. Set timeout: server.setTimeout(30000)
|
|
2877
|
+
2. Implement request timeout middleware
|
|
2878
|
+
3. Use: const timeout = require('connect-timeout')
|
|
2879
|
+
4. Add timeout: app.use(timeout('5s'))
|
|
2880
|
+
5. Optimize slow operations
|
|
2881
|
+
`.trim()
|
|
2882
|
+
},
|
|
2883
|
+
|
|
2884
|
+
{
|
|
2885
|
+
name: "EXPRESS_HANDLEBARS_ERROR",
|
|
2886
|
+
match: /handlebars|HBS|template.*error|helper.*not.*found|partial.*error/i,
|
|
2887
|
+
explain: (error) => `
|
|
2888
|
+
Express Handlebars template engine error.
|
|
2889
|
+
|
|
2890
|
+
Common causes:
|
|
2891
|
+
- Template file not found
|
|
2892
|
+
- Syntax error in template
|
|
2893
|
+
- Helper not registered
|
|
2894
|
+
- Partial not found
|
|
2895
|
+
|
|
2896
|
+
Solution:
|
|
2897
|
+
1. Set engine: app.engine('hbs', require('express-handlebars')())
|
|
2898
|
+
2. Register helper: hbs.registerHelper('name', function(){})
|
|
2899
|
+
3. Register partial: hbs.registerPartial('name', template)
|
|
2900
|
+
4. Check template syntax
|
|
2901
|
+
5. Verify partial exists
|
|
2902
|
+
`.trim()
|
|
2903
|
+
},
|
|
2904
|
+
|
|
2905
|
+
{
|
|
2906
|
+
name: "EXPRESS_EJS_ERROR",
|
|
2907
|
+
match: /EJS|ejs.*error|ejs.*undefined|template.*render|ejs.*syntax/i,
|
|
2908
|
+
explain: (error) => `
|
|
2909
|
+
Express EJS template engine error.
|
|
2910
|
+
|
|
2911
|
+
Common causes:
|
|
2912
|
+
- Variable not passed to template
|
|
2913
|
+
- Template syntax error
|
|
2914
|
+
- File not found
|
|
2915
|
+
- Encoding issue
|
|
2916
|
+
|
|
2917
|
+
Solution:
|
|
2918
|
+
1. Set engine: app.set('view engine', 'ejs')
|
|
2919
|
+
2. Pass data: res.render('template', { variable: value })
|
|
2920
|
+
3. In template use: <%= variable %>
|
|
2921
|
+
4. Check EJS syntax
|
|
2922
|
+
5. Verify variable passed from route
|
|
2923
|
+
`.trim()
|
|
2924
|
+
},
|
|
2925
|
+
|
|
2926
|
+
{
|
|
2927
|
+
name: "EXPRESS_PUG_ERROR",
|
|
2928
|
+
match: /Pug|jade|pug.*error|indentation.*error|pug.*syntax/i,
|
|
2929
|
+
explain: (error) => `
|
|
2930
|
+
Express Pug template engine error.
|
|
2931
|
+
|
|
2932
|
+
Common causes:
|
|
2933
|
+
- Indentation error (Pug requires proper indentation)
|
|
2934
|
+
- Undefined variable
|
|
2935
|
+
- Syntax error
|
|
2936
|
+
- File not found
|
|
2937
|
+
|
|
2938
|
+
Solution:
|
|
2939
|
+
1. Set engine: app.set('view engine', 'pug')
|
|
2940
|
+
2. Check indentation (spaces, not tabs)
|
|
2941
|
+
3. Pass variables: res.render('template', { var: value })
|
|
2942
|
+
4. Use: p= variable
|
|
2943
|
+
5. Check Pug syntax is correct
|
|
2944
|
+
`.trim()
|
|
2945
|
+
},
|
|
2946
|
+
|
|
2947
|
+
{
|
|
2948
|
+
name: "EXPRESS_JWT_ERROR",
|
|
2949
|
+
match: /JWT|json.*web.*token|token.*invalid|jwt.*error|token.*expired/i,
|
|
2950
|
+
explain: (error) => `
|
|
2951
|
+
JSON Web Token (JWT) authentication error.
|
|
2952
|
+
|
|
2953
|
+
Common causes:
|
|
2954
|
+
- Token invalid or expired
|
|
2955
|
+
- Token not provided
|
|
2956
|
+
- Wrong secret key
|
|
2957
|
+
- Signature verification failed
|
|
2958
|
+
|
|
2959
|
+
Solution:
|
|
2960
|
+
1. Install: npm install jsonwebtoken
|
|
2961
|
+
2. Create token: jwt.sign(payload, secret, { expiresIn: '1h' })
|
|
2962
|
+
3. Verify token: jwt.verify(token, secret)
|
|
2963
|
+
4. Use middleware: const token = req.headers.authorization?.split(' ')[1]
|
|
2964
|
+
5. Handle expiration gracefully
|
|
2965
|
+
`.trim()
|
|
2966
|
+
},
|
|
2967
|
+
|
|
2968
|
+
{
|
|
2969
|
+
name: "EXPRESS_REDIRECT_CHAIN",
|
|
2970
|
+
match: /redirect.*loop|infinite.*redirect|too.*many.*redirect|redirect.*chain/i,
|
|
2971
|
+
explain: (error) => `
|
|
2972
|
+
Infinite redirect loop detected.
|
|
2973
|
+
|
|
2974
|
+
Common causes:
|
|
2975
|
+
- Route redirects to itself
|
|
2976
|
+
- A redirects to B, B redirects to A
|
|
2977
|
+
- Wrong redirect target
|
|
2978
|
+
- Middleware causing redirect loop
|
|
2979
|
+
|
|
2980
|
+
Solution:
|
|
2981
|
+
1. Check redirect target: res.redirect('/path')
|
|
2982
|
+
2. Verify target route exists
|
|
2983
|
+
3. Ensure redirect logic is correct
|
|
2984
|
+
4. Avoid cycles: A→B→A
|
|
2985
|
+
5. Debug: console.log redirect targets
|
|
2986
|
+
`.trim()
|
|
2987
|
+
},
|
|
2988
|
+
|
|
2989
|
+
{
|
|
2990
|
+
name: "EXPRESS_QUERY_PARAM_ERROR",
|
|
2991
|
+
match: /req\.query|query.*param|undefined.*query|query.*string/i,
|
|
2992
|
+
explain: (error) => `
|
|
2993
|
+
Query parameter not accessible or undefined.
|
|
2994
|
+
|
|
2995
|
+
Common causes:
|
|
2996
|
+
- Query string not in URL
|
|
2997
|
+
- Typo in param name
|
|
2998
|
+
- Not checking if exists
|
|
2999
|
+
- Parser not configured
|
|
3000
|
+
|
|
3001
|
+
Solution:
|
|
3002
|
+
1. Access: req.query.name
|
|
3003
|
+
2. Check exists: if (req.query.name)
|
|
3004
|
+
3. Provide default: req.query.page || 1
|
|
3005
|
+
4. Parse as needed: parseInt(req.query.page)
|
|
3006
|
+
5. Use: ?name=value&page=2
|
|
3007
|
+
`.trim()
|
|
3008
|
+
},
|
|
3009
|
+
|
|
3010
|
+
{
|
|
3011
|
+
name: "EXPRESS_ROUTE_PARAM_ERROR",
|
|
3012
|
+
match: /req\.params|route.*param|undefined.*param|param.*not.*found/i,
|
|
3013
|
+
explain: (error) => `
|
|
3014
|
+
Route parameter missing or undefined.
|
|
3015
|
+
|
|
3016
|
+
Common causes:
|
|
3017
|
+
- Route not defined with param
|
|
3018
|
+
- Param name mismatch
|
|
3019
|
+
- Route not matched
|
|
3020
|
+
- Typo in param access
|
|
3021
|
+
|
|
3022
|
+
Solution:
|
|
3023
|
+
1. Define route: app.get('/user/:id', ...)
|
|
3024
|
+
2. Access: req.params.id
|
|
3025
|
+
3. Check param name matches route:id
|
|
3026
|
+
4. Validate param exists before use
|
|
3027
|
+
5. Convert if needed: parseInt(req.params.id)
|
|
3028
|
+
`.trim()
|
|
3029
|
+
},
|
|
3030
|
+
|
|
3031
|
+
{
|
|
3032
|
+
name: "EXPRESS_X_POWERED_BY",
|
|
3033
|
+
match: /x.?powered.?by|X-Powered-By|prevent.*disclosure/i,
|
|
3034
|
+
explain: (error) => `
|
|
3035
|
+
X-Powered-By header disclosure - security information leaked.
|
|
3036
|
+
|
|
3037
|
+
Common causes:
|
|
3038
|
+
- Header shows Express version
|
|
3039
|
+
- Security risk: attackers know stack
|
|
3040
|
+
- Not disabled
|
|
3041
|
+
|
|
3042
|
+
Solution:
|
|
3043
|
+
1. Disable: app.disable('x-powered-by')
|
|
3044
|
+
2. Or use Helmet: app.use(helmet())
|
|
3045
|
+
3. Hide server info from headers
|
|
3046
|
+
4. Don't expose technology stack
|
|
3047
|
+
5. Set custom Server header if needed
|
|
3048
|
+
`.trim()
|
|
3049
|
+
},
|
|
3050
|
+
|
|
3051
|
+
{
|
|
3052
|
+
name: "EXPRESS_CASE_SENSITIVE_ROUTING",
|
|
3053
|
+
match: /case.?sensitive|routing.*case|case.*insensitive/i,
|
|
3054
|
+
explain: (error) => `
|
|
3055
|
+
Route case sensitivity issue - /Path and /path treated differently.
|
|
3056
|
+
|
|
3057
|
+
Common causes:
|
|
3058
|
+
- Case-sensitive routing enabled
|
|
3059
|
+
- Client uses wrong case
|
|
3060
|
+
- Route defined differently
|
|
3061
|
+
|
|
3062
|
+
Solution:
|
|
3063
|
+
1. Enable case insensitive: app.set('case sensitive routing', false)
|
|
3064
|
+
2. Or disable: app.set('case sensitive routing', false)
|
|
3065
|
+
3. Consistent route naming
|
|
3066
|
+
4. Test with different cases
|
|
3067
|
+
5. Default is case sensitive
|
|
3068
|
+
`.trim()
|
|
3069
|
+
},
|
|
3070
|
+
|
|
3071
|
+
{
|
|
3072
|
+
name: "EXPRESS_STRICT_ROUTING",
|
|
3073
|
+
match: /strict.*routing|trailing.*slash|\/path\/ vs \/path/i,
|
|
3074
|
+
explain: (error) => `
|
|
3075
|
+
Strict routing enabled - trailing slash matters.
|
|
3076
|
+
|
|
3077
|
+
Common causes:
|
|
3078
|
+
- /path and /path/ treated differently
|
|
3079
|
+
- Strict routing enabled
|
|
3080
|
+
- Missing trailing slash
|
|
3081
|
+
|
|
3082
|
+
Solution:
|
|
3083
|
+
1. Disable strict: app.set('strict routing', false)
|
|
3084
|
+
2. Or handle both: app.get('/path', ...) and app.get('/path/', ...)
|
|
3085
|
+
3. Redirect: app.get('/path', (req, res) => res.redirect('/path/'))
|
|
3086
|
+
4. Be consistent in URLs
|
|
3087
|
+
5. Default is disabled (not strict)
|
|
3088
|
+
`.trim()
|
|
3089
|
+
},
|
|
3090
|
+
|
|
3091
|
+
{
|
|
3092
|
+
name: "EXPRESS_ETAG_ERROR",
|
|
3093
|
+
match: /ETag|weak.*ETag|strong.*ETag|304.*Not Modified/i,
|
|
3094
|
+
explain: (error) => `
|
|
3095
|
+
Entity tag (ETag) issue - caching problem.
|
|
3096
|
+
|
|
3097
|
+
Common causes:
|
|
3098
|
+
- ETag mismatch
|
|
3099
|
+
- If-None-Match not handled
|
|
3100
|
+
- Cache control issue
|
|
3101
|
+
|
|
3102
|
+
Solution:
|
|
3103
|
+
1. Use: app.set('etag', true)
|
|
3104
|
+
2. Express generates by default
|
|
3105
|
+
3. Disable if issues: app.disable('etag')
|
|
3106
|
+
4. Client sends: If-None-Match: <etag>
|
|
3107
|
+
5. Respond 304 if matches
|
|
3108
|
+
`.trim()
|
|
3109
|
+
},
|
|
3110
|
+
|
|
3111
|
+
{
|
|
3112
|
+
name: "EXPRESS_VARY_HEADER",
|
|
3113
|
+
match: /Vary.*header|Accept-Encoding|Accept-Language|vary|cache.*vary/i,
|
|
3114
|
+
explain: (error) => `
|
|
3115
|
+
Vary header issue - caching with multiple conditions.
|
|
3116
|
+
|
|
3117
|
+
Common causes:
|
|
3118
|
+
- Missing Vary header for conditional responses
|
|
3119
|
+
- Proxy caching issue
|
|
3120
|
+
- Response varies by Accept-* headers
|
|
3121
|
+
|
|
3122
|
+
Solution:
|
|
3123
|
+
1. Set Vary header: res.vary('Accept-Encoding')
|
|
3124
|
+
2. For multiple: res.vary('Accept-Encoding, Accept-Language')
|
|
3125
|
+
3. Express adds by default in some cases
|
|
3126
|
+
4. Ensures proper caching
|
|
3127
|
+
5. Tells caches response depends on header
|
|
3128
|
+
`.trim()
|
|
3129
|
+
},
|
|
3130
|
+
|
|
3131
|
+
{
|
|
3132
|
+
name: "EXPRESS_LINK_HEADER",
|
|
3133
|
+
match: /Link.*header|preload|rel=preload|link.*rel/i,
|
|
3134
|
+
explain: (error) => `
|
|
3135
|
+
HTTP Link header issue - preload or resource hints.
|
|
3136
|
+
|
|
3137
|
+
Common causes:
|
|
3138
|
+
- Preload header not working
|
|
3139
|
+
- Wrong syntax
|
|
3140
|
+
- Browser doesn't support
|
|
3141
|
+
|
|
3142
|
+
Solution:
|
|
3143
|
+
1. Add Link header: res.setHeader('Link', '<style.css>; rel=preload; as=style')
|
|
3144
|
+
2. Preload resources for performance
|
|
3145
|
+
3. Format: <url>; rel=relation; attr=value
|
|
3146
|
+
4. Modern browsers support preload
|
|
3147
|
+
5. Improves page load performance
|
|
3148
|
+
`.trim()
|
|
3149
|
+
},
|
|
3150
|
+
|
|
3151
|
+
{
|
|
3152
|
+
name: "EXPRESS_ACCEPT_HEADER",
|
|
3153
|
+
match: /Accept.*header|accepts|req\.accepts|content.*negotiation/i,
|
|
3154
|
+
explain: (error) => `
|
|
3155
|
+
Request Accept header negotiation error or mismatch.
|
|
3156
|
+
|
|
3157
|
+
Common causes:
|
|
3158
|
+
- Content type not accepted by client
|
|
3159
|
+
- Accept header not set properly
|
|
3160
|
+
- No matching content type
|
|
3161
|
+
|
|
3162
|
+
Solution:
|
|
3163
|
+
1. Check: req.accepts('json'), req.accepts('html')
|
|
3164
|
+
2. Use: app.get('/', (req, res) => {
|
|
3165
|
+
if (req.accepts('json')) res.json({})
|
|
3166
|
+
else res.send('');
|
|
3167
|
+
3. Client sets Accept header
|
|
3168
|
+
4. Negotiate content type
|
|
3169
|
+
5. Return 406 if can't negotiate
|
|
3170
|
+
`.trim()
|
|
3171
|
+
},
|
|
3172
|
+
|
|
3173
|
+
{
|
|
3174
|
+
name: "EXPRESS_GATEWAY_TIMEOUT",
|
|
3175
|
+
match: /gateway.*timeout|502.*gateway|upstream.*timeout|gateway.*error/i,
|
|
3176
|
+
explain: (error) => `
|
|
3177
|
+
Gateway timeout when proxying requests - upstream service too slow.
|
|
3178
|
+
|
|
3179
|
+
Common causes:
|
|
3180
|
+
- Upstream service slow
|
|
3181
|
+
- Timeout too short
|
|
3182
|
+
- Service not responding
|
|
3183
|
+
|
|
3184
|
+
Solution:
|
|
3185
|
+
1. Increase proxy timeout
|
|
3186
|
+
2. Use http-proxy-middleware
|
|
3187
|
+
3. Add: proxyReq.setTimeout(30000)
|
|
3188
|
+
4. Check upstream service status
|
|
3189
|
+
5. Add error handling for proxy
|
|
3190
|
+
`.trim()
|
|
3191
|
+
},
|
|
3192
|
+
|
|
3193
|
+
{
|
|
3194
|
+
name: "EXPRESS_NO_CATCH_ALL",
|
|
3195
|
+
match: /no.*catch.*all|final.*middleware|404.*handler|unhandled.*route/i,
|
|
3196
|
+
explain: (error) => `
|
|
3197
|
+
No catch-all 404 handler defined - unmatched routes not handled.
|
|
3198
|
+
|
|
3199
|
+
Common causes:
|
|
3200
|
+
- 404 middleware not added
|
|
3201
|
+
- 404 handler after routes
|
|
3202
|
+
- Routes not properly matched
|
|
3203
|
+
|
|
3204
|
+
Solution:
|
|
3205
|
+
1. Add at end of routes:
|
|
3206
|
+
app.use((req, res) => res.status(404).send('Not Found'))
|
|
3207
|
+
2. Or: app.use('*', (req, res) => res.status(404))
|
|
3208
|
+
3. Place after all other routes
|
|
3209
|
+
4. Provide user-friendly 404 page
|
|
3210
|
+
5. Log 404s for debugging
|
|
3211
|
+
`.trim()
|
|
3212
|
+
},
|
|
3213
|
+
|
|
3214
|
+
{
|
|
3215
|
+
name: "GENERAL_ERROR",
|
|
3216
|
+
match: /error|failed|exception/i,
|
|
3217
|
+
explain: (error) => `
|
|
3218
|
+
A general error occurred. Check the error message and stack trace above.
|
|
3219
|
+
|
|
3220
|
+
This is caught by the generic catch-all pattern.
|
|
3221
|
+
|
|
3222
|
+
Solution:
|
|
3223
|
+
1. Read the full error message carefully
|
|
3224
|
+
2. Look at the stack trace to find where error originated
|
|
3225
|
+
3. Check the file and line numbers
|
|
3226
|
+
4. Search error message online with project name
|
|
3227
|
+
5. Ask for help with complete error details
|
|
3228
|
+
`.trim()
|
|
3229
|
+
}
|
|
3230
|
+
];
|
|
3231
|
+
|
|
3232
|
+
/**
|
|
3233
|
+
* Find error pattern by matching against error text
|
|
3234
|
+
* Returns the first matching pattern or the GENERAL_ERROR pattern
|
|
3235
|
+
*/
|
|
3236
|
+
function findErrorPattern(errorText) {
|
|
3237
|
+
const pattern = errorPatterns.find(p => p.match.test(errorText));
|
|
3238
|
+
return pattern || errorPatterns[errorPatterns.length - 1]; // Return GENERAL_ERROR if no match
|
|
3239
|
+
}
|
|
3240
|
+
|
|
3241
|
+
/**
|
|
3242
|
+
* Get explanation for an error
|
|
3243
|
+
*/
|
|
3244
|
+
function getErrorExplanation(errorText) {
|
|
3245
|
+
const pattern = findErrorPattern(errorText);
|
|
3246
|
+
return pattern.explain(errorText);
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
module.exports = {
|
|
3250
|
+
errorPatterns,
|
|
3251
|
+
findErrorPattern,
|
|
3252
|
+
getErrorExplanation
|
|
3253
|
+
};
|