Repository navigation
Conversation
cli_tract_math caught every TypeError raised while running an operation and reported it as "Wrong number of parameters for the operation", hiding genuine bugs inside operations. Catch only TractMathWrongArgumentsError, and print just its message (no traceback) since it is a usage error. Too many parameters used to surface as the TypeError of the operation call itself; the decorator now checks the arguments against the operation signature and raises TractMathWrongArgumentsError, so wrong parameter counts still give a usage error. Also write the "Error reading file" message to stderr: print(sys.stderr, ...) printed the stream object to stdout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 4, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
scripts/cli_tract_math.pycaught everyTypeErrorraised while running an operation and reported it as a usage error, so bugs inside operations looked like wrong command lines. Reproduction on master (NumPy 2.5.4), wheretract_bhattacharyya_coefficienthas an internalTypeError(fixed separately in #143):Also
print(sys.stderr, "Error reading file ", ...)printed<_io.TextIOWrapper name='<stderr>' ...> Error reading file ...to stdout instead of writing to stderr.The change
cli_tract_math.maincatches onlyTractMathWrongArgumentsError(already aTypeErrorsubclass) and reports just its message throughparser.error, without a traceback, since it is a usage error. Any other exception propagates with its normal traceback and message. The now unusedtracebackimport is removed.TypeErrorof the operation call itself (e.g.tract_math t.trk count extra out.txt→count() takes 2 positional arguments but 3 were given). The decorator now checks the arguments withinspect.signature(func).bind(...)before calling the operation and raisesTractMathWrongArgumentsErroron a mismatch.print(..., file=sys.stderr)for the file reading error.After the change, the command above shows the
TypeErrortraceback from NumPy (exit status 1), whiletract_math t.trk tract_volume(missing parameter) prints onlytract_math: error: Wrong number of arguments for the operation...(exit status 2).Behaviour change: errors inside operations are no longer reported as "Wrong number of parameters"; usage errors no longer print a traceback.
Testing
tests/test_tract_math.py(pytest-console-scripts): missing and extra parameters give a usage error without a traceback; aTypeErrorraised inside an operation propagates out ofmain()instead of becoming a usage error; the file reading error goes to stderr. All four fail on master and pass here.python -m pytest -q -p no:cacheprovider tract_querier: 46 passed, 1 skipped (pre-existing unconditional skip intest_query_rewrite.py).Merge order
Touches lines next to #138 (
--forceinscripts/cli_tract_math.pyanddecorator.py, which raises its overwrite message throughTractMathWrongArgumentsError— with this PR that message is shown without a traceback) and #139 (decorator.py); textual conflicts only. Both #106 and #143 append tests totests/test_tract_math.py. Independent of #143 otherwise.Closes #106
🤖 Generated with Claude Code