Skip to content

fix: actionable hints when a source file cannot be located#678

Open
cats2101 wants to merge 1 commit intocrytic:masterfrom
cats2101:fix/issue-255-unknown-file-recommendations
Open

fix: actionable hints when a source file cannot be located#678
cats2101 wants to merge 1 commit intocrytic:masterfrom
cats2101:fix/issue-255-unknown-file-recommendations

Conversation

@cats2101
Copy link
Copy Markdown

Closes #255.

When _verify_filename_existence fails to resolve a path, surface actionable suggestions instead of a single-line Unknown file: ...:

  • Always include an ls <path> hint to verify the path exists.
  • For paths that look like an npm/yarn dependency (@scope/... or a bare-name pkg/... import that isn't a typical Solidity project source dir), point users at npm install / yarn install in the working directory.

Before:

crytic_compile.platform.exceptions.InvalidCompilation: Unknown file: @openzeppelin/contracts/token/ERC20/ERC20.sol

After:

Unknown file: @openzeppelin/contracts/token/ERC20/ERC20.sol
  - Verify the path exists (e.g. `ls @openzeppelin/contracts/token/ERC20/ERC20.sol`).
  - If this is an npm/yarn dependency, install project dependencies first (e.g. `npm install` or `yarn install` in `/path/to/project`).

The npm hint is suppressed for absolute paths, paths starting with ./.., and common Solidity project source roots (contracts, src, lib, test, tests, script) so it doesn't add noise to non-npm setups (e.g. Foundry).

Test plan

  • pytest tests/test_naming.py — 14 new tests covering scoped/bare/project/relative/absolute paths and message contents.
  • ruff check crytic_compile/ clean.
  • ruff format --check clean.
  • ty check crytic_compile/ clean.

When `_verify_filename_existence` fails to resolve a path, surface
suggestions to verify the path with `ls` and (for paths that look like
`@scope/...` or bare-name package imports) to run `npm install`/`yarn
install`. The most common cause of `Unknown file: @openzeppelin/...`
errors is a missing/failed dependency install, so the resolver now
points users at that fix instead of a single-line dead end.

Closes crytic#255
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.

Add recommendations if there is a missing file

1 participant