mirror of
https://github.com/anthropics/claude-code-action.git
synced 2026-08-22 11:28:55 +08:00
fix: write execution file when SDK throws (#1255)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as core from "@actions/core";
|
||||
import { readFile, writeFile, access } from "fs/promises";
|
||||
import { readFile, access } from "fs/promises";
|
||||
import { dirname, join } from "path";
|
||||
import { query } from "@anthropic-ai/claude-agent-sdk";
|
||||
import type {
|
||||
@@ -8,6 +8,7 @@ import type {
|
||||
SDKUserMessage,
|
||||
} from "@anthropic-ai/claude-agent-sdk";
|
||||
import type { ParsedSdkOptions } from "./parse-sdk-options";
|
||||
import { writeExecutionFile } from "./execution-file";
|
||||
|
||||
export type ClaudeRunResult = {
|
||||
executionFile?: string;
|
||||
@@ -16,8 +17,6 @@ export type ClaudeRunResult = {
|
||||
structuredOutput?: string;
|
||||
};
|
||||
|
||||
const EXECUTION_FILE = `${process.env.RUNNER_TEMP}/claude-execution-output.json`;
|
||||
|
||||
/** Filename for the user request file, written by prompt generation */
|
||||
const USER_REQUEST_FILENAME = "claude-user-request.txt";
|
||||
|
||||
@@ -172,6 +171,7 @@ export async function runClaudeWithSdk(
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("SDK execution error:", error);
|
||||
await writeExecutionFile(messages);
|
||||
throw new Error(`SDK execution error: ${error}`);
|
||||
}
|
||||
|
||||
@@ -179,13 +179,9 @@ export async function runClaudeWithSdk(
|
||||
conclusion: "failure",
|
||||
};
|
||||
|
||||
// Write execution file
|
||||
try {
|
||||
await writeFile(EXECUTION_FILE, JSON.stringify(messages, null, 2));
|
||||
console.log(`Log saved to ${EXECUTION_FILE}`);
|
||||
result.executionFile = EXECUTION_FILE;
|
||||
} catch (error) {
|
||||
core.warning(`Failed to write execution file: ${error}`);
|
||||
const executionFile = await writeExecutionFile(messages);
|
||||
if (executionFile) {
|
||||
result.executionFile = executionFile;
|
||||
}
|
||||
|
||||
// Extract session_id from system.init message
|
||||
|
||||
Reference in New Issue
Block a user