-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Support coloured messages in standard json #11507
Comments
We already have By the way, if we start colorizing standard JSON then I think that |
I'm not sure it is a good idea combining CLI options and standard json settings. |
@axic Do we actually need a setting inside Standard JSON? Description does not state that outright but I thought it was about colorizing JSON when it's displayed in the terminal. I.e. with But if it's supposed to work with solc-js too - do ANSI escape sequences embedded in strings inside JSON even make sense outside of the terminal? I see there are some JS libs for parsing them but if it's meant for JS tools, I think they would highly prefer some semantic markers that can be used to style them in a custom way rather than hard-coded colors. |
Can someone check how coloured strings would be displayed by e.g. remix or vs code? |
This is definitely not about colourising the JSON, but rather including colours in the
There are libraries which can turn ANSI escapes into HTML markup. I think Remix had something like that for some purposes, but I'm not 100% sure, @yann300? That is why this should be off by default, but tools can request it and process it.
They already have that by now using |
Looks like Hardhat wants to add error coloring so this could be useful to them: NomicFoundation/hardhat#680. I asked if ANSI escapes would work for them. BTW, I have created a separate issue for
I just checked to see how it's formatted and expected to see some markup in there but looks like it just includes the error type and a code snippet with a marker pointing out the error: "formattedMessage": "ParserError: Source \"util.sol\" not found: File outside of allowed directories.\n --> contract.sol:1:1:\n |\n1 | import \"./util.sol\";\n | ^^^^^^^^^^^^^^^^^^^^\n\n",
"message": "Source \"util.sol\" not found: File outside of allowed directories.", I don't think it's that's easy to style unless you start actually parsing the messages. |
Can we talk about this in the next meeting? I as i was doing the prior work, i have some questions (/concerns). |
Do you mean also for the existing case when printing to the CLI? I think that should still be guarded by
If the IDEs are printing these messages as-is to the user, I think that does make sense - at first though I was a little scared/confused, because I may have thought that the IDE would not do that, because we provide source location offsets and the IDE could just highlight in the source code. I think enabling that by default might not be good due to existing software not expecting this (?). Instead of providing the error message twice, I'd suggest to add a boolean WRT |
I had a short call with @cameel, also to clarify my concerns and whether I am understanding the mission right here. I wanted to summarize now at least some thoughts we came up with in the call:
|
There was also a question of whether colored |
@cameel It was a typo in my message, I meant that with |
@christianparpart this issue is solely about standard json, let's please leave the CLI out of the discussion 😅 |
GUI tools can use all the other fields we have in the message. If they want nice formatting and tooltips, they should just build it themselves and ignore |
@cameel this tool for example can parse ANSI sequences and craft a group of spans for HTML: https://www.npmjs.com/package/ansicolor |
I think I've seen this one (or something similar). I was just arguing that GUI tools might prefer a different markup but you are right that they can use other fields to construct the message. So I think ANSI sequences are fine if console tools would use them. And I think they would. For example Truffle just prints all messages without any coloring and some people are annoyed enough to write custom scripts to colorize the output: Colorizing truffle compile output. This seems like a waste since compiler already has this info. I guess Truffle could construct colored message from components but for whatever reason it does not (seems like there was no feature request for that though so maybe it's just that nobody thought to ask? :)). I guess if we provided these colored messages in Standard JSON, Truffle would start using them right away because it would require very little effort. |
I have submitted a feature request: trufflesuite/truffle#4305. By the way, I just noticed that |
Probably just a hiccup.
Also clarified on NomicFoundation/hardhat#680 that hardhat is not used outside of consoles, so using ANSI is fine. |
A concrete proposal (option 3) from above): |
@cameel I think it is not a good idea marking it |
Well, ok then, I'm taking it off. The implementation is going to be straightforward whatever we choose though so I thought it was appropriate. And if anyone wants to try before them, we can always say that it's still waiting for design discussion. |
Yes, this is one of those unfortunate issues where discussing it takes 10x-100x the time it takes to implement it 🙈 |
I like when things work in a "core functionality that can be used by anyone" + "the tool builds upon that functionality as anyone else". I'll clarify what I mean. The ideal thing, in my mind, would be for the standard json to work as a "source of truth", that is then used by the compiler CLI to generate its output in some opinionated way. That is, as much as possible, the compiler only relies on the JSON (or the equivalent internal data structure). One example would be:
I understand that this is not possible right now, since the I know this is a very disruptive proposal, and I should have participated before. Sorry about that! |
I don't think it does. It's formatted in a way suitable for the console (assumes fixed-width font and is just a single string with newlines) but currently it does not have any color info. Adding ANSI sequences to it what this issue proposes.
The metadata is already there. Here's an example what you get from Standard JSON now (not all fields are always present); {
"errors":
[
...
{
"component": "general",
"errorCode": "4334",
"formattedMessage": "TypeError: Trying to override non-virtual function. Did you forget to add \"virtual\"?\n --> C.sol:2:5:\n |\n2 | function f() public {}\n | ^^^^^^^^^^^^^^^^^^^^^^\nNote: Overriding function is here:\n --> C.sol:6:5:\n |\n6 | function f() internal\n | ^ (Relevant source part starts here and spans across multiple lines).\n\n",
"message": "Trying to override non-virtual function. Did you forget to add \"virtual\"?",
"secondarySourceLocations":
[
{
"end": 102,
"file": "C.sol",
"message": "Overriding function is here:",
"start": 65
}
],
"severity": "error",
"sourceLocation":
{
"end": 39,
"file": "C.sol",
"start": 17
},
"type": "TypeError"
},
...
],
"sources": {}
} So what you're proposing is already possible. Everything needed to reconstruct the message is already there. The code snippets are not included but they can be easily extracted from source present in Standard JSON input based on the provided locations. The goal of this issue, however, is to give tools an alternative to this. Currently most of them ignore these components and just use |
Also note that we had these fields from the very beginning (and is part of the documentation), but no single tool decided to use any of those and just sticked to |
Oh, sorry, I completely misunderstood the issue. I see what you mean now! I'll think about this a little more. |
This is a hard question. If I'm understanding correctly, there are three options here:
I don't know which option is better. I think that if ANSI colors are added, we might just disable them because we save the JSON input/output to disk, and having colors there feels wrong. (I'm not 100% sure though, but this is my first guess)
To be honest, I didn't know about this 😬 And now I kind of want to generate our own formatted error messages. But at the same time, yes, it is extra work and I have no idea when we'll have the bandwidth to do it. |
That's a good point against an option that modifies |
@alcuadrado mentioned that having a new First, this would avoid the need of having a new flag in the input, which is problematic for verification because it affects the metadata (it would suck if your verification fails because you had a different colors config when the contract was deployed). Second, having a different field means that it's easier to support all versions of solc; otherwise, we should know that after some version the If we have this field, then the part of the code that handles showing the messages can have a simple logic that works for all versions: if (error.ansiColoredMessage) {
console.log(error.ansiColoredMessage)
} else {
console.log(colorize(error.formattedMessage)
} |
The main options according to this:
|
In dapp we currently just dump the output from I would be happy to see full colorized output included in the output json, and would definitely make use of it in dapp, especially if it included e.g. syntax highlighting for the solidity snippets in the output. I don't have a strong preference regarding interface, either a switch in the input settings, or a new field in the output are fine by me, but as @fvictorio mentions a new field will probably make for a pretty clean impementation. |
This issue has been marked as stale due to inactivity for the last 90 days. |
Hi everyone! This issue has been automatically closed due to inactivity. |
When we made the coloured output default (aka the new error message formatter), we did not enable it for standard json, only the CLI.
In the standard json we currently have all the components (
message
,errorCode
,sourceLocation
, ...) and singleformattedMessage
field which has an output matching the CLI.We have a couple of options:
coloredFormattedMessage
The option to enable/disable it would need to be part of the settings in the input.
The text was updated successfully, but these errors were encountered: