Skip to content

fix: add validation to importChain to prevent crashes, fixes #12#45

Merged
Dancode-188 merged 1 commit intomainfrom
fix/issue-12-import-chain-validation
Dec 27, 2025
Merged

fix: add validation to importChain to prevent crashes, fixes #12#45
Dancode-188 merged 1 commit intomainfrom
fix/issue-12-import-chain-validation

Conversation

@Dancode-188
Copy link
Copy Markdown
Owner

Fixes #12

Problem

importChain had zero validation. Invalid JSON would crash with JSON.parse() errors, and missing or malformed data would cause TypeErrors when accessing undefined properties.

Changes

Added validation before processing:

  • Wrapped JSON.parse() in try-catch
  • Validate parsed data is an object
  • Validate name field exists and is a string
  • Validate steps is an array

Now throws descriptive errors instead of cryptic crashes.

importChain would crash when given invalid JSON or when required fields
were missing. No try-catch on JSON.parse() and no validation before
accessing chain.steps would cause TypeErrors.

Added validation for:
- JSON parsing errors (wrapped in try-catch)
- Required fields: name must be a string
- steps must be an array (not undefined/null)

Now throws clear errors instead of cryptic TypeErrors when import fails.
@Dancode-188
Copy link
Copy Markdown
Owner Author

Clean validation logic. Error messages are descriptive. Build passes.

@Dancode-188 Dancode-188 merged commit 4069cc3 into main Dec 27, 2025
2 checks passed
@Dancode-188 Dancode-188 deleted the fix/issue-12-import-chain-validation branch December 28, 2025 06:14
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.

[Bug]: ChainService importChain fails when JSON missing steps

1 participant