mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-01-22 22:44:13 +08:00
feat: enhance error reporting with specific error types from Claude execution (#164)
* feat: enhance error reporting with specific error types from Claude execution - Extract error subtypes (error_during_execution, error_max_turns) from result object - Display specific error messages in comment header based on error type - Use total_cost_usd field from SDKResultMessage type - Prevent showing redundant error details when already displayed in header 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: update claude-code-base-action to v0.0.19 * feat: use GitHub display name in Co-authored-by trailers (#163) * feat: use GitHub display name in Co-authored-by trailers - Add name field to GitHubAuthor type - Update GraphQL queries to fetch user display names - Add triggerDisplayName to CommonFields type - Extract display name from fetched GitHub data in prepareContext - Update Co-authored-by trailer generation to use display name when available This ensures consistency with GitHub's web interface behavior where Co-authored-by trailers use the user's display name rather than username. Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com> * fix: update GraphQL queries to handle Actor type correctly The name field is only available on the User subtype of Actor in GitHub's GraphQL API. This commit updates the queries to use inline fragments (... on User) to conditionally access the name field when the actor is a User type. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: clarify Co-authored-by instructions in prompt Replace interpolated values with clear references to XML tags and add explicit formatting instructions. This makes it clearer how to use the GitHub display name when available while maintaining the username for the email portion. Changes: - Use explicit references to <trigger_display_name> and <trigger_username> tags - Add clear formatting instructions and example - Explain fallback behavior when display name is not available 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: fetch trigger user display name via dedicated GraphQL query Instead of trying to extract the display name from existing data (which was incomplete due to Actor type limitations), we now: - Add a dedicated USER_QUERY to fetch user display names - Pass the trigger username to fetchGitHubData - Fetch the display name during data collection phase - Simplify prepareContext to use the pre-fetched display name This ensures we always get the correct display name for Co-authored-by trailers, regardless of where the trigger came from. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com> * feat: use dynamic fetch depth based on PR commit count (#169) - Replace fixed depth of 20 with dynamic calculation - Use Math.max(commitCount, 20) to ensure minimum context * Accept multiline input for allowed_tools and disallowed_tools (#168) * docs: add uv example for Python MCP servers in mcp_config section (#170) Added documentation showing how to configure Python-based MCP servers using uv with the --directory argument, as requested in issue #130. Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: Ashwin Bhat <ashwin-ant@users.noreply.github.com> * feat: add release workflow with beta tag management (#171) - Auto-increment patch version for new releases - Update beta tag to point to latest release - Update major version tag (v0) for simplified action usage - Support dry run mode for testing - Keep beta as the "latest" release channel 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <noreply@anthropic.com> * chore: update claude-code-base-action to v0.0.20 * update MCP server image to version 0.5.0 (#175) * refactor: convert error subtype check to switch case Replace if-else chain with switch statement for better readability and maintainability when handling error subtypes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: GitHub Actions <actions@github.com> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: ashwin-ant <ashwin-ant@users.noreply.github.com> Co-authored-by: Bastian Gutschke <bge@medicuja.com> Co-authored-by: Hidetake Iwata <int128@gmail.com> Co-authored-by: Tomohiro Ishibashi <103555868+tomoish@users.noreply.github.com>
This commit is contained in:
@@ -147,6 +147,7 @@ async function run() {
|
||||
} | null = null;
|
||||
let actionFailed = false;
|
||||
let errorDetails: string | undefined;
|
||||
let errorSubtype: string | undefined;
|
||||
|
||||
// First check if prepare step failed
|
||||
const prepareSuccess = process.env.PREPARE_SUCCESS !== "false";
|
||||
@@ -166,23 +167,40 @@ async function run() {
|
||||
// Output file is an array, get the last element which contains execution details
|
||||
if (Array.isArray(outputData) && outputData.length > 0) {
|
||||
const lastElement = outputData[outputData.length - 1];
|
||||
if (
|
||||
lastElement.type === "result" &&
|
||||
"cost_usd" in lastElement &&
|
||||
"duration_ms" in lastElement
|
||||
) {
|
||||
if (lastElement.type === "result") {
|
||||
// Extract execution details
|
||||
executionDetails = {
|
||||
cost_usd: lastElement.cost_usd,
|
||||
cost_usd: lastElement.total_cost_usd,
|
||||
duration_ms: lastElement.duration_ms,
|
||||
duration_api_ms: lastElement.duration_api_ms,
|
||||
};
|
||||
|
||||
// Check if this is an error result based on subtype
|
||||
switch (lastElement.subtype) {
|
||||
case "error_during_execution":
|
||||
errorSubtype = "Error during execution";
|
||||
// Override the actionFailed flag based on the result
|
||||
actionFailed = true;
|
||||
break;
|
||||
case "error_max_turns":
|
||||
errorSubtype = "Maximum turns exceeded";
|
||||
actionFailed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the Claude action failed
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS !== "false";
|
||||
actionFailed = !claudeSuccess;
|
||||
// Check if the Claude action failed (only if not already determined from result)
|
||||
if (!actionFailed) {
|
||||
const claudeSuccess = process.env.CLAUDE_SUCCESS !== "false";
|
||||
actionFailed = !claudeSuccess;
|
||||
}
|
||||
|
||||
// Use errorSubtype as errorDetails if no other error details are available
|
||||
if (actionFailed && !errorDetails && errorSubtype) {
|
||||
errorDetails = errorSubtype;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error reading output file:", error);
|
||||
// If we can't read the file, check for any failure markers
|
||||
|
||||
@@ -114,6 +114,16 @@ export function updateCommentBody(input: CommentUpdateInput): string {
|
||||
|
||||
if (actionFailed) {
|
||||
header = "**Claude encountered an error";
|
||||
|
||||
// Add error type to header if available
|
||||
if (errorDetails) {
|
||||
if (errorDetails === "Error during execution") {
|
||||
header = "**Claude encountered an error during execution";
|
||||
} else if (errorDetails === "Maximum turns exceeded") {
|
||||
header = "**Claude exceeded the maximum number of turns";
|
||||
}
|
||||
}
|
||||
|
||||
if (durationStr) {
|
||||
header += ` after ${durationStr}`;
|
||||
}
|
||||
@@ -181,8 +191,13 @@ export function updateCommentBody(input: CommentUpdateInput): string {
|
||||
// Build the new body with blank line between header and separator
|
||||
let newBody = `${header}${links}`;
|
||||
|
||||
// Add error details if available
|
||||
if (actionFailed && errorDetails) {
|
||||
// Add error details if available (but not if it's just the error type we already showed in header)
|
||||
if (
|
||||
actionFailed &&
|
||||
errorDetails &&
|
||||
errorDetails !== "Error during execution" &&
|
||||
errorDetails !== "Maximum turns exceeded"
|
||||
) {
|
||||
newBody += `\n\n\`\`\`\n${errorDetails}\n\`\`\``;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user