Skip to content

solc artifact: error on a component the artifact does not carry - #290

Merged
thedavidmeister merged 1 commit into
mainfrom
2026-08-25-issue-231
Aug 26, 2026
Merged

solc artifact: error on a component the artifact does not carry#290
thedavidmeister merged 1 commit into
mainfrom
2026-08-25-issue-231

Conversation

@thedavidmeister

Copy link
Copy Markdown
Contributor

Closes #231

The defect

extract_artifact_component_json indexed the parsed artifact with
json["abi"] / json["bytecode"] / json["deployedBytecode"]. Indexing a
serde_json::Value with a key it does not have yields Value::Null, so the
function returned Ok(Null) and the CLI printed null with exit 0:

$ printf '{"bytecode":{"object":"0x60"},"deployedBytecode":{"object":"0x60"}}' > artifact-no-abi.json
$ rain-metadata solc artifact --component abi --input-path artifact-no-abi.json
null
$ echo $?
0

Indistinguishable from an artifact whose component legitimately serialises as
null, and anything piping the output into ABI tooling gets null rather than
a failure.

The fix

Took the issue's first option: an absent component is an error, so the exit
code is nonzero and nothing reaches stdout.

The lookup is now json.get(key), which separates the two cases indexing
conflated - None for a key the artifact does not carry (also for an artifact
that is not a JSON object at all), Some(Null) for a key present and
explicitly null. Absent errors; explicit null still returns Value::Null, so
the distinction the issue names is preserved rather than collapsed the other
way.

The three key names moved into ArtifactComponent::artifact_key, so the lookup
and the error message name one string and cannot drift apart; the
per-component match is exhaustive, so a component variant added later is a
compile error there rather than a silent null.

The function's doc comment said it "does not perform any checks on the returned
[Value] such as if it is null or not" - that was the accurate description of
the defect, and it now states the absent-vs-explicit-null contract instead.

solc artifact is the only caller. SolidityAbiMeta::from_artifact does its
own ["abi"] indexing but already errors, because deserialising Null into
SolidityAbiMeta fails; it is untouched.

Relation to #266 (issue #181)

Same CLI output surface, adjacent but disjoint: #266 is cli/schema - it made
schema ls list exactly the metas schema show can produce, by routing both
through one exhaustive KnownMeta -> Option<RootSchema> map. This is
cli/solc plus solc/mod.rs; no file, function or test overlaps, so the two
merge in either order.

The shape is deliberately the same one #266 established: a defect where a
lookup silently produced a non-answer is fixed by an exhaustive match feeding
an Option, with the caller turning None into the error. #266's None
becomes "Unsupported for {} meta"; this one's becomes artifact has no "abi" component. Both make an added enum variant a compile error in one place.

QA

  • Discriminating tests: test_dispatch_solc_artifact_missing_component (new,
    crates/cli/tests/cli_dispatch.rs) - the issue's own repro: asserts nonzero
    exit, empty stdout, the missing key named on stderr, that -o writes no file
    on the failing path, and that an explicitly null component still succeeds and
    prints null. test_missing_component_errors,
    test_missing_component_errors_beside_present_siblings,
    test_explicit_null_component_is_returned, test_non_object_artifact_errors,
    test_artifact_key_per_component (all new, crates/cli/src/solc/mod.rs).
    Each fails on base, verified by restoring the pre-fix body
    (Ok(json[component.artifact_key()].clone())) and re-running: the four
    absent-key/non-object assertions fail with Ok(Null) where an Err is
    expected. test_missing_component_returns_null, which pinned the old
    behaviour, is replaced by test_missing_component_errors rather than deleted
    • the same behaviour asserted the other way.
  • Mutations applied (each restored and re-verified green after):
    solc/mod.rs:36-38 restore the pre-fix indexing body -> KILLED by
    test_missing_component_errors,
    test_missing_component_errors_beside_present_siblings,
    test_non_object_artifact_errors,
    test_dispatch_solc_artifact_missing_component.
    solc/mod.rs:37 insert .filter(|v| !v.is_null()) before .cloned(), i.e.
    treat explicit null as absent -> KILLED by
    test_explicit_null_component_is_returned and
    test_dispatch_solc_artifact_missing_component (this is the mutant proving
    the fix did not just move the conflation).
    solc/mod.rs:17 Abi => "abi" -> "bytecode" -> KILLED by 5 lib tests and
    both dispatch tests.
    solc/mod.rs:18 Bytecode => "bytecode" -> "abi" -> KILLED by 4 lib tests
    and test_dispatch_solc_artifact.
    solc/mod.rs:19 DeployedBytecode => "deployedBytecode" -> "bytecode" ->
    KILLED by 3 lib tests and test_dispatch_solc_artifact.
    solc/mod.rs:38 error text -> missing {} -> KILLED by
    test_missing_component_errors and
    test_dispatch_solc_artifact_missing_component. (Scoped to the function body;
    applied file-wide it rewrites the lib test's expectation in lockstep and only
    the dispatch test kills it, which is why the message is pinned from the other
    test target too.)
    No surviving mutant.
  • Oracle: the issue's stated intent - a component the artifact does not carry
    must not be reported as a value, and must be distinguishable from one that
    legitimately serialises as null. The absent/explicit-null split is derived
    from the issue's own wording, not from the new code: the fix has to make those
    two distinguishable, not error on both. The CLI test asserts process exit
    status and stderr text, observable without reference to the implementation,
    and the key names are checked against what solc writes into an artifact
    (abi, bytecode, deployedBytecode), not against the match being tested.
  • Category check: the issue asks for one thing with two named remedies -
    (a) error with nonzero exit when the component key is absent, or (b) keep the
    passthrough and document/flag it at the CLI layer. Covered by (a); (b) is the
    alternative the issue offers, not an additional requirement, and (a) is the
    one that fixes the piping hazard the issue describes rather than documenting
    it. Nothing else in the issue.

