fix: accept namespaced TII param refs#51
Conversation
📝 WalkthroughWalkthroughThe pull request adds backward compatibility for legacy core ChangesTIi JSON Legacy $ref Normalization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/tx/common.rs`:
- Around line 405-406: The assertion uses error.to_string() which only shows the
outermost anyhow context; change the check to inspect the full error chain
(e.g., use alternate formatting format!("{error:#}") or iterate error.chain()
and assert any chain element contains "invalid param type") so the assertion on
the variable `error` (obtained from result.expect_err) reliably finds the inner
cause; update the assertion around `let error = result.expect_err("unknown refs
should still fail");` to use one of these approaches.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| let error = result.expect_err("unknown refs should still fail"); | ||
| assert!(error.to_string().contains("invalid param type")); |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Does anyhow Error Display (to_string) include source/context chain or only the top-level message, and what does the alternate {:#} format print?
💡 Result:
When using the anyhow crate, the standard Display format (typically triggered by the {} format specifier or to_string) displays only the outermost error message or context [1][2][3]. It does not include the lower-level source or cause chain, behaving identically to the Display implementation of the underlying error type from which the anyhow::Error was constructed [1][3][4]. The alternate format specifier {:#} is used to print the error along with its full cause chain [5][3][4]. This format utilizes anyhow's built-in formatting logic to display the entire chain of underlying errors [6][5]. If you need to access or manually render the source chain without using the {:#} format, you can use the Error::chain method, which provides an iterator over the full sequence of source errors [3][4][7].
Citations:
- 1: https://github.com/dtolnay/anyhow/blob/master/src/lib.rs
- 2: https://docs.rs/anyhow/1.0.51/anyhow/struct.Error.html
- 3: https://docs.rs/anyhow/latest/anyhow/struct.Error.html
- 4: https://docs.rs/anyhow/latest/src/anyhow/lib.rs.html
- 5: https://docs.rs/anyhow/1.0.32/anyhow/struct.Error.html
- 6: https://docs.rs/anyhow/1.0.35/src/anyhow/fmt.rs.html
- 7: https://github.com/dtolnay/anyhow/blob/master/src/error.rs
Fix the error assertion to check anyhow’s full cause chain
anyhow’s to_string() / default {error} formatting prints only the outermost context message (e.g., "parsing tii file"), not the inner "invalid param type" from the source error chain. Use alternate formatting ({error:#}) or iterate error.chain().
🐛 Proposed fix
- let error = result.expect_err("unknown refs should still fail");
- assert!(error.to_string().contains("invalid param type"));
+ let error = result.expect_err("unknown refs should still fail");
+ assert!(
+ format!("{error:#}").contains("invalid param type"),
+ "unexpected error: {error:#}"
+ );📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let error = result.expect_err("unknown refs should still fail"); | |
| assert!(error.to_string().contains("invalid param type")); | |
| let error = result.expect_err("unknown refs should still fail"); | |
| assert!( | |
| format!("{error:#}").contains("invalid param type"), | |
| "unexpected error: {error:#}" | |
| ); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/tx/common.rs` around lines 405 - 406, The assertion uses
error.to_string() which only shows the outermost anyhow context; change the
check to inspect the full error chain (e.g., use alternate formatting
format!("{error:#}") or iterate error.chain() and assert any chain element
contains "invalid param type") so the assertion on the variable `error`
(obtained from result.expect_err) reliably finds the inner cause; update the
assertion around `let error = result.expect_err("unknown refs should still
fail");` to use one of these approaches.
Summary
Normalize namespaced TII schema refs before handing the JSON to tx3-sdk.
This makes
cshell tx invokeandcshell tx resolveaccept TIIs generated by currenttrix build, where parameter refs come as:https://tx3.land/specs/v1beta0/tii#/$defs/Byteshttps://tx3.land/specs/v1beta0/tii#/$defs/Addresshttps://tx3.land/specs/v1beta0/tii#/$defs/UtxoRefWhat changed
src/tx/common.rscore#...equivalentstx3_sdk::tii::Protocol::from_json(...)Tests
Validation
validated against a minimal repro where
cshell tx invokepreviously failed withinvalid param typeFixes #50
Summary by CodeRabbit
Release Notes