Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved error reporting for near macro #1301

Merged
merged 2 commits into from
Feb 7, 2025
Merged

Conversation

akorchyn
Copy link
Collaborator

@akorchyn akorchyn commented Feb 6, 2025

This PR intends to clarify errors for the user. This PR doesn't introduce new errors, but rather clarifies them. As older compilation errors are hard to understand

  • Added a new error message if the near(contract_state) was used two times in the same crate.
  • Added a new error message if there is a nested near macro

Messages before:

Contract state repetion:

error: symbol `__near_abi_contract_source_metadata` is already defined
 --> compilation_tests/double_contract_state_error.rs:9:5
  |
9 |     #[near(contract_state)]

Near macro nesting:

error: multiple `borsh` attributes not allowed
  --> compilation_tests/nested_near_error.rs:6:1
   |
6  | / #[near(contract_metadata(
7  | |     version = "39f2d2646f2f60e18ab53337501370dc02a5661c",
8  | |     link = "https://github.com/near-examples/nft-tutorial",
9  | |     standard(standard = "nep171", version = "1.0.0"),
10 | |     standard(standard = "nep177", version = "2.0.0"),
11 | | ))]
   | |___^
   |
   = note: this error originates in the attribute macro `near` (in Nightly builds, run with -Z macro-backtrace for more info)

Copy link
Collaborator

@dj8yfo dj8yfo left a comment

Choose a reason for hiding this comment

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

@race-of-sloths score 8

@race-of-sloths
Copy link

race-of-sloths commented Feb 6, 2025

@akorchyn Thank you for your contribution! Your pull request is now a part of the Race of Sloths!
Are you going to win race-of-sloths this month? If so, you should speed up! Run, Sloth, run!

Shows inviting banner with latest news.

Shows profile picture for the author of the PR

Current status: executed
Reviewer Score
@dj8yfo 8

Your contribution is much appreciated with a final score of 8!
You have received 88 (80 base + 10% lifetime bonus) Sloth points for this contribution

@dj8yfo received 25 Sloth Points for reviewing and scoring this pull request.

What is the Race of Sloths

Race of Sloths is a friendly competition where you can participate in challenges and compete with other open-source contributors within your normal workflow

For contributors:

  • Tag @race-of-sloths inside your pull requests
  • Wait for the maintainer to review and score your pull request
  • Check out your position in the Leaderboard
  • Keep weekly and monthly streaks to reach higher positions
  • Boast your contributions with a dynamic picture of your Profile

For maintainers:

  • Score pull requests that participate in the Race of Sloths and receive a reward
  • Engage contributors with fair scoring and fast responses so they keep their streaks
  • Promote the Race to the point where the Race starts promoting you
  • Grow the community of your contributors

Feel free to check our website for additional details!

Bot commands
  • For contributors
    • Include a PR: @race-of-sloths include to enter the Race with your PR
  • For maintainers:
    • Invite contributor @race-of-sloths invite to invite the contributor to participate in a race or include it, if it's already a runner.
    • Assign points: @race-of-sloths score [1/2/3/5/8/13] to award points based on your assessment.
    • Reject this PR: @race-of-sloths exclude to send this PR back to the drawing board.
    • Exclude repo: @race-of-sloths pause to stop bot activity in this repo until @race-of-sloths unpause command is called

Copy link
Collaborator

@dj8yfo dj8yfo left a comment

Choose a reason for hiding this comment

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

TODO: test this patch with neardevhub-contract (repo, a few contracts therein)

neardevhub-contract should be a goto place to check if unsure if stuff's gonna break unexpectedly

Copy link

codecov bot commented Feb 6, 2025

Codecov Report

Attention: Patch coverage is 43.24324% with 21 lines in your changes missing coverage. Please review.

Project coverage is 80.06%. Comparing base (5ddafdc) to head (2bd96ad).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
near-sdk-macros/src/lib.rs 43.24% 21 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1301      +/-   ##
==========================================
- Coverage   80.24%   80.06%   -0.18%     
==========================================
  Files         104      104              
  Lines       14819    14856      +37     
==========================================
+ Hits        11892    11895       +3     
- Misses       2927     2961      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@akorchyn
Copy link
Collaborator Author

akorchyn commented Feb 6, 2025

image

code changes: https://github.com/akorchyn/neardevhub-contract/compare/main...akorchyn:neardevhub-contract:test-near-macro-errors?expand=1

@akorchyn akorchyn requested a review from dj8yfo February 6, 2025 15:38
@dj8yfo
Copy link
Collaborator

dj8yfo commented Feb 6, 2025

image

code changes: https://github.com/akorchyn/neardevhub-contract/compare/main...akorchyn:neardevhub-contract:test-near-macro-errors?expand=1

TODO: + a devhub-community-factory there in, patching near-sdk in all dependent contracts, though it must've been defined once in workspace

@akorchyn
Copy link
Collaborator Author

akorchyn commented Feb 6, 2025

image
image
image

Tested with discussions, community, community factory. All of them compiles.

UPD: the contracts are using near

@dj8yfo
Copy link
Collaborator

dj8yfo commented Feb 6, 2025

@akorchyn i cannot come up with any logical reason, how any of those could be affected, but now i feel calmer

@akorchyn
Copy link
Collaborator Author

akorchyn commented Feb 6, 2025

That was a good call, I completely agree

@dj8yfo
Copy link
Collaborator

dj8yfo commented Feb 6, 2025

TODO: @akorchyn can you run cargo test --workspace with this patch there too? on 1.81 toolchain, otherwise it likely won't work.

dj8yfo
dj8yfo previously approved these changes Feb 6, 2025
near-sdk-macros/src/lib.rs Outdated Show resolved Hide resolved
near-sdk-macros/src/lib.rs Outdated Show resolved Hide resolved
near-sdk-macros/src/lib.rs Show resolved Hide resolved
@dj8yfo dj8yfo dismissed their stale review February 6, 2025 18:33

there's one more aspect i want to check, which might be a breaking change; wanted to check it first

@dj8yfo dj8yfo self-requested a review February 6, 2025 19:23
Copy link
Collaborator

@dj8yfo dj8yfo left a comment

Choose a reason for hiding this comment

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

nope, that was allright

@dj8yfo
Copy link
Collaborator

dj8yfo commented Feb 6, 2025

Judging from how this was layed outtg link, looks like it wouldn't conflict with this pr

@akorchyn
Copy link
Collaborator Author

akorchyn commented Feb 7, 2025

image
It passes :)

@akorchyn akorchyn enabled auto-merge (squash) February 7, 2025 12:08
@akorchyn akorchyn merged commit 200d037 into master Feb 7, 2025
38 of 39 checks passed
@akorchyn akorchyn deleted the near-macro-errors branch February 7, 2025 12:14
@frol frol mentioned this pull request Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Shipped 🚀
Development

Successfully merging this pull request may close these issues.

3 participants