starknet-foundry icon indicating copy to clipboard operation
starknet-foundry copied to clipboard

Make sure valid json is always returned

Open THenry14 opened this issue 1 year ago • 0 comments

It seems that a few things (printing warnings, scarb) are breaking our --json format, rendering it unusable for any external tools.

An example of that is (https://github.com/foundry-rs/starknet-foundry/pull/1704#discussion_r1490544931):

I agree, ideally warnings should be printed to stderr, to allow users to filter them. Let's do this (all of them use the same function, so this should be rather easy).

I believe, however, that the issue is may not be isolated to these particular cases. Now this should be verified with scarb team, but it seems some of the commands (like declare) may also break json, because scarb returns multiple objects (only last json is from sncast):

{"status":"compiling","message":"lib(map) map v0.1.0 (/Users/wojciech/git-repos/starkware/starknet-foundry/crates/sncast/tests/data/contracts/map/Scarb.toml)"}
{"type":"warn","message":"Sierra, textual Sierra and CASM lib targets have been disabled, Scarb will not produce anything"}
{"status":"compiling","message":"starknet-contract(map) map v0.1.0 (/Users/wojciech/git-repos/starkware/starknet-foundry/crates/sncast/tests/data/contracts/map/Scarb.toml)"}
{"status":"finished","message":"release target(s) in 1 second"}
{"class_hash":"0x43a9554442216b8c5b551c6cae6357ce69fd9838e9bf40fb27b455cac5ba9f4","transaction_hash":"0x21d5dfe1854c294b371632ea9f2435017d0373f8adc6d4194c88a16c87eb0c","command":"declare"}

we should take a closer look at this under different issue. We must also decide what to do with our --wait function (under the same issue), as it also uses println to inform about tx hash, so it can also potentially break json.

We must come up with a proper solution, that would allow users to actually use --json flag reliably.

THenry14 avatar Feb 16 '24 14:02 THenry14