ApeWorX / py-solc-x

Python wrapper and version management tool for the solc Solidity compiler.
https://solcx.readthedocs.io/
MIT License
141 stars 49 forks source link

Add more structured data in `SolcError` #91

Closed Pet3ris closed 4 years ago

Pet3ris commented 4 years ago

Overview

I'm trying to extract line ranges and individual errors from Solidity error messages but it seems like SolcError collapses all that information into one string. Would it perhaps be useful to preserve the compiler_output["errors"] variable for this purpose?

Specification

One easy way would be to add a new entry for compiler errors into SolcError like so:

raise SolcError(
  command,
  proc.returncode,
  json.dumps(input_data),
  stdoutdata,
  stderrdata,
  compiler_output["errors"],  # <-- new variable
  message=error_message,
)

This would still allow people to use existing arguments to the exception without change.

iamdefinitelyahuman commented 4 years ago

Yeah, this seems like a great idea.

The data sent to stdout is always JSON formatted, so something like exc.error_data = json.loads(stdoutdata)["errors"] should work to allow easier access.

iamdefinitelyahuman commented 4 years ago

Will be included in the upcoming v1.0 release.