-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
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
index out of bounds: the len is 0 but the index is 0 #4630
Labels
T-bug
Type: bug
Comments
I was unable to reproduce this
with
|
but there's a panic if the object is empty, so I'll fix that:
|
@mattsse Yes that's right sorry the issue happens when the property is not found. Thanks! |
Wanted to confirm this, here is an alternative repro: // SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {stdJson} from "forge-std/StdJson.sol";
import "forge-std/Test.sol";
contract JsonTest is Test {
function testJson() public {
string memory json = '{"name":"John","age":30,"city":"New York"}';
// works
assertEq(stdJson.readString(json, ".name"), "John");
// crashes with
// The application panicked (crashed).
// Message: index out of bounds: the len is 0 but the index is 0
// Location: evm/src/executor/inspector/cheatcodes/ext.rs:424
stdJson.readString(json, ".darkest_secret");
}
} Running a git bisect points at f8e700 being the first bad commit where this started happening |
should be fixed via #4631 |
25 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (6570a4c 2023-03-23T00:04:51.797681082Z)
What command(s) is the bug in?
forge script
Operating System
Linux
Describe the bug
When using
vm.parseJsonUint
on a json where the key is not found I'm getting:It happened to me having a JSON like:
Used to work in previous versions:
With latest I get this error:
Then I saw that
jq
syntax is required now, so when I do (it starts with a dot.
now):Is when I get the crash.
In my use case, I check if
prop1
exists in some objects in the JSON, but when it is not found is when it crashes.The text was updated successfully, but these errors were encountered: