atlas-pipeline-mcp 1.0.17 → 1.0.18
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/README.md +45 -1
- package/dist/mcp.js +263 -0
- package/dist/mcp.js.map +1 -1
- package/dist/tools/debug.d.ts +101 -0
- package/dist/tools/debug.d.ts.map +1 -0
- package/dist/tools/debug.js +712 -0
- package/dist/tools/debug.js.map +1 -0
- package/dist/tools/docs.d.ts +94 -0
- package/dist/tools/docs.d.ts.map +1 -0
- package/dist/tools/docs.js +508 -0
- package/dist/tools/docs.js.map +1 -0
- package/dist/tools/explain.d.ts +82 -0
- package/dist/tools/explain.d.ts.map +1 -0
- package/dist/tools/explain.js +543 -0
- package/dist/tools/explain.js.map +1 -0
- package/dist/tools/security.d.ts +45 -0
- package/dist/tools/security.d.ts.map +1 -0
- package/dist/tools/security.js +417 -0
- package/dist/tools/security.js.map +1 -0
- package/dist/tools/testgen.d.ts +52 -0
- package/dist/tools/testgen.d.ts.map +1 -0
- package/dist/tools/testgen.js +413 -0
- package/dist/tools/testgen.js.map +1 -0
- package/dist/tools/think.d.ts +187 -0
- package/dist/tools/think.d.ts.map +1 -0
- package/dist/tools/think.js +432 -0
- package/dist/tools/think.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,712 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atlas Server - Debugging Assistance Tool
|
|
3
|
+
*
|
|
4
|
+
* Intelligent debugging capabilities:
|
|
5
|
+
* - Error analysis and root cause detection
|
|
6
|
+
* - Stack trace parsing and explanation
|
|
7
|
+
* - Fix suggestions with code examples
|
|
8
|
+
* - Memory leak detection hints
|
|
9
|
+
* - Performance bottleneck identification
|
|
10
|
+
* - Common anti-pattern detection
|
|
11
|
+
*/
|
|
12
|
+
import { getActiveProvider, isNoLLMMode } from '../providers/index.js';
|
|
13
|
+
import { logger } from '../utils.js';
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Main Debug Function
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Analyze an error and provide debugging assistance
|
|
19
|
+
*/
|
|
20
|
+
export async function analyzeError(request) {
|
|
21
|
+
const { error, stackTrace, code, context, language, framework } = request;
|
|
22
|
+
logger.debug({ errorPreview: error?.substring(0, 100) }, 'Starting debug analysis');
|
|
23
|
+
if (!error && !stackTrace) {
|
|
24
|
+
throw new Error('Either error message or stack trace is required');
|
|
25
|
+
}
|
|
26
|
+
// Detect language
|
|
27
|
+
const detectedLanguage = language ?? detectLanguage(code ?? stackTrace ?? '');
|
|
28
|
+
const detectedFramework = framework ?? detectFramework(code ?? stackTrace ?? '');
|
|
29
|
+
// Parse stack trace if present
|
|
30
|
+
const stackAnalysis = stackTrace ? parseStackTrace(stackTrace, detectedLanguage) : undefined;
|
|
31
|
+
// Classify error type
|
|
32
|
+
const errorType = classifyError(error ?? '', stackTrace ?? '');
|
|
33
|
+
// Generate analysis
|
|
34
|
+
let analysis;
|
|
35
|
+
if (!isNoLLMMode()) {
|
|
36
|
+
try {
|
|
37
|
+
analysis = await analyzeWithAI({
|
|
38
|
+
error,
|
|
39
|
+
stackTrace,
|
|
40
|
+
code,
|
|
41
|
+
context,
|
|
42
|
+
language: detectedLanguage,
|
|
43
|
+
framework: detectedFramework,
|
|
44
|
+
stackAnalysis,
|
|
45
|
+
errorType,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
logger.warn({ err }, 'AI analysis failed, using heuristic analysis');
|
|
50
|
+
analysis = generateHeuristicAnalysis(error ?? '', stackTrace, code, detectedLanguage, errorType, stackAnalysis);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
analysis = generateHeuristicAnalysis(error ?? '', stackTrace, code, detectedLanguage, errorType, stackAnalysis);
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
analysis,
|
|
58
|
+
metadata: {
|
|
59
|
+
language: detectedLanguage,
|
|
60
|
+
framework: detectedFramework,
|
|
61
|
+
errorType,
|
|
62
|
+
hasStackTrace: !!stackTrace,
|
|
63
|
+
hasCode: !!code,
|
|
64
|
+
},
|
|
65
|
+
generatedAt: new Date().toISOString(),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
// ============================================================================
|
|
69
|
+
// Error Classification
|
|
70
|
+
// ============================================================================
|
|
71
|
+
function classifyError(error, stackTrace) {
|
|
72
|
+
const combined = `${error} ${stackTrace}`.toLowerCase();
|
|
73
|
+
// Syntax errors
|
|
74
|
+
if (combined.includes('syntaxerror') || combined.includes('unexpected token') ||
|
|
75
|
+
combined.includes('parsing error') || combined.includes('invalid syntax')) {
|
|
76
|
+
return 'syntax';
|
|
77
|
+
}
|
|
78
|
+
// Type errors
|
|
79
|
+
if (combined.includes('typeerror') || combined.includes('cannot read property') ||
|
|
80
|
+
combined.includes('is not a function') || combined.includes('undefined is not') ||
|
|
81
|
+
combined.includes("'undefined' is not") || combined.includes('type error')) {
|
|
82
|
+
return 'type';
|
|
83
|
+
}
|
|
84
|
+
// Reference errors
|
|
85
|
+
if (combined.includes('referenceerror') || combined.includes('is not defined') ||
|
|
86
|
+
combined.includes('cannot find name') || combined.includes('undeclared')) {
|
|
87
|
+
return 'reference';
|
|
88
|
+
}
|
|
89
|
+
// Async errors
|
|
90
|
+
if (combined.includes('unhandled promise') || combined.includes('async') ||
|
|
91
|
+
combined.includes('await') || combined.includes('promise rejected')) {
|
|
92
|
+
return 'async';
|
|
93
|
+
}
|
|
94
|
+
// Network errors
|
|
95
|
+
if (combined.includes('network') || combined.includes('fetch') ||
|
|
96
|
+
combined.includes('econnrefused') || combined.includes('timeout') ||
|
|
97
|
+
combined.includes('cors') || combined.includes('http')) {
|
|
98
|
+
return 'network';
|
|
99
|
+
}
|
|
100
|
+
// Memory errors
|
|
101
|
+
if (combined.includes('heap') || combined.includes('memory') ||
|
|
102
|
+
combined.includes('out of memory') || combined.includes('stack overflow')) {
|
|
103
|
+
return 'memory';
|
|
104
|
+
}
|
|
105
|
+
// Configuration errors
|
|
106
|
+
if (combined.includes('config') || combined.includes('environment') ||
|
|
107
|
+
combined.includes('env') || combined.includes('setting')) {
|
|
108
|
+
return 'configuration';
|
|
109
|
+
}
|
|
110
|
+
// Dependency errors
|
|
111
|
+
if (combined.includes('module not found') || combined.includes('cannot find module') ||
|
|
112
|
+
combined.includes('no such file') || combined.includes('import') && combined.includes('failed')) {
|
|
113
|
+
return 'dependency';
|
|
114
|
+
}
|
|
115
|
+
// Permission errors
|
|
116
|
+
if (combined.includes('permission') || combined.includes('access denied') ||
|
|
117
|
+
combined.includes('unauthorized') || combined.includes('forbidden')) {
|
|
118
|
+
return 'permission';
|
|
119
|
+
}
|
|
120
|
+
// Runtime (general)
|
|
121
|
+
if (combined.includes('error') || combined.includes('exception')) {
|
|
122
|
+
return 'runtime';
|
|
123
|
+
}
|
|
124
|
+
return 'unknown';
|
|
125
|
+
}
|
|
126
|
+
// ============================================================================
|
|
127
|
+
// Stack Trace Parsing
|
|
128
|
+
// ============================================================================
|
|
129
|
+
function parseStackTrace(stackTrace, language) {
|
|
130
|
+
const lines = stackTrace.split('\n').filter(l => l.trim());
|
|
131
|
+
const frames = [];
|
|
132
|
+
if (['javascript', 'typescript', 'node'].includes(language.toLowerCase())) {
|
|
133
|
+
// JavaScript/Node.js stack trace format
|
|
134
|
+
const frameRegex = /at\s+(?:(.+?)\s+\()?(.+?):(\d+):(\d+)\)?/;
|
|
135
|
+
for (const line of lines) {
|
|
136
|
+
const match = frameRegex.exec(line);
|
|
137
|
+
if (match) {
|
|
138
|
+
const filePath = match[2] ?? '';
|
|
139
|
+
frames.push({
|
|
140
|
+
function: match[1] ?? '<anonymous>',
|
|
141
|
+
file: filePath,
|
|
142
|
+
line: parseInt(match[3] ?? '0', 10),
|
|
143
|
+
column: parseInt(match[4] ?? '0', 10),
|
|
144
|
+
isUserCode: !filePath.includes('node_modules') && !filePath.includes('internal/'),
|
|
145
|
+
isAsync: line.includes('async') || line.includes('Promise'),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if (language.toLowerCase() === 'python') {
|
|
151
|
+
// Python traceback format
|
|
152
|
+
const frameRegex = /File\s+"(.+?)",\s+line\s+(\d+),\s+in\s+(.+)/;
|
|
153
|
+
for (const line of lines) {
|
|
154
|
+
const match = frameRegex.exec(line);
|
|
155
|
+
if (match) {
|
|
156
|
+
frames.push({
|
|
157
|
+
function: match[3] ?? '<module>',
|
|
158
|
+
file: match[1] ?? '',
|
|
159
|
+
line: parseInt(match[2] ?? '0', 10),
|
|
160
|
+
isUserCode: !match[1]?.includes('site-packages'),
|
|
161
|
+
isAsync: match[3]?.includes('async') ?? false,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// Find originating frame (first user code frame)
|
|
167
|
+
const originatingFrame = frames.find(f => f.isUserCode) ?? frames[0] ?? {
|
|
168
|
+
function: 'unknown',
|
|
169
|
+
file: 'unknown',
|
|
170
|
+
line: 0,
|
|
171
|
+
isUserCode: false,
|
|
172
|
+
isAsync: false,
|
|
173
|
+
};
|
|
174
|
+
// Build call path
|
|
175
|
+
const callPath = frames.map(f => f.function).filter(f => f !== '<anonymous>');
|
|
176
|
+
// Find involved modules
|
|
177
|
+
const involvedModules = [...new Set(frames
|
|
178
|
+
.map(f => {
|
|
179
|
+
const match = f.file.match(/node_modules\/([^/]+)/);
|
|
180
|
+
return match ? match[1] : null;
|
|
181
|
+
})
|
|
182
|
+
.filter((m) => m !== null))];
|
|
183
|
+
return {
|
|
184
|
+
frames,
|
|
185
|
+
originatingFrame,
|
|
186
|
+
callPath,
|
|
187
|
+
isAsync: frames.some(f => f.isAsync),
|
|
188
|
+
involvedModules,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// ============================================================================
|
|
192
|
+
// AI Analysis
|
|
193
|
+
// ============================================================================
|
|
194
|
+
async function analyzeWithAI(params) {
|
|
195
|
+
const provider = await getActiveProvider();
|
|
196
|
+
const prompt = `Analyze this programming error and provide debugging assistance.
|
|
197
|
+
|
|
198
|
+
## Error Information
|
|
199
|
+
**Error Message:** ${params.error ?? 'Not provided'}
|
|
200
|
+
**Error Type:** ${params.errorType}
|
|
201
|
+
**Language:** ${params.language}
|
|
202
|
+
${params.framework ? `**Framework:** ${params.framework}` : ''}
|
|
203
|
+
|
|
204
|
+
${params.stackTrace ? `## Stack Trace
|
|
205
|
+
\`\`\`
|
|
206
|
+
${params.stackTrace}
|
|
207
|
+
\`\`\`` : ''}
|
|
208
|
+
|
|
209
|
+
${params.code ? `## Related Code
|
|
210
|
+
\`\`\`${params.language}
|
|
211
|
+
${params.code}
|
|
212
|
+
\`\`\`` : ''}
|
|
213
|
+
|
|
214
|
+
${params.context ? `## Additional Context
|
|
215
|
+
${params.context}` : ''}
|
|
216
|
+
|
|
217
|
+
${params.stackAnalysis ? `## Stack Analysis
|
|
218
|
+
- Originating frame: ${params.stackAnalysis.originatingFrame.function} at ${params.stackAnalysis.originatingFrame.file}:${params.stackAnalysis.originatingFrame.line}
|
|
219
|
+
- Call path: ${params.stackAnalysis.callPath.join(' → ')}
|
|
220
|
+
- Is async: ${params.stackAnalysis.isAsync}
|
|
221
|
+
- Involved modules: ${params.stackAnalysis.involvedModules.join(', ') || 'none'}` : ''}
|
|
222
|
+
|
|
223
|
+
## Output Format
|
|
224
|
+
Provide your analysis as JSON:
|
|
225
|
+
{
|
|
226
|
+
"summary": "One-line summary of the issue",
|
|
227
|
+
"rootCause": {
|
|
228
|
+
"type": "${params.errorType}",
|
|
229
|
+
"description": "What caused this error",
|
|
230
|
+
"location": {"file": "filename", "line": 123, "function": "funcName"},
|
|
231
|
+
"explanation": "Detailed explanation of why this error occurred",
|
|
232
|
+
"commonScenarios": ["scenario 1", "scenario 2"]
|
|
233
|
+
},
|
|
234
|
+
"fixes": [
|
|
235
|
+
{
|
|
236
|
+
"title": "Fix title",
|
|
237
|
+
"description": "How this fixes the issue",
|
|
238
|
+
"code": {
|
|
239
|
+
"before": "buggy code",
|
|
240
|
+
"after": "fixed code",
|
|
241
|
+
"language": "${params.language}",
|
|
242
|
+
"explanation": "What changed and why"
|
|
243
|
+
},
|
|
244
|
+
"steps": ["step 1", "step 2"],
|
|
245
|
+
"confidence": 0.9,
|
|
246
|
+
"tradeoffs": "Any drawbacks to this approach"
|
|
247
|
+
}
|
|
248
|
+
],
|
|
249
|
+
"relatedIssues": [
|
|
250
|
+
{
|
|
251
|
+
"title": "Related issue",
|
|
252
|
+
"description": "Description",
|
|
253
|
+
"likelihood": "high|medium|low",
|
|
254
|
+
"symptoms": ["symptom 1"]
|
|
255
|
+
}
|
|
256
|
+
],
|
|
257
|
+
"preventionTips": ["Tip 1", "Tip 2"],
|
|
258
|
+
"resources": [
|
|
259
|
+
{"title": "Resource", "url": "https://...", "type": "documentation", "relevance": 0.9}
|
|
260
|
+
],
|
|
261
|
+
"confidence": 0.85
|
|
262
|
+
}`;
|
|
263
|
+
const response = await provider.completeJson(prompt, {
|
|
264
|
+
systemPrompt: 'You are an expert debugger and software engineer. Analyze errors thoroughly and provide actionable fix suggestions. Return valid JSON only.',
|
|
265
|
+
temperature: 0.3,
|
|
266
|
+
maxTokens: 4096,
|
|
267
|
+
});
|
|
268
|
+
if (response.data) {
|
|
269
|
+
return response.data;
|
|
270
|
+
}
|
|
271
|
+
throw new Error('Failed to generate AI analysis');
|
|
272
|
+
}
|
|
273
|
+
// ============================================================================
|
|
274
|
+
// Heuristic Analysis
|
|
275
|
+
// ============================================================================
|
|
276
|
+
function generateHeuristicAnalysis(error, stackTrace, code, language, errorType, stackAnalysis) {
|
|
277
|
+
// Get error-specific analysis
|
|
278
|
+
const errorInfo = getErrorTypeInfo(errorType, error, language);
|
|
279
|
+
return {
|
|
280
|
+
summary: `${errorType.charAt(0).toUpperCase() + errorType.slice(1)} error: ${error.split('\n')[0]?.substring(0, 100)}`,
|
|
281
|
+
rootCause: {
|
|
282
|
+
type: errorType,
|
|
283
|
+
description: errorInfo.description,
|
|
284
|
+
location: stackAnalysis?.originatingFrame ? {
|
|
285
|
+
file: stackAnalysis.originatingFrame.file,
|
|
286
|
+
line: stackAnalysis.originatingFrame.line,
|
|
287
|
+
function: stackAnalysis.originatingFrame.function,
|
|
288
|
+
} : undefined,
|
|
289
|
+
explanation: errorInfo.explanation,
|
|
290
|
+
commonScenarios: errorInfo.scenarios,
|
|
291
|
+
},
|
|
292
|
+
stackAnalysis,
|
|
293
|
+
fixes: errorInfo.fixes,
|
|
294
|
+
relatedIssues: errorInfo.relatedIssues,
|
|
295
|
+
preventionTips: errorInfo.preventionTips,
|
|
296
|
+
resources: errorInfo.resources,
|
|
297
|
+
confidence: 0.6,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
function getErrorTypeInfo(errorType, error, language) {
|
|
301
|
+
const errorLower = error.toLowerCase();
|
|
302
|
+
switch (errorType) {
|
|
303
|
+
case 'type':
|
|
304
|
+
return {
|
|
305
|
+
description: 'A type-related operation failed, such as calling a method on undefined or using the wrong data type.',
|
|
306
|
+
explanation: 'This typically occurs when a variable has an unexpected value (null, undefined) or when trying to use a value as the wrong type (e.g., calling a function on a number).',
|
|
307
|
+
scenarios: [
|
|
308
|
+
'Accessing a property on undefined or null',
|
|
309
|
+
'Calling a function that doesn\'t exist on an object',
|
|
310
|
+
'Array index out of bounds',
|
|
311
|
+
'Wrong data type passed to a function',
|
|
312
|
+
],
|
|
313
|
+
fixes: [
|
|
314
|
+
{
|
|
315
|
+
title: 'Add null/undefined check',
|
|
316
|
+
description: 'Check if the value exists before using it',
|
|
317
|
+
code: {
|
|
318
|
+
before: 'obj.property.method()',
|
|
319
|
+
after: 'obj?.property?.method?.()',
|
|
320
|
+
language,
|
|
321
|
+
explanation: 'Optional chaining (?.) safely handles undefined values',
|
|
322
|
+
},
|
|
323
|
+
steps: [
|
|
324
|
+
'Identify the variable that might be undefined',
|
|
325
|
+
'Add optional chaining (?.) or nullish checks',
|
|
326
|
+
'Consider providing default values',
|
|
327
|
+
],
|
|
328
|
+
confidence: 0.8,
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
title: 'Add type validation',
|
|
332
|
+
description: 'Validate types before operations',
|
|
333
|
+
steps: [
|
|
334
|
+
'Check typeof before operations',
|
|
335
|
+
'Use TypeScript for compile-time checks',
|
|
336
|
+
'Add runtime type guards',
|
|
337
|
+
],
|
|
338
|
+
confidence: 0.7,
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
relatedIssues: [
|
|
342
|
+
{
|
|
343
|
+
title: 'Async timing issue',
|
|
344
|
+
description: 'Data might not be loaded when accessed',
|
|
345
|
+
likelihood: 'medium',
|
|
346
|
+
symptoms: ['Works sometimes', 'Works after refresh', 'Console logs show data later'],
|
|
347
|
+
},
|
|
348
|
+
],
|
|
349
|
+
preventionTips: [
|
|
350
|
+
'Use TypeScript for better type safety',
|
|
351
|
+
'Initialize variables with default values',
|
|
352
|
+
'Add defensive null checks in critical paths',
|
|
353
|
+
'Use optional chaining (?.) and nullish coalescing (??)',
|
|
354
|
+
],
|
|
355
|
+
resources: [
|
|
356
|
+
{ title: 'Optional Chaining', type: 'documentation', relevance: 0.9 },
|
|
357
|
+
{ title: 'TypeScript Null Checking', type: 'documentation', relevance: 0.8 },
|
|
358
|
+
],
|
|
359
|
+
};
|
|
360
|
+
case 'reference':
|
|
361
|
+
return {
|
|
362
|
+
description: 'A variable or function was used before it was defined or is not in scope.',
|
|
363
|
+
explanation: 'This happens when code tries to access something that doesn\'t exist in the current scope, often due to typos, missing imports, or scope issues.',
|
|
364
|
+
scenarios: [
|
|
365
|
+
'Typo in variable or function name',
|
|
366
|
+
'Missing import statement',
|
|
367
|
+
'Variable used before declaration',
|
|
368
|
+
'Out-of-scope variable access',
|
|
369
|
+
],
|
|
370
|
+
fixes: [
|
|
371
|
+
{
|
|
372
|
+
title: 'Check for typos',
|
|
373
|
+
description: 'Verify the variable/function name is spelled correctly',
|
|
374
|
+
steps: [
|
|
375
|
+
'Compare the name with where it\'s defined',
|
|
376
|
+
'Check for case sensitivity issues',
|
|
377
|
+
'Look for similar-looking characters',
|
|
378
|
+
],
|
|
379
|
+
confidence: 0.9,
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
title: 'Add missing import',
|
|
383
|
+
description: 'Import the module that defines this',
|
|
384
|
+
steps: [
|
|
385
|
+
'Identify which module exports this',
|
|
386
|
+
'Add the import statement at the top',
|
|
387
|
+
'Check if the export name matches',
|
|
388
|
+
],
|
|
389
|
+
confidence: 0.8,
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
relatedIssues: [
|
|
393
|
+
{
|
|
394
|
+
title: 'Circular dependency',
|
|
395
|
+
description: 'Modules importing each other can cause undefined exports',
|
|
396
|
+
likelihood: 'low',
|
|
397
|
+
symptoms: ['Works in isolation', 'Import is undefined at runtime'],
|
|
398
|
+
},
|
|
399
|
+
],
|
|
400
|
+
preventionTips: [
|
|
401
|
+
'Use an IDE with autocomplete',
|
|
402
|
+
'Enable strict mode in TypeScript',
|
|
403
|
+
'Use ESLint with no-undef rule',
|
|
404
|
+
'Keep imports organized and explicit',
|
|
405
|
+
],
|
|
406
|
+
resources: [
|
|
407
|
+
{ title: 'JavaScript Scope', type: 'documentation', relevance: 0.9 },
|
|
408
|
+
{ title: 'ES6 Modules', type: 'documentation', relevance: 0.8 },
|
|
409
|
+
],
|
|
410
|
+
};
|
|
411
|
+
case 'async':
|
|
412
|
+
return {
|
|
413
|
+
description: 'An asynchronous operation failed or was not handled properly.',
|
|
414
|
+
explanation: 'Async errors occur when Promises reject without proper error handling, or when async/await is used incorrectly.',
|
|
415
|
+
scenarios: [
|
|
416
|
+
'Missing await keyword',
|
|
417
|
+
'Unhandled Promise rejection',
|
|
418
|
+
'Network request failed',
|
|
419
|
+
'Timeout exceeded',
|
|
420
|
+
],
|
|
421
|
+
fixes: [
|
|
422
|
+
{
|
|
423
|
+
title: 'Add try/catch around async operations',
|
|
424
|
+
description: 'Wrap async code in error handling',
|
|
425
|
+
code: {
|
|
426
|
+
before: 'const data = await fetchData();',
|
|
427
|
+
after: `try {
|
|
428
|
+
const data = await fetchData();
|
|
429
|
+
} catch (error) {
|
|
430
|
+
console.error('Failed to fetch:', error);
|
|
431
|
+
}`,
|
|
432
|
+
language,
|
|
433
|
+
explanation: 'try/catch handles Promise rejections in async functions',
|
|
434
|
+
},
|
|
435
|
+
steps: [
|
|
436
|
+
'Identify the async operation',
|
|
437
|
+
'Wrap in try/catch block',
|
|
438
|
+
'Add appropriate error handling',
|
|
439
|
+
],
|
|
440
|
+
confidence: 0.85,
|
|
441
|
+
},
|
|
442
|
+
{
|
|
443
|
+
title: 'Add missing await',
|
|
444
|
+
description: 'Ensure async functions are properly awaited',
|
|
445
|
+
steps: [
|
|
446
|
+
'Check if function returns a Promise',
|
|
447
|
+
'Add await before the call',
|
|
448
|
+
'Make parent function async if needed',
|
|
449
|
+
],
|
|
450
|
+
confidence: 0.75,
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
relatedIssues: [
|
|
454
|
+
{
|
|
455
|
+
title: 'Race condition',
|
|
456
|
+
description: 'Multiple async operations completing in unexpected order',
|
|
457
|
+
likelihood: 'medium',
|
|
458
|
+
symptoms: ['Inconsistent behavior', 'Works on retry'],
|
|
459
|
+
},
|
|
460
|
+
],
|
|
461
|
+
preventionTips: [
|
|
462
|
+
'Always use try/catch with async/await',
|
|
463
|
+
'Add .catch() to all Promises',
|
|
464
|
+
'Use Promise.all for parallel operations',
|
|
465
|
+
'Set appropriate timeouts',
|
|
466
|
+
],
|
|
467
|
+
resources: [
|
|
468
|
+
{ title: 'Async/Await Best Practices', type: 'documentation', relevance: 0.9 },
|
|
469
|
+
{ title: 'Promise Error Handling', type: 'documentation', relevance: 0.85 },
|
|
470
|
+
],
|
|
471
|
+
};
|
|
472
|
+
case 'network':
|
|
473
|
+
return {
|
|
474
|
+
description: 'A network-related operation failed.',
|
|
475
|
+
explanation: 'Network errors can occur due to connectivity issues, server errors, CORS restrictions, or timeout.',
|
|
476
|
+
scenarios: [
|
|
477
|
+
'Server is unreachable',
|
|
478
|
+
'CORS policy blocking request',
|
|
479
|
+
'Request timeout',
|
|
480
|
+
'Invalid URL or endpoint',
|
|
481
|
+
],
|
|
482
|
+
fixes: [
|
|
483
|
+
{
|
|
484
|
+
title: 'Add retry logic',
|
|
485
|
+
description: 'Retry failed requests with backoff',
|
|
486
|
+
steps: [
|
|
487
|
+
'Wrap request in retry function',
|
|
488
|
+
'Add exponential backoff',
|
|
489
|
+
'Set maximum retry count',
|
|
490
|
+
],
|
|
491
|
+
confidence: 0.7,
|
|
492
|
+
},
|
|
493
|
+
{
|
|
494
|
+
title: 'Check CORS configuration',
|
|
495
|
+
description: 'Ensure server allows the request origin',
|
|
496
|
+
steps: [
|
|
497
|
+
'Check browser console for CORS error',
|
|
498
|
+
'Verify server CORS headers',
|
|
499
|
+
'Use a proxy in development',
|
|
500
|
+
],
|
|
501
|
+
confidence: 0.65,
|
|
502
|
+
},
|
|
503
|
+
],
|
|
504
|
+
relatedIssues: [
|
|
505
|
+
{
|
|
506
|
+
title: 'SSL/TLS certificate issue',
|
|
507
|
+
description: 'Certificate validation failing',
|
|
508
|
+
likelihood: 'low',
|
|
509
|
+
symptoms: ['Works on some machines', 'Works without HTTPS'],
|
|
510
|
+
},
|
|
511
|
+
],
|
|
512
|
+
preventionTips: [
|
|
513
|
+
'Always handle network errors gracefully',
|
|
514
|
+
'Implement request timeouts',
|
|
515
|
+
'Add loading and error states to UI',
|
|
516
|
+
'Use proper error boundaries',
|
|
517
|
+
],
|
|
518
|
+
resources: [
|
|
519
|
+
{ title: 'Fetch API Error Handling', type: 'documentation', relevance: 0.9 },
|
|
520
|
+
{ title: 'CORS Explained', type: 'article', relevance: 0.8 },
|
|
521
|
+
],
|
|
522
|
+
};
|
|
523
|
+
case 'dependency':
|
|
524
|
+
return {
|
|
525
|
+
description: 'A required module or package could not be found.',
|
|
526
|
+
explanation: 'This happens when an import references a module that isn\'t installed, has a wrong path, or has version conflicts.',
|
|
527
|
+
scenarios: [
|
|
528
|
+
'Package not installed',
|
|
529
|
+
'Wrong import path',
|
|
530
|
+
'Version mismatch',
|
|
531
|
+
'Typo in package name',
|
|
532
|
+
],
|
|
533
|
+
fixes: [
|
|
534
|
+
{
|
|
535
|
+
title: 'Install missing package',
|
|
536
|
+
description: 'Add the required dependency',
|
|
537
|
+
code: {
|
|
538
|
+
before: '// Package not found error',
|
|
539
|
+
after: 'npm install <package-name>',
|
|
540
|
+
language: 'bash',
|
|
541
|
+
explanation: 'Install the missing package with npm or yarn',
|
|
542
|
+
},
|
|
543
|
+
steps: [
|
|
544
|
+
'Identify the package name from the error',
|
|
545
|
+
'Run npm install or yarn add',
|
|
546
|
+
'Restart the development server',
|
|
547
|
+
],
|
|
548
|
+
confidence: 0.9,
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
title: 'Fix import path',
|
|
552
|
+
description: 'Correct the relative or absolute import path',
|
|
553
|
+
steps: [
|
|
554
|
+
'Check the actual file location',
|
|
555
|
+
'Verify the path is relative to current file',
|
|
556
|
+
'Check for index.js conventions',
|
|
557
|
+
],
|
|
558
|
+
confidence: 0.8,
|
|
559
|
+
},
|
|
560
|
+
],
|
|
561
|
+
relatedIssues: [
|
|
562
|
+
{
|
|
563
|
+
title: 'Peer dependency conflict',
|
|
564
|
+
description: 'Package requires a different version of another package',
|
|
565
|
+
likelihood: 'medium',
|
|
566
|
+
symptoms: ['npm install warnings', 'Works after --force'],
|
|
567
|
+
},
|
|
568
|
+
],
|
|
569
|
+
preventionTips: [
|
|
570
|
+
'Keep package.json in sync',
|
|
571
|
+
'Use a lock file (package-lock.json)',
|
|
572
|
+
'Run npm ci in CI/CD',
|
|
573
|
+
'Regularly update dependencies',
|
|
574
|
+
],
|
|
575
|
+
resources: [
|
|
576
|
+
{ title: 'npm install documentation', type: 'documentation', relevance: 0.9 },
|
|
577
|
+
{ title: 'Node.js module resolution', type: 'documentation', relevance: 0.8 },
|
|
578
|
+
],
|
|
579
|
+
};
|
|
580
|
+
case 'memory':
|
|
581
|
+
return {
|
|
582
|
+
description: 'A memory-related error occurred, potentially a leak or overflow.',
|
|
583
|
+
explanation: 'Memory errors happen when the application uses too much memory, has a leak, or causes stack overflow through deep recursion.',
|
|
584
|
+
scenarios: [
|
|
585
|
+
'Infinite loop creating objects',
|
|
586
|
+
'Event listeners not cleaned up',
|
|
587
|
+
'Recursive function without base case',
|
|
588
|
+
'Large data structures in memory',
|
|
589
|
+
],
|
|
590
|
+
fixes: [
|
|
591
|
+
{
|
|
592
|
+
title: 'Add recursion base case',
|
|
593
|
+
description: 'Ensure recursive functions have exit conditions',
|
|
594
|
+
steps: [
|
|
595
|
+
'Identify the recursive function',
|
|
596
|
+
'Add or fix the base case condition',
|
|
597
|
+
'Consider converting to iteration',
|
|
598
|
+
],
|
|
599
|
+
confidence: 0.8,
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
title: 'Clean up event listeners',
|
|
603
|
+
description: 'Remove listeners when components unmount',
|
|
604
|
+
steps: [
|
|
605
|
+
'Track all added listeners',
|
|
606
|
+
'Remove in cleanup/unmount',
|
|
607
|
+
'Use WeakMap for object references',
|
|
608
|
+
],
|
|
609
|
+
confidence: 0.75,
|
|
610
|
+
},
|
|
611
|
+
],
|
|
612
|
+
relatedIssues: [
|
|
613
|
+
{
|
|
614
|
+
title: 'Closure retaining references',
|
|
615
|
+
description: 'Closures holding onto large objects',
|
|
616
|
+
likelihood: 'medium',
|
|
617
|
+
symptoms: ['Memory grows over time', 'GC not collecting'],
|
|
618
|
+
},
|
|
619
|
+
],
|
|
620
|
+
preventionTips: [
|
|
621
|
+
'Use heap profiling tools',
|
|
622
|
+
'Implement proper cleanup',
|
|
623
|
+
'Avoid global variables',
|
|
624
|
+
'Use streaming for large data',
|
|
625
|
+
],
|
|
626
|
+
resources: [
|
|
627
|
+
{ title: 'Memory Management in JavaScript', type: 'documentation', relevance: 0.9 },
|
|
628
|
+
{ title: 'Chrome DevTools Memory', type: 'documentation', relevance: 0.85 },
|
|
629
|
+
],
|
|
630
|
+
};
|
|
631
|
+
default:
|
|
632
|
+
return {
|
|
633
|
+
description: 'An error occurred during code execution.',
|
|
634
|
+
explanation: 'This error needs further investigation to determine the root cause.',
|
|
635
|
+
scenarios: [
|
|
636
|
+
'Logic error in code',
|
|
637
|
+
'Unexpected input data',
|
|
638
|
+
'Environment-specific issue',
|
|
639
|
+
'Third-party library bug',
|
|
640
|
+
],
|
|
641
|
+
fixes: [
|
|
642
|
+
{
|
|
643
|
+
title: 'Add logging for debugging',
|
|
644
|
+
description: 'Add console logs to trace the issue',
|
|
645
|
+
steps: [
|
|
646
|
+
'Add logs before and after the failing line',
|
|
647
|
+
'Log variable values',
|
|
648
|
+
'Check the execution path',
|
|
649
|
+
],
|
|
650
|
+
confidence: 0.6,
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
title: 'Isolate the problem',
|
|
654
|
+
description: 'Create a minimal reproduction',
|
|
655
|
+
steps: [
|
|
656
|
+
'Create a simple test case',
|
|
657
|
+
'Remove unrelated code',
|
|
658
|
+
'Test in isolation',
|
|
659
|
+
],
|
|
660
|
+
confidence: 0.5,
|
|
661
|
+
},
|
|
662
|
+
],
|
|
663
|
+
relatedIssues: [],
|
|
664
|
+
preventionTips: [
|
|
665
|
+
'Write unit tests for critical paths',
|
|
666
|
+
'Use error monitoring in production',
|
|
667
|
+
'Add comprehensive logging',
|
|
668
|
+
'Document known issues',
|
|
669
|
+
],
|
|
670
|
+
resources: [
|
|
671
|
+
{ title: 'Debugging Techniques', type: 'documentation', relevance: 0.7 },
|
|
672
|
+
{ title: 'Error Handling Best Practices', type: 'article', relevance: 0.6 },
|
|
673
|
+
],
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
// ============================================================================
|
|
678
|
+
// Helper Functions
|
|
679
|
+
// ============================================================================
|
|
680
|
+
function detectLanguage(content) {
|
|
681
|
+
if (content.includes('at ') && content.includes('.js:'))
|
|
682
|
+
return 'javascript';
|
|
683
|
+
if (content.includes('at ') && content.includes('.ts:'))
|
|
684
|
+
return 'typescript';
|
|
685
|
+
if (content.includes('File "') && content.includes('.py"'))
|
|
686
|
+
return 'python';
|
|
687
|
+
if (content.includes('.go:'))
|
|
688
|
+
return 'go';
|
|
689
|
+
if (content.includes('.java:'))
|
|
690
|
+
return 'java';
|
|
691
|
+
return 'javascript';
|
|
692
|
+
}
|
|
693
|
+
function detectFramework(content) {
|
|
694
|
+
if (content.includes('React') || content.includes('useState') || content.includes('useEffect'))
|
|
695
|
+
return 'React';
|
|
696
|
+
if (content.includes('angular') || content.includes('@Component'))
|
|
697
|
+
return 'Angular';
|
|
698
|
+
if (content.includes('Vue') || content.includes('createApp'))
|
|
699
|
+
return 'Vue';
|
|
700
|
+
if (content.includes('next') || content.includes('getServerSideProps'))
|
|
701
|
+
return 'Next.js';
|
|
702
|
+
if (content.includes('express') || content.includes('app.get'))
|
|
703
|
+
return 'Express';
|
|
704
|
+
if (content.includes('fastify'))
|
|
705
|
+
return 'Fastify';
|
|
706
|
+
if (content.includes('django') || content.includes('views.py'))
|
|
707
|
+
return 'Django';
|
|
708
|
+
if (content.includes('flask') || content.includes('@app.route'))
|
|
709
|
+
return 'Flask';
|
|
710
|
+
return undefined;
|
|
711
|
+
}
|
|
712
|
+
//# sourceMappingURL=debug.js.map
|