-
Notifications
You must be signed in to change notification settings - Fork 0
Fix double-quoted error messages in KeyError handlers #6
Copy link
Copy link
Open
Description
Summary
When a tool call fails due to an unknown circuit_id, the error field in the JSON response contains extra quotes:
{"success": false, "error": "\"No circuit found with id 'abc'\"}Expected:
{"success": false, "error": "No circuit found with id 'abc'"}Root Cause
All KeyError handlers across the tool modules use str(exc) to serialize the exception:
except KeyError as exc:
return json.dumps({"success": False, "error": str(exc)})str(KeyError("message")) returns the repr of its first argument, which adds surrounding quotes to strings. Using exc.args[0] instead returns the raw message.
Affected Files
src/stim_mcp_server/tools/circuit_management.pysrc/stim_mcp_server/tools/simulation.pysrc/stim_mcp_server/tools/analysis.pysrc/stim_mcp_server/tools/visualization.py
Fix
Replace str(exc) with exc.args[0] in every except KeyError handler, e.g.:
except KeyError as exc:
return json.dumps({"success": False, "error": exc.args[0]})Notes
- Pre-existing issue (present in original
server.pybefore modularization) - Non-blocking: existing tests pass because the circuit_id substring is still present inside the quoted string
- Found during QA of
feature/generate-circuit-modularize
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels