Hardhat error HH602: Artifacts not found after restoring backup without cache
0 reputation · 11 Feb 2022, 18:29 UTC
0 reputation · 11 Feb 2022, 18:29 UTC
When a Hardhat project backup restores only the artifacts directory while omitting the cache folder, the compiler may throw error HH602 ("Artifacts not found") even though the source contracts are present. The goal is to confirm that the recovered contract data can be verified without manual intervention. The uncertainty lies in whether Hardhat should automatically detect missing artifacts, clear the cache, and trigger a full rebuild, or whether it should merely warn the user and leave the rebuild decision to them. This behavior is not defined in the current documentation and varies with the use of plugins that affect incremental compilation.
Considering Hardhat v2.12+ where HH602 is documented, what should the compiler’s response be when it encounters missing artifacts after a partial backup restore? Should it force a clean compilation automatically, or should it rely on the user to decide whether to rebuild?
35775 reputation · 11 Feb 2022, 21:31 UTC
Hardhat v2.12+ does not automatically trigger a clean compilation when it encounters HH602 “Artifacts not found” after restoring only the artifacts directory. The compiler errors on the missing artifact and leaves the rebuild decision to the user; an explicit hardhat compile (or a task that invokes compilation) is required to regenerate the artifacts and restore consistency.
cache directory holds incremental compilation metadata. Without it, the next explicit hardhat compile performs a full rebuild, but compilation is not started automatically on an artifact‑lookup failure.artifacts without cache leaves the build state inconsistent, so the error can appear even when source contracts are unchanged.When the backup restores only the artifacts folder, the incremental metadata that tells Hardhat which source files correspond to which artifacts is missing. Before any compile task runs, Hardhat attempts to resolve an artifact (e.g., during a test, deploy script, or hardhat run) and finds the file missing, raising HH602. Because the compiler does not treat a missing artifact as a signal to rebuild, the user must intervene.
artifacts and cache directories to guarantee a clean state:rm -rf artifacts cache\nnpx hardhat compilecache/solidity-build-info contains build‑info files matching the newly generated artifacts.npx hardhat test) and confirm the error disappears.Behavior can vary with plugins that maintain their own artifact references (e.g., hardhat-deploy, ethers plugin). In such cases HH602 may surface at different points, but the underlying requirement—manual rebuild—remains the same. Hardhat versions beyond v2.12 may adjust error handling; the described behavior holds for the documented v2.12+ range.
One diagnostic that could change the recommendation: identify whether HH602 is thrown during an explicit hardhat compile call or only during artifact access in another task (tests, scripts, hardhat run). If the error occurs during compile itself, please share the exact compile output; otherwise the clean‑rebuild steps above are sufficient.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.