Skip to content

Tidy the validators and fail loudly on non-instruction paths - #206

Merged
lorisleiva merged 3 commits into
mainfrom
11-27-tidy_validators
Nov 27, 2026
Merged

lorisleiva merged 3 commits into
mainfrom
11-27-tidy_validators

Conversation

@lorisleiva

Copy link
Copy Markdown
Member

This PR tidies codama-validators and codama-visitors-core before rc.0. Error items are built in one place, get_node_items is sorted by node kind with instructions and programs in their own helpers, every node kind with an identifier now reports an empty one, and the instruction input helpers fail on paths that don't end with an instruction instead of returning nothing.

PdaLinkNode::default()  // Before: Pointing to a missing PDA named ""
                        // After:  Pointing to a PDA with no identifier.
get_instruction_data_fields(&program_path, &linkables)?; // Before: vec![]  After: Err(UnexpectedNodeKind)

@lorisleiva lorisleiva added the no changelog This pull request does not warrant a release note label Nov 27, 2026
@lorisleiva

Copy link
Copy Markdown
Member Author

@trevor-cortex

@trevor-cortex trevor-cortex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Pre-rc.0 tidy of codama-validators and codama-visitors-core:

  • validation_error_item centralises the "error item with its CodamaError as cause" construction that was duplicated across contextual_value_items.rs and the visitor.
  • get_node_items is split: a generic get_missing_identifier_item driven by NodeRef::identifier() (with a names_another_node short-circuit so a link/value with an empty identifier is reported once rather than also as "missing X named """), then get_node_kind_items sorted alphabetically by kind with instructions and programs pulled out into get_instruction_items / get_program_items.
  • NodePath::expect_last::<T>() replaces the ad-hoc let Some(NodeRef::X(..)) = path.last() else … patterns, and get_instruction_data_fields / get_resolved_instruction_inputs now fail with UnexpectedNodeKind on non-instruction paths instead of returning an empty vec.

I read the whole visitor post-refactor and compared it branch by branch against the old match: no check was dropped, and the ordering of items for the kinds that previously combined identifier + kind-specific checks (DefinedType, Error, Program) is preserved. The one behavioural shift — "Instruction account has no identifier." now reported when the account itself is visited rather than from the parent instruction — is covered by reports_instruction_accounts_without_identifiers_against_the_account and is the better home for it anyway.

The error-propagation path checks out too: expect_last returns CodamaResult, and ? in get_resolved_instruction_inputs goes through the existing From<CodamaError> for ResolveInstructionInputsError, so the validator's Err(cause) => validation_error_item(cause, …) arm handles it without changes.

Things to watch

  • Change file. The diff has no .changeset/ entry, and this touches published crates with user-visible changes: get_instruction_data_fields now returns CodamaResult<Vec<_>>, get_resolved_instruction_inputs errs where it used to return Ok(vec![]), and a number of new/renamed validation messages. Per CONTRIBUTING.md the Knope Bot check will want one (or the no changelog label if you consider this folded into an existing rc.0 entry). Just flagging so it isn't a surprise at merge time.
  • The generic fallback arm in get_missing_identifier_item ("Node of kind [{}] has no identifier.") means any future node kind that grows an identifier field is reported automatically, just with a less polished message. That's a sensible safety net; worth remembering when new node kinds land so the hand-written message list stays in step.
  • AccountDataValueNode keeps its account identifier under account rather than identifier, so it isn't covered by the new helper and an empty one still surfaces through get_contextual_value_items as "missing account named """. Pre-existing and arguably correct since the field isn't called identifier, so no change requested — just noting the one asymmetry with the "every node kind with an identifier" framing.

Notes for other reviewers

Nothing needs extra scrutiny beyond the changeset question. The validation_items_visitor.rs diff looks big (+220/-189) but is almost entirely a reorder; reading the file at HEAD rather than the diff is the quicker way to verify it.

Comment on lines 10 to +11
/// recorded node. Ranges are not checked, so `256` is a value of a `u8`. Injected and constant values
/// are not concrete, so they are never values of a type here. Numbers accept integers and floats also
/// accept floats, a struct value must provide every field without a default value, and an enum value
/// are not concrete, so they are never values of a type here. Number types accept integer values and

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the rewording is clearer, but line 11 now runs to ~125 chars while the rest of the doc block is wrapped at 100. rustfmt won't rewrap comments, so this one needs a manual re-flow if you want it to match.

@trevor-cortex trevor-cortex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review

Three changes since my last pass, all good:

  • get_missing_identifier_item now special-cases AccountDataValueNode (its identifier lives under account), reporting "Account data value has no account." and short-circuiting via names_another_node so it isn't also reported as "missing account named """. That closes the one asymmetry I noted; the PR's "every node kind with an identifier" framing now holds without exception.
  • Two new tests cover the generic helper (reports_every_node_without_an_identifier on a PDA + variable seed) and the single-report behaviour for links/values naming another node, including the AccountDataValue case. Paths in the assertions match where the items are now emitted.
  • The is_value_node_of_type doc block is re-wrapped at 100 and reads better than the previous version ("Number types accept integer values and float types also accept float values").

Re-read the full visitor at HEAD once more: still a pure reorder plus the above, nothing dropped.

Still no change file in the diff — same note as before, the Knope check will want one or the no changelog label. Not blocking on it.

@lorisleiva
lorisleiva merged commit 93106a5 into main Nov 27, 2026
4 checks passed
@lorisleiva
lorisleiva deleted the 11-27-tidy_validators branch November 27, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This pull request does not warrant a release note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants