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

InvalidCompilation errors are verbose and sometimes obscure the underlying issue #2011

Open
0xalpharush opened this issue Jun 29, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@0xalpharush
Copy link
Contributor

I think we need to rethink this because it causes stuff like parser errors, wrong solc version, or any error in crytic-compile to be shown twice. It's very verbose and obfuscates the issue (e.g. it looks like it's a slither or crytic-compile error when in fact it may have to do with a missing comma in Solidity)

slither/slither/__main__.py

Lines 873 to 877 in 3d4f934

except Exception: # pylint: disable=broad-except
output_error = traceback.format_exc()
traceback.print_exc()
logging.error(f"Error in {args.filename}") # pylint: disable=logging-fstring-interpolation
logging.error(output_error)

For example

Traceback (most recent call last):
  File "/Users/alpharush/env/lib/python3.9/site-packages/slither/__main__.py", line 814, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/alpharush/env/lib/python3.9/site-packages/slither/__main__.py", line 91, in process_all
    compilations = compile_all(target, **vars(args))
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 646, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 131, in __init__
    self._compile(**kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 553, in _compile
    self._platform.compile(self, **kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 149, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 278, in _get_targets_json
    return _run_solc(
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 495, in _run_solc
    compiler="solc", version=get_version(solc, env), optimized=is_optimized(solc_arguments)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 393, in get_version
    raise InvalidCompilation(
crytic_compile.platform.exceptions.InvalidCompilation: 
Solidity version not found:
STDOUT:

STDERR:
Traceback (most recent call last):
  File "/Users/alpharush/env/bin/solc", line 8, in <module>
    sys.exit(solc())
  File "/Users/alpharush/env/lib/python3.9/site-packages/solc_select/__main__.py", line 80, in solc
    res = current_version()
  File "/Users/alpharush/env/lib/python3.9/site-packages/solc_select/solc_select.py", line 62, in current_version
    raise argparse.ArgumentTypeError(
argparse.ArgumentTypeError: No solc version set. Run `solc-select use VERSION` or set SOLC_VERSION environment variable.

ERROR:root:Error in test3.sol
ERROR:root:Traceback (most recent call last):
  File "/Users/alpharush/env/lib/python3.9/site-packages/slither/__main__.py", line 814, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/alpharush/env/lib/python3.9/site-packages/slither/__main__.py", line 91, in process_all
    compilations = compile_all(target, **vars(args))
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 646, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 131, in __init__
    self._compile(**kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 553, in _compile
    self._platform.compile(self, **kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 149, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 278, in _get_targets_json
    return _run_solc(
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 495, in _run_solc
    compiler="solc", version=get_version(solc, env), optimized=is_optimized(solc_arguments)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 393, in get_version
    raise InvalidCompilation(
crytic_compile.platform.exceptions.InvalidCompilation: 
Solidity version not found:
STDOUT:

STDERR:
Traceback (most recent call last):
  File "/Users/alpharush/env/bin/solc", line 8, in <module>
    sys.exit(solc())
  File "/Users/alpharush/env/lib/python3.9/site-packages/solc_select/__main__.py", line 80, in solc
    res = current_version()
  File "/Users/alpharush/env/lib/python3.9/site-packages/solc_select/solc_select.py", line 62, in current_version
    raise argparse.ArgumentTypeError(
argparse.ArgumentTypeError: No solc version set. Run `solc-select use VERSION` or set SOLC_VERSION environment variable.


@0xalpharush 0xalpharush added the bug Something isn't working label Jun 29, 2023
@0xalpharush
Copy link
Contributor Author

Another example

'solc --version' running
'solc test3.sol --combined-json abi,ast,bin,bin-runtime,srcmap,srcmap-runtime,userdoc,devdoc,hashes --allow-paths .,/Users/alpharush' running
Compilation warnings/errors on test3.sol:
Error: Source file requires different compiler version (current compiler is 0.8.20+commit.a1b79de6.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
 --> test3.sol:1:1:
  |
1 | pragma solidity >=0.4.0 <0.7.0;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


Traceback (most recent call last):
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 575, in _run_solc
    ret: Dict = json.loads(stdout)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/alpharush/env/lib/python3.9/site-packages/slither/__main__.py", line 814, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/alpharush/env/lib/python3.9/site-packages/slither/__main__.py", line 91, in process_all
    compilations = compile_all(target, **vars(args))
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 646, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 131, in __init__
    self._compile(**kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 553, in _compile
    self._platform.compile(self, **kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 149, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 278, in _get_targets_json
    return _run_solc(
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 579, in _run_solc
    raise InvalidCompilation(f"Invalid solc compilation {stderr}")
crytic_compile.platform.exceptions.InvalidCompilation: Invalid solc compilation Error: Source file requires different compiler version (current compiler is 0.8.20+commit.a1b79de6.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
 --> test3.sol:1:1:
  |
1 | pragma solidity >=0.4.0 <0.7.0;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


ERROR:root:Error in test3.sol
ERROR:root:Traceback (most recent call last):
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 575, in _run_solc
    ret: Dict = json.loads(stdout)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/alpharush/env/lib/python3.9/site-packages/slither/__main__.py", line 814, in main_impl
    ) = process_all(filename, args, detector_classes, printer_classes)
  File "/Users/alpharush/env/lib/python3.9/site-packages/slither/__main__.py", line 91, in process_all
    compilations = compile_all(target, **vars(args))
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 646, in compile_all
    compilations.append(CryticCompile(target, **kwargs))
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 131, in __init__
    self._compile(**kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/crytic_compile.py", line 553, in _compile
    self._platform.compile(self, **kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 149, in compile
    targets_json = _get_targets_json(compilation_unit, self._target, **kwargs)
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 278, in _get_targets_json
    return _run_solc(
  File "/Users/alpharush/env/lib/python3.9/site-packages/crytic_compile/platform/solc.py", line 579, in _run_solc
    raise InvalidCompilation(f"Invalid solc compilation {stderr}")
crytic_compile.platform.exceptions.InvalidCompilation: Invalid solc compilation Error: Source file requires different compiler version (current compiler is 0.8.20+commit.a1b79de6.Darwin.appleclang) - note that nightly builds are considered to be strictly less than the released version
 --> test3.sol:1:1:
  |
1 | pragma solidity >=0.4.0 <0.7.0;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@0xalpharush
Copy link
Contributor Author

0xalpharush commented Aug 23, 2024

The PR removed too much info and impaired users debugging and reporting issues
#2525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant