fix: distinguish Blender addon errors from transport failures#228
fix: distinguish Blender addon errors from transport failures#228obselate wants to merge 1 commit into
Conversation
Python exceptions inside execute_blender_code surfaced as 'Communication error with Blender: Code execution error: <real exc>', implying a transport/socket failure when the socket was healthy and the addon had responded normally with an error status. Introduce BlenderCommandError for addon-reported errors and let it propagate through send_command's catch-all without re-wrapping (and without nulling the socket). execute_blender_code returns these as 'Blender Python error: <exc>' with the addon's duplicate prefix stripped. True transport failures still return 'Communication error'. All other tools inherit a cleaner error message as a side-effect (they already caught Exception generically).
Review Summary by QodoDistinguish Blender addon errors from transport failures
WalkthroughsDescription• Introduce BlenderCommandError exception to distinguish addon errors from transport failures • Addon-reported errors no longer wrapped as communication errors, socket preserved • execute_blender_code returns cleaner "Blender Python error" message without duplicate prefixes • Other tools inherit improved error messages through existing generic exception handlers Diagramflowchart LR
A["Addon responds with error status"] --> B["BlenderCommandError raised"]
B --> C["Re-raised without wrapping"]
C --> D["Socket preserved for reuse"]
E["execute_blender_code catches BlenderCommandError"] --> F["Returns 'Blender Python error'"]
G["True transport failure"] --> H["Caught as generic Exception"]
H --> I["Returns 'Communication error'"]
File Changes1. src/blender_mcp/server.py
|
📝 WalkthroughWalkthroughAdded a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Code Review by Qodo
1. Nested transport error messages
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/blender_mcp/server.py`:
- Around line 370-371: Replace the eager f-string logging and explicit str()
conversion with lazy logger formatting and use the !s conversion flag for the
returned string: change the logger call that currently uses
logger.error(f"Communication error executing code: {str(e)}") to use lazy
formatting like logger.error("Communication error executing code: %s", e) and
update the return value from return f"Communication error: {str(e)}" to return
f"Communication error: {e!s}" so the logger defers formatting and the return
uses the conversion flag instead of wrapping str().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Summary
When user Python raises inside
execute_blender_code, the server currently returns:The
Communication errorprefix implies a transport/socket failure, but the socket is healthy — it's a normal Python exception that round-tripped successfully through the addon. First-instinct response is to restart Blender / reconnect the MCP, which wastes triage time. The socket is also dropped unnecessarily by the catch-all, so every user-code error forces a reconnect on the next call.Fix
BlenderCommandErrorexception class for errors the addon reported via{"status": "error"}(socket healthy, addon responsive).BlenderConnection.send_commandraisesBlenderCommandErrorinstead of a genericException, and re-raises it through the catch-all without wrapping and without nullingself.sock.execute_blender_codecatchesBlenderCommandErrorspecifically and returnsBlender Python error: <exc>with the addon's duplicateCode execution error:prefix stripped. True transport failures still returnCommunication error: ....All other
@mcp.toolendpoints already have a genericexcept Exception as e:catcher and inherit a cleaner error message for free — no changes needed in their bodies.Before / after
Before (Python
NameErrorin executed code):After:
Before (socket dies mid-call):
After:
Test plan
uv pip install -e .), callexecute_blender_codewith code that raises (raise ValueError('x')) → response starts withBlender Python error:.Communication error:.execute_blender_codewith failing code, then immediately call a succeeding command — should reuse the same socket (no reconnect log).get_object_infoon a missing object,set_texturewith a bad slot) return the addon's error message without aCommunication error with Blender:prefix.Filed from downstream tracking as issue
Blender-ntrin a workspace accumulating blender-mcp fixes; happy to follow up with the rest of the queue (version exposure, visual-verification tooling, material-slot helpers) if there's interest.Summary by CodeRabbit