Repository navigation
Fail undo/redo with an explanation instead of AttributeError - #53
floraschouw wants to merge 1 commit into
Conversation
Both tools called image.undo() / image.redo(), which do not exist on GIMP
3.x, so every call raised:
'Image' object has no attribute 'undo'
There is no fix that makes them work. GIMP 3.2 exposes undo *stack*
management only -- undo_group_start/end, undo_freeze/thaw,
undo_disable/enable -- and none of the 1034 procedures in the PDB performs
an undo or a redo. GIMP has no action-dispatch procedures either, so a
plug-in cannot reach Edit > Undo. Undo remains a GUI-only operation.
So the tools now fail with a message naming the limitation and pointing at
Ctrl+Z / Ctrl+Y, instead of raising AttributeError.
The server-side docstrings matter as much as the handlers here: they are
what an MCP client reads when deciding whether to call a tool, and the old
text ("Returns: {steps_undone}") invites an agent to plan a workflow around
being able to roll back. They now say the tool always fails and suggest
working on a duplicate layer, or verifying with get_state_snapshot before
a hard-to-reverse change.
gimp-mcp#42 reports the undo crash; redo was broken identically and is fixed here
too.
Fixes gimp-mcp#42
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review. WalkthroughThe plugin no longer calls unavailable GIMP image undo or redo methods. It returns explicit unsupported-operation errors. Server tool documentation now explains the limitation and available alternatives. ChangesUndo and redo handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Undo and redo now fail with clear explanations instead of unexpected AttributeError exceptions, while documenting available alternatives. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation The PR fixes the reported AttributeError for undo and the suspected equivalent redo failure by returning explicit limitation errors. However, issue
✨ 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 Warning |
Fixes #42.
This does not make undo work
I could not find a way to. On GIMP 3.2.4:
Gimp.Imageexposesundo_disable,undo_enable,undo_freeze,undo_group_start,undo_group_end,undo_is_enabled,undo_thaw— stack management only. Noundo(), noredo().gimp-image-undo-*stack calls. There is nogimp-edit-undo, andgimp-edit-*covers only copy/cut/paste.actionorgimp-gui-*), so a plug-in cannot reach Edit > Undo indirectly.Undo appears to be deliberately GUI-only in GIMP 3.x. If there is a route I missed, I would genuinely like to know and will rework this.
So the tools now fail with a message naming the limitation instead of raising
AttributeError, in the same spirit as the untracked-image path in #52.The docstrings are the substantive part
The handler change only swaps one error for a better one. What actually protects a caller is the tool description, since that is what an MCP client reads when deciding whether to call something.
The old text was:
which reads as a working rollback primitive and invites an agent to plan a multi-step pipeline around being able to revert, then discover mid-run that it cannot. The new text says the tool always fails and points at what does work:
duplicate_layer) and delete the copy to revert, orget_state_snapshotbefore a change that is hard to reverse.redo was broken the same way
#42 reports only
undo, but_redocalledimage.redo()and failed identically. Both are covered here.Undo groups already work
Worth recording, because it is the actual answer for a human operator: the plug-in already wraps its operations in
undo_group_start/undo_group_end, so a single Ctrl+Z in GIMP reverts one whole plug-in operation rather than twenty internal steps. The new error messages say this, so a user who hits the failure learns the working alternative.Verification
Against a running GIMP 3.2.4 on Windows 10, over MCP:
undo(steps=1)'Image' object has no attribute 'undo'redo(steps=2)'Image' object has no attribute 'redo'python -m py_compilepasses on both files.ruff checkis unchanged at 421 findings across the two files — no new violations.Summary by CodeRabbit
Bug Fixes
Documentation