Skip to content

fix(dependency_resolver): map JSON parse errors to InvalidInput variant (#209)#245

Closed
SAY-5 wants to merge 2 commits intoTrueNine:devfrom
SAY-5:fix/dependency-resolver-invalid-input-209
Closed

fix(dependency_resolver): map JSON parse errors to InvalidInput variant (#209)#245
SAY-5 wants to merge 2 commits intoTrueNine:devfrom
SAY-5:fix/dependency-resolver-invalid-input-209

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented Apr 29, 2026

Closes #209.

topological_sort(input_json) previously rolled JSON parse failures into DependencyResolverError::MissingDependency with node_name: "invalid input: …" and an empty missing_dependency. Downstream consumers matching on the serialised kind field — the discriminator declared by #[serde(tag = "kind", rename_all = "camelCase")] — would treat parse failures as graph problems.

Add an InvalidInput { message: String } variant and route the serde error there. The kind payload now reads invalidInput, which the JS-side wrapper (and any future consumer) can branch on cleanly without string-sniffing the node_name.

Tests

  • New topological_sort_maps_invalid_json_to_invalid_input: asserts the new variant fires for invalid JSON and the serialised payload has kind: "invalidInput".
  • New topological_sort_handles_well_formed_input: sanity check that the happy path still produces a sorted list.
  • Existing detects_missing_dependency / detects_simple_cycle / etc. unchanged.

Test plan

  • cargo test --manifest-path sdk/Cargo.toml --lib policy::dependency_resolver — 13/13 pass

TrueNine and others added 2 commits April 25, 2026 10:10
Fix two CI failures from previous merge
Closes TrueNine#209.

`topological_sort(input_json)` previously rolled JSON parse failures
into `DependencyResolverError::MissingDependency` with
`node_name: "invalid input: …"` and an empty `missing_dependency`.
Downstream consumers matching on the serialised `kind` field — the
discriminator declared by `#[serde(tag = "kind", rename_all =
"camelCase")]` — would treat parse failures as graph problems
instead of input-shape problems.

Add an `InvalidInput { message: String }` variant and route the
serde error there. The `kind` payload now reads `invalidInput`,
which the JS-side wrapper (and any future consumer) can branch
on cleanly without string-sniffing the `node_name`.

The two existing variants and their behaviour are unchanged.

Tests in `dependency_resolver.rs` gain
`topological_sort_maps_invalid_json_to_invalid_input` (asserts the
new variant + `kind: "invalidInput"` payload) and
`topological_sort_handles_well_formed_input` (sanity that the happy
path still produces a sorted list). 13/13 module tests pass.
@SAY-5 SAY-5 requested a review from TrueNine as a code owner April 29, 2026 22:36
@TrueNine TrueNine changed the base branch from main to dev April 30, 2026 08:08
@TrueNine
Copy link
Copy Markdown
Owner

Merged into dev via cherry-pick. The PR base was changed from main to dev, which caused conflicts because dev had diverged significantly. All commits have been cherry-picked onto dev and pushed. Thanks for the contributions!

@TrueNine TrueNine closed this Apr 30, 2026
@TrueNine
Copy link
Copy Markdown
Owner

Thank you for the contribution! All commits have been cherry-picked and merged into the dev branch. 🙏

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.

[Dependency Resolver] JSON 解析错误映射到错误的 error variant

2 participants