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: improve error messages #48

Closed
wants to merge 1 commit into from

Conversation

itegulov
Copy link
Contributor

Fixes #29

Copy link
Contributor

@miraclx miraclx left a comment

Choose a reason for hiding this comment

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

I'm taking a different approach of checking if the near-sdk dependency expects the __abi-generate and __abi-embed features. Instead of discriminating by any source specifier.

.unwrap_or(false)
{
anyhow::bail!("Unable to generate ABI: NEAR SDK \"abi\" feature is not enabled")
.and_then(|deps| deps.get("near-sdk"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't catch

  • near-sdk = { version = "..", features = ["abi"] }
  • near = { package = "near-sdk", version = ".." }

and outright fail for near-sdk = { git = ".." }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

near-sdk = { version = "..", features = ["abi"] }

What do you mean? This is absolutely being caught. We have multiple existing tests covering this and similar scenarios.

near = { package = "near-sdk", version = ".." }

This, most likely, is never (or at least not in the foreseeable future) going to be supported. The problem lies in near-sdk itself which expects the crate to be called near_sdk. See https://github.com/near/cargo-near/blob/main/integration-tests/tests/cargo/mod.rs#L137

and outright fail for near-sdk = { git = ".." }

No, it won't. You can only specify a git dependency in a table which is handled in a different branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean? This is absolutely being caught. We have multiple existing tests covering this and similar scenarios.

It's actually not. From the current logic, when the SDK dep is a table, it skips version checking altogether. And only checks for the abi feature.

No, it won't. You can only specify a git dependency in a table which is handled in a different branch.

Same situation.

Since the abi feature flag is no longer required to generate ABI, when this check gets removed, many false negatives would scale through this pretty easily.

And when the dep is a table with version, one could specify "4.0" and it won't report any error until it hits the first cargo metadata which reports a verbose error:

[dependencies]
near-sdk = { version = "4", features = ["abi"] }
error: Error invoking `cargo metadata`. Your `Cargo.toml` file is likely malformed

Caused by:
    `cargo metadata` exited with an error: error: failed to select a version for `near-sdk`.
        ... required by package `adder v0.1.0 (/Users/miraclx/git/near/near-sdk-rs/examples/adder)`
    versions that meet the requirements `^4` (locked to 4.0.0) are: 4.0.0
    
    the package `adder` depends on `near-sdk`, with features: `abi` but `near-sdk` does not have these features.
    
    
    failed to select a version for `near-sdk` which could resolve this conflict

This, most likely, is never (or at least not in the foreseeable future) going to be supported. The problem lies in near-sdk itself which expects the crate to be called near_sdk. See https://github.com/near/cargo-near/blob/main/integration-tests/tests/cargo/mod.rs#L137

fair point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, waiting for your PR then

Copy link
Contributor

Choose a reason for hiding this comment

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

#49

@itegulov
Copy link
Contributor Author

itegulov commented Aug 31, 2022

I'm taking a different approach of checking if the near-sdk dependency expects the __abi-generate and __abi-embed features. Instead of discriminating by any source specifier.

I mean there is nothing stopping us from combining the two approaches. Directly checking for versions might lead to better contextual errors (depends on how you implement your approach, obviously I haven't seen it yet), and then you could check for __abi-generate for cases where version is not available (git, local path etc).

@itegulov itegulov closed this Aug 31, 2022
@itegulov itegulov deleted the daniyar/negative-tests branch August 31, 2022 09:27
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.

2 participants