We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
forge script --json
Forge
forge 0.2.0 (ec3f9bd 2023-09-19T13:44:30.009787069Z)
forge script
Linux
Errors thrown in scripts when parsing JSON config are swallowed:
import {console2} from "forge-std/console2.sol"; import {Script} from "forge-std/Script.sol"; import {stdJson} from "forge-std/StdJson.sol"; contract MyScript is Script { function run() { string memory config = "{\"nst\":\"0x7Fc85446b851eBD2ED047978E8A46fEb9b87e67f\",\"vestTot\":2000000000000000000000000,\"vestBgn\":1688158800,\"vestTau\":31536000,\"vestEta\":0}"; ConfigReader reader = new ConfigReader(config); console2.log("config:", config); try reader.readAddress(".ngt") returns (address) { } catch (bytes memory e) { console2.logBytes(e); // Displays the error } console2.log("ngt:", config.readAddress(".ngt")); // Error is swallowed }
ConfigReader above is just a wrapper on top of stdJson so it can work with try...catch blocks:
ConfigReader
stdJson
try...catch
contract ConfigReader { string internal config; constructor(string memory _config) { config = _config; } function readAddress(string memory key) external returns (address) { return stdJson.readAddress(config, key); } function readUint(string memory key) external returns (uint256) { return stdJson.readUint(config, key); } }
If I run the script above:
forge script --json MyScript -vvvvv
I get:
{ "logs": [ "config: {\"nst\":\"0x7Fc85446b851eBD2ED047978E8A46fEb9b87e67f\",\"vestTot\":2000000000000000000000000,\"vestBgn\":1688158800,\"vestTau\":31536000,\"vestEta\":0}", "0x0bc445030000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002d4e6f206d61746368696e672076616c7565206f7220617272617920666f756e6420666f72206b6579202e6e677400000000000000000000000000000000000000" ], "gas_used": 885313, "returns": {} }
Only the error caught is shown.
When running the same script without --json, I get a proper error message:
--json
Error: No matching value or array found for key .ngt
If there is logging whatsoever (i.e.: simply try to read the missing JSON key), I simply get a pretty much empty response:
{ "logs": [], "gas_used": 874524, "returns": {} }
which is not very useful.
I understand that --json is supposed to output a valid JSON, but I can see 2 possible ways of doing this:
stderr
The text was updated successfully, but these errors were encountered:
A possible fix was added in: #7071
@amusingaxl would be great if you could check if this fixes you issue
Sorry, something went wrong.
Marking as resolved by #7071
resolved
Feel free to re-open if you are still facing issues around this @amusingaxl
No branches or pull requests
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (ec3f9bd 2023-09-19T13:44:30.009787069Z)
What command(s) is the bug in?
forge script
Operating System
Linux
Describe the bug
Errors thrown in scripts when parsing JSON config are swallowed:
ConfigReader
above is just a wrapper on top ofstdJson
so it can work withtry...catch
blocks:If I run the script above:
I get:
Only the error caught is shown.
When running the same script without
--json
, I get a proper error message:If there is logging whatsoever (i.e.: simply try to read the missing JSON key), I simply get a pretty much empty response:
which is not very useful.
I understand that
--json
is supposed to output a valid JSON, but I can see 2 possible ways of doing this:stderr
to display the error in a non-JSON format.The text was updated successfully, but these errors were encountered: