Skip to content

fix: improve error handling in similarity tools - #3066

Open
lxcxjxhx wants to merge 1 commit into
crytic:masterfrom
lxcxjxhx:fix/similarity-tools-error-handling
Open

fix: improve error handling in similarity tools#3066
lxcxjxhx wants to merge 1 commit into
crytic:masterfrom
lxcxjxhx:fix/similarity-tools-error-handling

Conversation

@lxcxjxhx

Copy link
Copy Markdown

Description

This PR fixes several error handling issues in the similarity tools (slither-simil) that could cause crashes or misleading error messages.

Problems Fixed

1. Path Concatenation Bug (encode.py:96)

  • Issue: Incorrect path construction using string concatenation: x + '/'.join(y) + '/' + f
  • Fix: Use os.path.join(x, f) for proper cross-platform path handling
  • Impact: Prevents path errors on Windows and ensures consistent path separators

2. Unsafe Attribute Access (train.py:52, test.py:50, plot.py:82)

  • Issue: Direct access to �rgs.filename in exception handlers could raise AttributeError
  • Fix: Use getattr(args, 'filename', '') for safe attribute access
  • Impact: Prevents secondary crashes when reporting errors

3. Potential KeyError (encode.py:228)

  • Issue: Direct dictionary access kwargs['solc'] could raise KeyError
  • Fix: Use kwargs.get('solc', 'unknown') for safe access
  • Impact: Provides graceful error reporting when solc parameter is missing

Testing

  • Verified syntax correctness
  • No functional behavior changes for valid inputs
  • Error messages now more robust for edge cases

Note

These are defensive programming improvements that enhance tool stability. All changes are backward compatible.


I apologize for any inconvenience caused by previous submissions. This is a focused fix for error handling in similarity tools.

Local environment limitations: Dependency constraints (missing wn module), relying on CI/CD automated testing.

cc @crytic maintainers

- Fix path concatenation bug in encode.py using os.path.join
- Use safe attribute access for args.filename in error messages
- Use kwargs.get() to avoid KeyError for missing solc parameter
@lxcxjxhx
lxcxjxhx requested a review from smonicas as a code owner July 29, 2026 01:27
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants