fix: actionable hint when source map falls outside cached source#680
Open
cats2101 wants to merge 1 commit intocrytic:masterfrom
Open
fix: actionable hint when source map falls outside cached source#680cats2101 wants to merge 1 commit intocrytic:masterfrom
cats2101 wants to merge 1 commit intocrytic:masterfrom
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
get_line_from_offsetandget_global_offset_from_linecould raise a bareKeyErrorwhen 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 KeyErrorthat re-raisesInvalidCompilationwith a stale-artifact message, including a platform-specific clean command:forge cleannpx hardhat cleannpx truffle compile --allbrownie compile --alldapp cleannpx buidler cleanembark resetrm -rf buildetherlime 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 fallbacksruff check crytic_compile/ tests/test_stale_cache_hint.pyruff format --checkty check crytic_compile/