Skip to content

[CI Failure Doctor] TypeScript Type Error in close_older_issues.cjs - Accessing .stack on unknown type #11063

@github-actions

Description

@github-actions

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

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 sufficient

Impact

  • 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 from error_helpers.cjs for error messages
  • Use error instanceof Error check before accessing .stack, .message, or other Error properties
  • Always run npm run typecheck before 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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions