Skip to content

fix: actionable hint when source map falls outside cached source#680

Open
cats2101 wants to merge 1 commit intocrytic:masterfrom
cats2101:fix/issue-265-stale-cache-error-hint
Open

fix: actionable hint when source map falls outside cached source#680
cats2101 wants to merge 1 commit intocrytic:masterfrom
cats2101:fix/issue-265-stale-cache-error-hint

Conversation

@cats2101
Copy link
Copy Markdown

get_line_from_offset and get_global_offset_from_line could raise a bare KeyError when the cached source map fell outside the file on disk. This usually happens when the build artifacts are out of sync with the working tree (e.g. files renamed/edited after a previous compile), but the surfaced traceback gave no clue about the cause or remedy.

Wrap both lookups in a try/except KeyError that re-raises InvalidCompilation with a stale-artifact message, including a platform-specific clean command:

Platform Hint
Foundry forge clean
Hardhat npx hardhat clean
Truffle npx truffle compile --all
Brownie brownie compile --all
Dapp dapp clean
Buidler npx buidler clean
Embark embark reset
Waffle rm -rf build
Etherlime etherlime compile ...

Unknown platforms fall back to a generic "remove the build directory and recompile" message.

Closes #265

Test plan

  • pytest tests/test_stale_cache_hint.py — 5 new tests cover the helper, both wrapped methods, and known/unknown/missing platform fallbacks
  • ruff check crytic_compile/ tests/test_stale_cache_hint.py
  • ruff format --check
  • ty check crytic_compile/

`get_line_from_offset` and `get_global_offset_from_line` could raise a bare
`KeyError` when the cached source map fell outside the file on disk, which
typically happens when build artifacts get out of sync with the source tree.
Wrap the lookup in a try/except that re-raises `InvalidCompilation` with a
platform-specific clean recommendation (e.g. `forge clean`, `npx hardhat
clean`).

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

Improve error reporting on cache clean

1 participant