claude-code-action icon indicating copy to clipboard operation
claude-code-action copied to clipboard

Error messages hidden by output sanitization when is_error: true

Open shcv opened this issue 10 months ago • 0 comments

Description

When an invalid model ID causes an API error, the helpful error message is hidden by the action's output sanitization, leaving users with only an opaque "process exited with code 1" error and minified code context.

Root Cause

The action's sanitizeSdkOutput function in base-action/src/run-claude-sdk.ts (lines 105-119) deliberately omits the result field from result messages:

if (message.type === "result") {
  const resultMsg = message as SDKResultMessage;
  return JSON.stringify(
    {
      type: "result",
      subtype: resultMsg.subtype,
      is_error: resultMsg.is_error,
      duration_ms: resultMsg.duration_ms,
      num_turns: resultMsg.num_turns,
      total_cost_usd: resultMsg.total_cost_usd,
      permission_denials: resultMsg.permission_denials,
      // NOTE: 'result' field is NOT included - this hides error messages!
    },
    null,
    2,
  );
}

When is_error: true, the result field contains the actual error message (e.g., "API Error: 404 model not found"), but this is never shown to the user.

Reproduction

Workflow configuration with invalid model ID:

- uses: anthropics/claude-code-action@v1
  with:
    claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
    claude_args: |
      --model claude-sonnet-4-5-20250514

What User Sees

{
  "type": "result",
  "subtype": "success",
  "is_error": true,
  "duration_ms": 230,
  "num_turns": 1,
  "total_cost_usd": 0,
  "permission_denials": []
}
SDK execution error: 14 |     depsCount: ${Q},
15 |     deps: ${$}}`};var Pj={keyword:"dependencies"...
...
error: Claude Code process exited with code 1

No indication of what went wrong. The minified code dump is just coincidental context, not the actual error.

What User Should See

{
  "type": "result",
  "subtype": "success",
  "is_error": true,
  "duration_ms": 230,
  "result": "API Error: 404 {\"type\":\"error\",\"error\":{\"type\":\"not_found_error\",\"message\":\"model: claude-sonnet-4-5-20250514\"}}",
  ...
}

Suggested Fix

In base-action/src/run-claude-sdk.ts, include the result field when is_error is true:

if (message.type === "result") {
  const resultMsg = message as SDKResultMessage;
  return JSON.stringify(
    {
      type: "result",
      subtype: resultMsg.subtype,
      is_error: resultMsg.is_error,
      duration_ms: resultMsg.duration_ms,
      num_turns: resultMsg.num_turns,
      total_cost_usd: resultMsg.total_cost_usd,
      permission_denials: resultMsg.permission_denials,
      // Include result field when there's an error
      ...(resultMsg.is_error && { result: resultMsg.result }),
    },
    null,
    2,
  );
}

Environment

  • Action Version: anthropics/claude-code-action@v1
  • SDK Version: 0.2.23
  • Claude Code Version: 2.1.23

Workaround

Enable show_full_output: true in your workflow to see full error messages:

- uses: anthropics/claude-code-action@v1
  with:
    show_full_output: true
    # ...

Or run in debug mode by setting the ACTIONS_STEP_DEBUG secret to true.

Related PRs

  • #83 - "Add enhanced text sanitization" - Likely introduced this sanitization behavior
  • #164 - "feat: enhance error reporting with specific error types" - Improved error types but didn't address the result field being stripped
  • #580 - "Add show_full_output option" - Added the workaround but didn't fix the default behavior for errors

Note

This fix may also help with #874 (unhelpful error message when API key has no credits) - the actual API error message is likely being hidden by the same sanitization logic.

shcv avatar Jan 29 '26 17:01 shcv