-
Notifications
You must be signed in to change notification settings - Fork 251
Description
Summary
The CI workflow (run #21219744664) failed due to a TypeScript type safety error in close_older_issues.cjs. The code attempts to access the .stack property directly on a catch clause error variable without a type guard, which TypeScript correctly flags as unsafe.
Failure Details
- Run: #21219744664
- Commit: ff3cdd2
- PR: Clean up smoke trigger label after successful test run #10997 - Clean up smoke trigger label after successful test run
- Trigger: push (main branch)
- Failed Job:
js(step: Run tests - typecheck phase)
Root Cause Analysis
TypeScript Error TS18046
close_older_issues.cjs:315:36 - error TS18046: 'error' is of type 'unknown'.
315 core.error(` Stack trace: ${error.stack || "(not available)"}`);
~~~~~
Why This Fails
As of TypeScript 4.4+, catch clause variables default to unknown instead of any for better type safety. The code at line 315 attempts to access error.stack without first checking that error is actually an Error object.
Current Code (Line 311-317)
} catch (error) {
core.info("");
core.error(`✗ Failed to close issue #${issue.number}`);
core.error(` Error: ${getErrorMessage(error)}`); // ✅ Correct - uses helper
core.error(` Stack trace: ${error.stack || "(not available)"}`); // ❌ Error - direct access
// Continue with other issues even if one fails
}Correct Pattern Used in Other Files
All other files in the codebase correctly use type guards:
// create_issue.cjs:537 - instanceof check
core.info(`Error details: ${error instanceof Error ? error.stack : String(error)}`);
// mcp_logger.cjs:44-45 - instanceof check
if (error instanceof Error && error.stack) {
logger.debug(`${prefix}Stack trace: ${error.stack}`);
}
// safe_inputs_mcp_server_http.cjs:299-300 - 'in' operator check
if ("stack" in error && error.stack) {
errorLogger.debug(`Stack trace:\n${error.stack}`);
}Recommended Fix
Option 1: Use instanceof check (recommended)
} catch (error) {
core.info("");
core.error(`✗ Failed to close issue #${issue.number}`);
core.error(` Error: ${getErrorMessage(error)}`);
if (error instanceof Error && error.stack) {
core.error(` Stack trace: ${error.stack}`);
}
// Continue with other issues even if one fails
}Option 2: Use 'in' operator check
core.error(` Stack trace: ${"stack" in error && error.stack ? error.stack : "(not available)"}`);Option 3: Remove stack trace logging (simplest)
// Just remove line 315 - the error message from getErrorMessage() is usually sufficientImpact
- Severity: Medium (blocks CI, but easy fix)
- Time to Fix: ~5 minutes
- Affected Area: JavaScript test job in CI pipeline
Prevention Strategy
For AI Coding Agents
Add to developer instructions:
## TypeScript Catch Clause Error Handling
**ALWAYS use type guards when accessing error properties in catch clauses:**
```javascript
// ❌ WRONG - TypeScript error TS18046
} catch (error) {
console.log(error.stack); // Error: 'error' is of type 'unknown'
}
// ✅ CORRECT - Use instanceof type guard
} catch (error) {
if (error instanceof Error) {
console.log(error.stack);
}
}
// ✅ CORRECT - Use 'in' operator
} catch (error) {
if ("stack" in error && error.stack) {
console.log(error.stack);
}
}
// ✅ CORRECT - Use helper function (preferred in this codebase)
} catch (error) {
const errorMessage = getErrorMessage(error); // Handles unknown type safely
console.log(errorMessage);
}Pattern used in this codebase:
- Use
getErrorMessage(error)helper fromerror_helpers.cjsfor error messages - Use
error instanceof Errorcheck before accessing.stack,.message, or other Error properties - Always run
npm run typecheckbefore committing JavaScript changes
### Pre-Commit Checklist
```bash
cd actions/setup/js
npm ci
npm run typecheck # MUST pass
npm test # MUST pass
Historical Context
This is the first occurrence of this specific error pattern in the repository. The error was introduced as part of PR #10997, which was a large commit (2570 files changed) that appears to include a bulk repository update or merge.
Investigation Metadata
- Pattern:
TYPESCRIPT_ERROR_UNKNOWN_TYPE(1st occurrence) - Investigation Record:
/tmp/gh-aw/cache-memory/investigations/2026-01-21-21219744664.json - Created: 2026-01-21T17:51:25Z
🤖 AI generated by CI Failure Doctor
AI generated by CI Failure Doctor
To add this workflow in your repository, run
gh aw add githubnext/agentics/workflows/ci-doctor.md@ea350161ad5dcc9624cf510f134c6a9e39a6f94d. See usage guide.