Conversation
…guard for error.stack access Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix TypeScript type error in close_older_issues.cjs
Fix TypeScript type error in close_older_issues.cjs - add type guard for error.stack access
Jan 21, 2026
Contributor
|
@copilot use error helper instead to handle errors |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TypeScript TS18046 error in CI: catch clause
errorvariable isunknowntype (TypeScript 4.4+), cannot access.stackproperty without type guard.Changes
instanceof Errortype guard before accessingerror.stackin catch clause (line 315)create_issue.cjs,mcp_logger.cjs, andmcp_server_core.cjsBefore/After
Original prompt
This section details on the original issue you should resolve
<issue_title>[CI Failure Doctor] TypeScript Type Error in close_older_issues.cjs - Accessing .stack on unknown type</issue_title>
<issue_description>## Summary
The CI workflow (run githubnext/gh-aw#21219744664) failed due to a TypeScript type safety error in
close_older_issues.cjs. The code attempts to access the.stackproperty directly on a catch clauseerrorvariable without a type guard, which TypeScript correctly flags as unsafe.Failure Details
js(step: Run tests - typecheck phase)Root Cause Analysis
TypeScript Error TS18046
Why This Fails
As of TypeScript 4.4+, catch clause variables default to
unknowninstead ofanyfor better type safety. The code at line 315 attempts to accesserror.stackwithout first checking thaterroris actually anErrorobject.Current Code (Line 311-317)
Correct Pattern Used in Other Files
All other files in the codebase correctly use type guards:
Recommended Fix
Option 1: Use instanceof check (recommended)
Option 2: Use 'in' operator check
Option 3: Remove stack trace logging (simplest)
// Just remove line 315 - the error message from getErrorMessage() is usually sufficientImpact
Prevention Strategy
For AI Coding Agents
Add to developer instructions:
Pattern used in this codebase:
getErrorMessage(error)helper fromerror_helpers.cjsfor error messageserror instanceof Errorcheck before accessing.stack,.message, or other Error propertiesnpm run typecheckbefore committing JavaScript changesHistorical 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
TYPESCRIPT_ERROR_UNKNOWN_TYPE(1st occurrence)/tmp/gh-aw/cache-memory/investigations/2026-01-21-21219744664.json💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.