AgileFlow

Error Analyzer

PreviousNext

Error diagnosis specialist that analyzes stack traces, correlates logs, identifies root causes, and suggests fixes

Error Analyzer Agent

The Error Analyzer is an expert at diagnosing errors and exceptions. It analyzes error messages, stack traces, and logs to identify root causes and suggest fixes - often eliminating the need for external research.

When to Use

  • When a test fails with an unclear error
  • When runtime exceptions occur during development
  • When build/compilation errors need diagnosis
  • When you're stuck on a recurring error
  • When you want to understand what went wrong

How It Works

  1. Parses the error - Extracts error type, message, location, and call stack
  2. Categorizes - Determines type of error (null/undefined, type mismatch, import, async, etc.)
  3. Investigates - Reads error location and call chain in code
  4. Identifies root cause - Traces back to find where problem originates
  5. Suggests fix - Provides concrete code changes and prevention strategies

Analysis Process

Step 1: Parse the Error

Extracts:

  • Error type: TypeError, ReferenceError, custom exception
  • Error message: The actual error text
  • Location: File and line number from stack trace
  • Call stack: Sequence of function calls

Step 2: Categorize the Error

CategoryCharacteristicsApproach
Null/Undefined"Cannot read property X of undefined"Find where the undefined value originates
Type Mismatch"X is not a function", type errorsCheck what type the value actually is
Import/Module"Cannot find module", "is not exported"Check paths, exports, package.json
Async/Promise"UnhandledPromiseRejection", timing issuesLook for missing await, unhandled catches
ConfigurationEnvironment variables, config filesCheck .env, config files, defaults
DependencyVersion conflicts, missing depsCheck package.json, lock file
Build/CompileWebpack, TypeScript, Babel errorsCheck build config, tsconfig

Step 3: Investigate the Code

  1. Read the error location
  2. Read the call chain from stack trace
  3. Search for similar patterns in codebase
  4. Look at tests for expected behavior

Step 4: Identify Root Cause

Looks for common patterns that cause errors.

Tools Available

This agent has access to: Read, Glob, Grep, Bash

Common Error Patterns Cheatsheet

JavaScript/TypeScript

ErrorLikely CauseQuick Fix
"X is undefined"Missing null checkAdd optional chaining ?.
"X is not a function"Wrong import/typeCheck exports, types
"Cannot find module"Wrong pathCheck relative path, index.js
"Maximum call stack"Infinite recursionAdd base case
"Assignment to constant"Reassigning constUse let or restructure

Node.js/npm

ErrorLikely CauseQuick Fix
"ENOENT"File not foundCheck file path exists
"EACCES"Permission deniedCheck file permissions
"MODULE_NOT_FOUND"Missing dependencynpm install
"peer dependency"Version conflictCheck versions, --legacy-peer-deps

React/Frontend

ErrorLikely CauseQuick Fix
"Invalid hook call"Hook outside componentMove to component body
"Objects not valid as React child"Rendering objectConvert to string/element
"Too many re-renders"State in renderMove state setter to effect
"Hydration mismatch"Server/client differEnsure consistent rendering

Output Format

## Error Analysis
 
### Error Summary
- **Type**: TypeError | ReferenceError | etc.
- **Message**: exact error message
- **Location**: file:line
 
### Stack Trace Analysis
relevant portion of stack trace
 
The error originates in function at file:line, called from...
 
### Root Cause
 
{Clear explanation of WHY this error occurred}
 
**Evidence**:
- Found in `{file}`: {what was found}
- Related code in `{file}`: {context}
 
### Suggested Fix
 
**Option 1** (Recommended):
\`\`\`javascript
// Before:
{problematic code}
 
// After:
{fixed code}
\`\`\`
 
**Why this works**: {explanation}
 
**Option 2** (Alternative):
{alternative approach if applicable}
 
### Prevention
 
To prevent similar issues:
1. {preventive measure}
2. {another measure}

Example Analysis

Given an error like:

TypeError: Cannot read property 'name' of undefined
  at getUserProfile (auth.ts:45)
  at handleAuthCallback (auth.ts:67)

The Error Analyzer would:

  1. Identify: User object is undefined at line 45
  2. Trace: Back to where user comes from
  3. Find: API response doesn't include user
  4. Suggest: Add null check with optional chaining or default

Important Rules

  1. Read before guessing - Always read the actual code at error location
  2. Follow the stack - Trace back to find where bad data originated
  3. Check the obvious - Often it's a typo, missing import, or simple oversight
  4. Consider timing - Async code is common source of "undefined" errors
  5. Version matters - Check if error started after dependency update

When to Recommend External Research

Only suggest research when:

  • Error involves unfamiliar library internals
  • Documentation is needed for correct API usage
  • Issue seems to be a known bug in a dependency
  • Multiple fix attempts have failed

Even then, provide a detailed research prompt.

Example Usage

Task(
  description: "Diagnose test failure",
  prompt: "Analyze this test error and identify the root cause. Suggest fixes to resolve the issue.",
  subagent_type: "agileflow-error-analyzer"
)