fix: guard JSON.parse(result.stdout) with || "{}" fallback in hook handlers (#1191)

Co-authored-by: wangxiaoya.2000 <wangxiaoya.2000@bytedance.com>
This commit is contained in:
Xiaoya Wang
2026-01-28 15:26:28 +08:00
committed by GitHub
parent 5558ddf468
commit d11c4a1f81
4 changed files with 4 additions and 4 deletions

View File

@@ -123,7 +123,7 @@ export async function executePostToolUseHooks(
if (result.exitCode === 0 && result.stdout) {
try {
const output = JSON.parse(result.stdout) as PostToolUseOutput
const output = JSON.parse(result.stdout || "{}") as PostToolUseOutput
if (output.decision === "block") {
return {
block: true,

View File

@@ -73,7 +73,7 @@ export async function executePreCompactHooks(
if (result.stdout) {
try {
const output = JSON.parse(result.stdout) as PreCompactOutput
const output = JSON.parse(result.stdout || "{}") as PreCompactOutput
if (output.hookSpecificOutput?.additionalContext) {
collectedContext.push(...output.hookSpecificOutput.additionalContext)

View File

@@ -117,7 +117,7 @@ export async function executePreToolUseHooks(
if (result.stdout) {
try {
const output = JSON.parse(result.stdout) as PreToolUseOutput
const output = JSON.parse(result.stdout || "{}") as PreToolUseOutput
// Handle deprecated decision/reason fields (Claude Code backward compat)
let decision: PermissionDecision | undefined

View File

@@ -93,7 +93,7 @@ export async function executeStopHooks(
if (result.stdout) {
try {
const output = JSON.parse(result.stdout) as StopOutput
const output = JSON.parse(result.stdout || "{}") as StopOutput
if (output.stop_hook_active !== undefined) {
stopHookActiveState.set(ctx.sessionId, output.stop_hook_active)
}