Break up RemoteRunner.call_process and repair its error messages - #745
Open
appleweiping wants to merge 1 commit into
Open
Break up RemoteRunner.call_process and repair its error messages#745appleweiping wants to merge 1 commit into
appleweiping wants to merge 1 commit into
Conversation
`RemoteRunner.call_process` reports C901 at complexity 14 against the `--max-complexity=10` the lint job uses, which is nlpie#399. Most of that came from two error-translation blocks nested inside the happy path. Extracts `_rpc_error_message`, `_handle_rpc_error` and `_process_remotely` as methods, and `_group_created_indices` as a module-level function, leaving `call_process` as the request/response flow. The grouping loop also becomes a `setdefault`, replacing a try/except KeyError. No behaviour changes from the restructuring itself: the suite reports the same 242 passed and 10 skipped before and after. Restructuring the block surfaced two error paths that never worked: The UNAVAILABLE advice was written as msg = f'Failed to connect to "{name}", check ' "that the service is running and the address is " "correctly configured." The second and third lines are expression statements, not continuations, so they were discarded and operators saw a message ending mid-sentence at "check ". They are now part of the string. The closed-channel case tested `e == ValueError('Cannot invoke RPC on closed channel!')`. `ValueError` does not define `__eq__`, so that comparison is always False and the intended "Channel was closed when trying to process." message could never be produced. It now compares the type and `str(e)`. Adds tests covering both messages, the absence of a message for other status codes, and the index grouping. These pin the corrected behaviour; the previous behaviour could not be asserted against, since the logic was inline. Lint on `python` with the CI flags goes from 4 findings to 3. The two remaining, both in `deployment.py`, are pre-existing and untouched. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Author
|
Validated the latest head aa12cc5 locally.
This covers the refactored RemoteRunner call, the repaired error messages, and the grouping helper. Please review the updated branch. |
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.
Fixes #399.
RemoteRunner.call_processreportsC901 ... is too complex (14)against the--max-complexity=10the lint job uses. Most of that came from two error-translation blocks nested inside the happy path.This extracts
_rpc_error_message,_handle_rpc_errorand_process_remotelyas methods, plus_group_created_indicesas a module-level function, leavingcall_processas the request/response flow. The grouping loop becomes asetdefaultinstead of atry/except KeyError.The restructuring itself changes no behaviour:
pytest python/testsreports the same 242 passed, 10 skipped before and after.Two error paths that never worked
Pulling the block apart made both visible.
The UNAVAILABLE advice was being discarded. It was written as:
The second and third lines are expression statements, not continuations of the assignment, so they evaluate and are thrown away. Operators saw a message that stopped mid-sentence at
check. They are now part of the string.The closed-channel message could never be produced. The check was
e == ValueError('Cannot invoke RPC on closed channel!').ValueErrordefines no__eq__, so this is alwaysFalse:It now compares the type and
str(e).Testing
Adds
python/tests/processing/test_runners.pycovering both messages, the absence of a specific message for other status codes, and the index grouping — 5 tests, suite goes to 247 passed / 10 skipped.These pin the corrected behaviour rather than reproducing the old one: the message construction was inline inside
call_process, so there was nothing to assert against before the extraction. The evidence that the old paths were dead is the language behaviour shown above.Running the lint job's flags over
pythongoes from 4 findings to 3. The two that remain are pre-existingE501/E303indeployment.py, untouched here.🤖 Generated with Claude Code