Verification

Green locally: cargo test -p rain-metadata --lib solc (7 passed),
cargo test -p rain-metadata --test cli_dispatch --test cli (5 + 9 passed),
cargo clippy -p rain-metadata --all-targets clean, cargo fmt --all --check
clean. The full suite was not run locally.

Behaviour change

extract_artifact_component_json and ArtifactComponent are re-exported from
the crate root (pub use solc::*), so this is a library-visible change: a call
that previously got Ok(Value::Null) for a missing key now gets
Err(Error::InvalidInput(..)), rendered as
invalid input: artifact has no "abi" component. That is the point of the
issue. No new Error variant, so the public error enum's match surface is
unchanged. solc artifact is the only in-repo caller.

🤖 Generated with Claude Code

extract_artifact_component_json indexed the parsed artifact and returned
Value::Null for an absent key, so `solc artifact -c abi` printed `null`
and exited 0 on an artifact with no abi.

Look the key up instead, so an absent key is an error naming it and a key
present as explicit null still returns null. The three key names move into
ArtifactComponent::artifact_key so the lookup and the error name one string.

Closes #231

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 42 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: f7bff057-1995-490e-bc75-59a374c52580

📥 Commits

Reviewing files that changed from the base of the PR and between c5a1cb0 and dc25ead.

📒 Files selected for processing (2)
  • crates/cli/src/solc/mod.rs
  • crates/cli/tests/cli_dispatch.rs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@thedavidmeister
thedavidmeister merged commit 0512d52 into main Aug 26, 2026
11 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai assess this PR size classification for the totality of the PR with the following criterias and report it in your comment:

S/M/L PR Classification Guidelines:

This guide helps classify merged pull requests by effort and complexity rather than just line count. The goal is to assess the difficulty and scope of changes after they have been completed.

Small (S)

Characteristics:

  • Simple bug fixes, typos, or minor refactoring
  • Single-purpose changes affecting 1-2 files
  • Documentation updates
  • Configuration tweaks
  • Changes that require minimal context to review

Review Effort: Would have taken 5-10 minutes

Examples:

  • Fix typo in variable name
  • Update README with new instructions
  • Adjust configuration values
  • Simple one-line bug fixes
  • Import statement cleanup

Medium (M)

Characteristics:

  • Feature additions or enhancements
  • Refactoring that touches multiple files but maintains existing behavior
  • Breaking changes with backward compatibility
  • Changes requiring some domain knowledge to review

Review Effort: Would have taken 15-30 minutes

Examples:

  • Add new feature or component
  • Refactor common utility functions
  • Update dependencies with minor breaking changes
  • Add new component with tests
  • Performance optimizations
  • More complex bug fixes

Large (L)

Characteristics:

  • Major feature implementations
  • Breaking changes or API redesigns
  • Complex refactoring across multiple modules
  • New architectural patterns or significant design changes
  • Changes requiring deep context and multiple review rounds

Review Effort: Would have taken 45+ minutes

Examples:

  • Complete new feature with frontend/backend changes
  • Protocol upgrades or breaking changes
  • Major architectural refactoring
  • Framework or technology upgrades

Additional Factors to Consider

When deciding between sizes, also consider:

  • Test coverage impact: More comprehensive test changes lean toward larger classification
  • Risk level: Changes to critical systems bump up a size category
  • Team familiarity: Novel patterns or technologies increase complexity

Notes:

  • the assessment must be for the totality of the PR, that means comparing the base branch to the last commit of the PR
  • the assessment output must be exactly one of: S, M or L (single-line comment) in format of: SIZE={S/M/L}
  • do not include any additional text, only the size classification
  • your assessment comment must not include tips or additional sections
  • do NOT tag me or anyone else on your comment

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.

CLI solc artifact prints null with exit 0 when the requested component is missing from the artifact

1 participant