Skip to content
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

Update test "compiling standard JSON (invalid JSON)" to be nlohmann::json compatible #729

Merged
merged 1 commit into from May 6, 2024

Conversation

aarlt
Copy link
Member

@aarlt aarlt commented Feb 26, 2024

The test is trying to parse {invalid. Doing so with nlohmann::json will create the following error:

{
  "errors": [
    {
      "component": "general",
      "formattedMessage": "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - invalid literal; last read: '{i'; expected string literal",
      "message": "[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - invalid literal; last read: '{i'; expected string literal",
      "severity": "error",
      "type": "JSONError"
    }
  ]
}

This PR updates the expected error message.

Copy link
Member

@cameel cameel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be merged after we update to nlohmann-json? Because right now the binary will still give you the old output.

test/compiler.ts Outdated
@@ -751,7 +751,7 @@ function runTests (solc, versionText) {
t.test('compiling standard JSON (invalid JSON)', function (st) {
const output = JSON.parse(solc.compile('{invalid'));
// TODO: change wrapper to output matching error
st.ok(expectError(output, 'JSONError', 'Line 1, Column 2\n Missing \'}\' or object member name') || expectError(output, 'JSONError', 'Invalid JSON supplied:'));
st.ok(expectError(output, 'JSONError', '[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - invalid literal; last read: \'{i\'; expected string literal'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that currently this already allows two different messages. Probably because the message already changed in the past and some compiler versions will generate one and some the other. Those older messages can still happen since solc-js is meant to support all compiler versions, so you should add the new message as another alternative instead of replacing the old ones.

test/compiler.ts Outdated
@@ -751,7 +751,7 @@ function runTests (solc, versionText) {
t.test('compiling standard JSON (invalid JSON)', function (st) {
const output = JSON.parse(solc.compile('{invalid'));
// TODO: change wrapper to output matching error
st.ok(expectError(output, 'JSONError', 'Line 1, Column 2\n Missing \'}\' or object member name') || expectError(output, 'JSONError', 'Invalid JSON supplied:'));
st.ok(expectError(output, 'JSONError', '[json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - invalid literal; last read: \'{i\'; expected string literal'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way, I'm not sure if exposing the [json.exception.parse_error.101] part to the user is a great idea. We already have our own error type here and this is an implementation detail showing through. I'd filter it out in solc if that's no too complicated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know. I don't see any value in removing such information.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed this on the chat, so I'll just repost the relevant bits here:

It would be better not to have this if it's easy to get rid of. It's something that would be more relevant in a debug message, but this is not an internal error, it's a normal parsing error meant for the end user. Those should be formatted without extra cruft, with things like error type being properly accounted for via the fields we already have.

I mean, I was assuming it must be pretty simple to do. Like, instead of printing exception.what() print just the field containing the message.
But actually not sure now if that message is even exposed. https://json.nlohmann.me/api/basic_json/parse_error/ does not mention it.
Also, apparently this is less of an internal detail than I expected. The numeric codes are even officially documented: https://json.nlohmann.me/home/exceptions/

So maybe it's ok after all. Just the way it's formatted makes it look like something internal. The class name there is just redundant. The error codes seem to be unique and showing that would have been enough.

Also it bothers me a bit how this introduces a new layer of error codes that's not connected to our own error codes.
I don't think the compiler should really be leaking internal implementation like that in its errors.
On the other hand doing it properly might not be easy, so I'm not saying to jump into it. We probably don't have time for that. Just still, I don't like it :)

@aarlt aarlt force-pushed the fix_for_nlohmann_json branch 2 times, most recently from 82e37f3 to 8ee2703 Compare February 26, 2024 16:15
@coveralls
Copy link

coveralls commented Feb 26, 2024

Coverage Status

coverage: 84.537%. remained the same
when pulling 840f3b1 on fix_for_nlohmann_json
into 6c2d135 on master.

@aarlt aarlt force-pushed the fix_for_nlohmann_json branch 2 times, most recently from a4257f3 to 5613f43 Compare February 26, 2024 17:20
@cameel
Copy link
Member

cameel commented Feb 26, 2024

Is this meant to be merged after we update to nlohmann-json?

I mean, I'm wondering why you need this in solc-js already if solc on develop does not produce this output yet and shouldn't be causing any problems here.

@aarlt aarlt force-pushed the fix_for_nlohmann_json branch 3 times, most recently from 8fc7d24 to 009c607 Compare February 27, 2024 10:49
@aarlt aarlt marked this pull request as draft February 27, 2024 11:41
@aarlt aarlt self-assigned this Mar 5, 2024
@aarlt aarlt marked this pull request as ready for review March 5, 2024 13:26
@aarlt aarlt requested a review from cameel March 5, 2024 13:26
@aarlt aarlt merged commit 4ab32d8 into master May 6, 2024
17 checks passed
@aarlt aarlt deleted the fix_for_nlohmann_json branch May 6, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants