Skip to content

Commit 072c585

Browse files
dguidoclaude
andcommitted
fix: handle missing current version gracefully in versions command
- Fix crash when running 'solc-select versions' with no version set - Add try/catch for ArgumentTypeError in versions command - Strip whitespace from version string when reading from file - Resolves issue where command would fail instead of listing versions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f37a428 commit 072c585

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

solc_select/__main__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,13 @@ def solc_select() -> None:
6969
versions_installed = installed_versions()
7070
if versions_installed:
7171
(current_ver, source) = (None, None)
72-
res = current_version()
73-
if res:
74-
(current_ver, source) = res
72+
try:
73+
res = current_version()
74+
if res:
75+
(current_ver, source) = res
76+
except argparse.ArgumentTypeError:
77+
# No version is currently set, that's ok
78+
res = None
7579
for version in sort_versions(versions_installed):
7680
if res and version == current_ver:
7781
print(f"{version} (current, set by {source})")

solc_select/solc_select.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def current_version() -> (str, str):
8181
source = source_path.as_posix()
8282
if Path.is_file(source_path):
8383
with open(source_path, encoding="utf-8") as f:
84-
version = f.read()
84+
version = f.read().strip()
8585
else:
8686
raise argparse.ArgumentTypeError(
8787
"No solc version set. Run `solc-select use VERSION` or set SOLC_VERSION environment variable."

0 commit comments

Comments
 (0)