Improve error messages for missing JsonSchema trait in ABI generation#387
Improve error messages for missing JsonSchema trait in ABI generation#387
Conversation
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
Co-authored-by: r-near <163825889+r-near@users.noreply.github.com>
|
@copilot the error message is nice, but couldn't we also be smart about this and support it in the same way borsh does? |
The automatic schema derivation like borsh does happens in the near-sdk macros during compilation, not in cargo-near. When users apply The issue here is that the user is using manual derives ( The enhanced error message in this PR is the most helpful approach cargo-near can provide - it clearly guides users to add For fully automatic support like borsh, that would need to be implemented in near-sdk itself to handle cases where users use manual derives. Would you like me to create an issue in the near-sdk-rs repo to discuss this enhancement? |
When custom types used in contract function signatures lack
JsonSchemaimplementation, ABI generation fails with an unhelpful compiler error that doesn't explain the fix.Changes
Enhanced error detection (
cargo-near-build/src/cargo_native/compile.rs)#[near(serializers = [json])]for near-sdk 5.0+JsonSchemaderive from schemarsAdded test (
integration-tests/tests/abi/json_schema.rs)test_schema_vec_of_custom_types()demonstrates correct usage ofVec<CustomType>Updated CHANGELOG
Example
Before:
After:
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
s3-us-west-1.amazonaws.com/home/REDACTED/work/cargo-near/cargo-near/target/debug/build/near-workspaces-a8b4a713a403149e/build-script-build /home/REDACTED/work/cargo-near/cargo-near/target/debug/build/near-workspaces-a8b4a713a403149e/build-script-build -I libgit2/deps/xdiff 64-REDACTED-linux-gnu/bin/gcc-ld/ld.lld 40df�� go-near/target/d-g ebug/build/libgi-gdwarf-4 l/include son c-rendered-ansi,-O0 h2-sys-e90d28c77-ffunction-sections /usr/libexec/gcc-fdata-sections sl-s�� t2-sys-bc666140e-g t2-sys-bc666140e-gdwarf-4 stable-x86_64-un-fno-omit-frame-pointer ude ude 163292.so stable-x86_64-un--log-level(dns block)/home/REDACTED/work/cargo-near/.codeql-scratch/dbs/rust/working/target/debug/build/near-workspaces-2094825312d8cd28/build-script-build /home/REDACTED/work/cargo-near/.codeql-scratch/dbs/rust/working/target/debug/build/near-workspaces-2094825312d8cd28/build-script-build --gdwarf-4 --64 --noexecstack -o /libdbus-sys-9c66e14519a1242e/out/include /tmp/ccXmTMob.s(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>ABI not generated when functions return a vector of objects or regular JSON</issue_title>
<issue_description>When running
cargo near build --embed-abias well ascargo near abion the following contract sources:https://github.com/archetype-org/attestation-registry/blob/main/src/lib.rs
I get the following error:
Similar code also fails due to the same reason:
https://github.com/NEAR-DevHub/neardevhub-contract
I believe this is because the abigen does not support the same types of schema traits as
borsh. Is this a limitation with the standard or will support be added in the future.</issue_description>
Comments on the Issue (you are @copilot in this section)
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.