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

Raise exception when compiler version is not supported by solc-select #234

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions crytic_compile/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

LOGGER = logging.getLogger("CryticCompile")


class UnsupportedSolcVersion(Exception):
"""The requested solc version cannot be installed by solc-select."""


# pylint: disable=too-few-public-methods
class CompilerVersion:
"""
Expand Down Expand Up @@ -37,16 +42,21 @@ def look_for_installed_version(self) -> None:
This function queries solc-select to see if the current compiler version is installed
And if its not it will install it

Returns:

Raises:
UnsupportedSolcVersion: If the version requested cannot be automatically installed by solc-select.
"""

# pylint: disable=import-outside-toplevel
try:
from solc_select import solc_select

if self.version not in solc_select.installed_versions():
if (
self.version not in solc_select.installed_versions()
and self.version in solc_select.get_available_versions()
Copy link
Member

Choose a reason for hiding this comment

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

get_available_versions makes an url query. install_artifacts calls also get_available_versions, so here we end up making two time the same URL query, which is not great.

Maybe we can rather update solc-select to return boolean in install_artifacts to indicate success?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like install_artifacts returns True on success as of this PR to solc-select and, as before, throws on failure. Given the throw on failure, we could try/catch the install_artifacts call instead of using an if statement to save the extra url query.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that was an oversight. We should return false crytic/solc-select#143. I also opened issues to cache these requests crytic/solc-select#145.

):
solc_select.install_artifacts([self.version])
else:
raise UnsupportedSolcVersion(f"{self.version} is not supported by solc-select")

except ImportError:
LOGGER.info(
Expand Down