fix(blueprint): add error handling for JSON.parse in state, config, and migration loaders#638
Open
pjt222 wants to merge 1 commit intoNVIDIA:mainfrom
Open
fix(blueprint): add error handling for JSON.parse in state, config, and migration loaders#638pjt222 wants to merge 1 commit intoNVIDIA:mainfrom
pjt222 wants to merge 1 commit intoNVIDIA:mainfrom
Conversation
…nd migration loaders Three sites used bare JSON.parse(readFileSync(...)) that crash on corrupted files. The same codebase already has robust error handling in loadConfigDocument() (migration-state.ts:143-153) — this applies the same patterns to the remaining unprotected call sites. Fixes: - loadState() (state.ts): try-catch returning blankState() — state is ephemeral machine-written data, silent recovery matches the existing null-on-missing pattern and allows self-healing on next saveState() call. - loadOnboardConfig() (config.ts): try-catch returning null — triggers re-onboarding, matches the null-on-missing pattern. - readSnapshotManifest() (migration-state.ts): structural validation (not-null, is-object, not-array) following the loadConfigDocument() pattern — throws on corruption because migration cannot proceed safely with corrupt manifest data. Related to NVIDIA#553 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe PR adds error-handling safeguards for JSON file operations across three modules (state, migration-state, and config). Each loader function now gracefully handles malformed or invalid JSON by returning fallback values instead of throwing exceptions, and validation logic ensures parsed data matches expected types. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
JSON.parsecalls inloadState(),loadOnboardConfig(), andreadSnapshotManifest()loadConfigDocument()inmigration-state.ts(lines 143-153)loadState()recovers silently (returns blank state) — state is machine-written ephemeral data, and the nextsaveState()call self-heals the fileloadOnboardConfig()recovers silently (returns null) — allows re-onboardingreadSnapshotManifest()throws a descriptive error with structural validation (matchingloadConfigDocumentpattern) — migration cannot proceed safely with corrupt dataRelated to #553
Test plan
cd nemoclaw && npx vitest run— 79 tests pass (4 new)npx tsc --noEmit— no type errorsstate.test.tsconfig.test.tsmigration-state.test.tsCo-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com