Skip to content

fix: wrap validateRuntimeState in try-catch to prevent pipeline crash#132

Open
pzysvip99999 wants to merge 1 commit intoNarcooo:masterfrom
pzysvip99999:fix/validator-try-catch
Open

fix: wrap validateRuntimeState in try-catch to prevent pipeline crash#132
pzysvip99999 wants to merge 1 commit intoNarcooo:masterfrom
pzysvip99999:fix/validator-try-catch

Conversation

@pzysvip99999
Copy link
Copy Markdown

Fix: prevent state validator crash from invalid JSON parse errors

Problem

When the LLM outputs JSON containing invalid characters (e.g. control chars like \x00, malformed escape sequences), the Zod schema parse throws a non-ZodError exception. Since validateRuntimeState() was not wrapped in a try-catch, this uncaught exception crashed the entire write pipeline with:

State validation failed for chapter N: Error: State validator returned invalid JSON

Fix

Wrap the entire validateRuntimeState function body in a try-catch. Any uncaught errors (JSON.parse failures, schema.parse throws from non-Zod sources) are now returned as a validation issue with code validator_crash rather than crashing the process.

Testing

# Before: write next crashes with 'State validator returned invalid JSON'
# After: validator returns [{ code: 'validator_crash', message: '...' }] and pipeline continues

…ors from crashing the pipeline

The state validator was throwing an uncaught exception when the LLM output
contains invalid JSON characters (e.g. control chars, unescaped sequences),
causing the entire write pipeline to crash with 'State validator returned
invalid JSON'. This wraps the entire function in a try-catch so that any
such errors are returned as a validation issue rather than crashing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant