8000 Detect headless GIMP instead of hiding display errors by tomerkon · Pull Request #183 · gimp-mcp/gimp-mcp · GitHub
[go: up one dir, main page]

Skip to content

Detect headless GIMP instead of hiding display errors - #183

Merged
tomerkon merged 1 commit into
mainfrom
fix/88-headless-display-detection
Dec 3, 2026
Merged

tomerkon merged 1 commit into
mainfrom
fix/88-headless-display-detection

Conversation

@tomerkon
@tomerkon tomerkon commented Dec 3, 2026 •
Copy link
Copy Markdown
Collaborator

Fixes #88.

_create_display() caught every Gimp.Display.new() exception, so headless runs (gimp -i) wouldn't fail open_image / new_canvas. That also hid real display failures in GUI mode: the call returned success with display_opened: false, and the cause appeared only in GIMP's stdout.

Change

  • Headless detection: Gimp.Display.name() is documented to return NULL when GIMP runs without a GUI (--no-interface or a console build). When it is None, _create_display() doesn't try to open a window, and the result is display_opened: false with no warning, as before.
  • GUI failures: in GUI mode a Display.new() failure now reaches the caller. The new _display_result() turns it into a warning next to display_opened: false. The call still succeeds, because the image already exists: an error would leave it open without the caller knowing its id.
  • new_canvas and open_image use _display_result(). The server docstrings document warning, and CHANGELOG.md has a Fixed entry.

Testing

  • tests/test_open_image_headless.py now covers three cases: headless (Display.new must not be called), GUI success, and GUI failure (warning names the error). It fails on the old code for the headless and GUI-failure cases.
  • tests/test_gimp3_compat.py: the Display stub gains name().
  • All offline tests and ruff check pass.
  • Live, GIMP 3.2 snap on Linux:
    • gimp -i: Display.name() is None, and Display.new() raises TypeError: constructor returned NULL.
    • GUI: Display.name() is ':0', and new_canvas returns display_opened: true. With Display.new patched to raise inside GIMP, new_canvas returned display_opened: false plus the warning, and the image existed.
  • Not tested on Windows or macOS.

Summary by CodeRabbit

  • Bug Fixes
    • Image creation and opening now report a warning if GIMP cannot open the image window, while preserving the successful image operation.
    • In headless mode, no window is attempted; the result indicates that no display was opened without returning a warning.
  • Documentation
    • Clarified when display status and warnings may appear for image creation and opening.

_create_display() caught every Gimp.Display.new() exception so headless
runs (gimp -i) wouldn't fail open_image/new_canvas, which also hid real
display failures in GUI mode.

Check Gimp.Display.name() instead: it is None when GIMP has no GUI, so
no window is attempted there. In GUI mode a Display.new() failure now
comes back as a "warning" next to display_opened: false; the image is
still created, so the call doesn't fail.
@github-actions github-actions Bot added bug Something isn't working documentation Improvements or additions to documentation labels Dec 3, 2026
@coderabbitai
coderabbitai Bot commented Dec 3, 2026 •
Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The plugin now skips display creation when GIMP has no display. When display creation fails in GUI mode, new_canvas and open_image preserve the successful image operation and return a warning with the cause.

Changes

Display reporting

Layer / File(s) Summary
Detect display availability and report outcomes
gimp-mcp-plugin.py, gimp_mcp_server.py, tests/test_gimp3_compat.py, tests/test_open_image_headless.py, CHANGELOG.md
The plugin skips display creation when Gimp.Display.name() returns None. In GUI mode, display-creation failures produce display_opened: false and a warning in successful new_canvas and open_image results. Tests cover headless mode, GUI success, and GUI failure. The tool documentation and changelog describe these outcomes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • gimp-mcp/gimp-mcp#67: Adds the shared display-creation helper and covers the same open_image and new_canvas paths.

Suggested labels: bug

Suggested reviewers: gokmonk, jhammons, vicarc

Merge Risk: Minimal · up to ac13e

This change makes open_image and new_canvas skip the display step in headless mode and report a warning when the GUI cannot open a window, instead of silently hiding the failure. Image operations still succeed. No merge-blocking risk is apparent.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the core change: headless GIMP is now detected via Gimp.Display.name(), replacing the blanket catch that hid display errors. The changeset matches this. The summary shows the headless …
Linked Issues check Passed Issue #88 requires: (1) a reliable headless signal, (2) no display creation in headless mode, and (3) GUI-mode Display.new() failures surfaced as an error or a warning. The whole-PR summary and PR des…
Out of Scope Changes check Passed All changed areas connect to #88: gimp-mcp-plugin.py (_create_display, new _display_result, _new_canvas, _open_image), gimp_mcp_server.py (docstrings documenting display_opened and `warn…
Full details: Title check

Explanation

The title names the core change: headless GIMP is now detected via Gimp.Display.name(), replacing the blanket catch that hid display errors. The changeset matches this. The summary shows the headless check, the GUI-mode warning path through _display_result, and the removal of the broad exception catch in _create_display. The title is specific and short, and it does not cover the docstring, changelog, or test updates, which is expected.

Full details: Linked Issues check

Explanation

Issue #88 requires: (1) a reliable headless signal, (2) no display creation in headless mode, and (3) GUI-mode Display.new() failures surfaced as an error or a warning. The whole-PR summary and PR description consistently show: _create_display() returns False without calling Gimp.Display.new() when Gimp.Display.name() is None (headless). Requirement (1) is met by that signal, and the PR reports live checks showing name() is None under gimp -i and ':0' in GUI mode. In GUI mode, Display.new() errors now propagate to _display_result(), which returns display_opened: false with a warning while the call still succeeds (requirement 3, warning alternative). new_canvas and open_image both use _display_result(). tests/test_open_image_headless.py covers headless (Display.new not called), GUI success, and GUI failure (warning contains the error). Limitation: the file diff could not be read directly, so the code behavior rests on the summary and the author's reported live tests. The summary is consistent with the PR description. The issue's 'detect once' wording is not explicitly confirmed; the check is per call per the summary, which does not conflict with the stated requirement.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to #88: gimp-mcp-plugin.py (_create_display, new _display_result, _new_canvas, _open_image), gimp_mcp_server.py (docstrings documenting display_opened and warning), CHANGELOG.md (Fixed entry), tests/test_open_image_headless.py (headless, success, and failure cases), and tests/test_gimp3_compat.py (adds name() to the Display stub so existing tests run). The summary reports no changes to exported or public declarations. No unrelated change is evident. The diff could not be read directly, so this rests on the summary, which lists only these files.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 2dfafd9 and ac13e66.

Files selected for processing: 5

  • CHANGELOG.md
  • gimp-mcp-plugin.py
  • gimp_mcp_server.py
  • tests/test_gimp3_compat.py
  • tests/test_open_image_headless.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@tomerkon
tomerkon merged commit 5c49300 into main Dec 3, 2026
6 checks passed
@tomerkon
tomerkon deleted the fix/88-headless-display-detection branch December 3, 2026 09:06
@tomerkon tomerkon mentioned this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect headless mode instead of catching all display errors

1 participant

0