Skip to content

fix(ci): suppress OpenCV NULL guiReceiver error in headless environment#290

Open
MD-Mushfiqur123 wants to merge 1 commit into
Udayraj123:masterfrom
MD-Mushfiqur123:fix/opencv-gui-receiver-headless
Open

fix(ci): suppress OpenCV NULL guiReceiver error in headless environment#290
MD-Mushfiqur123 wants to merge 1 commit into
Udayraj123:masterfrom
MD-Mushfiqur123:fix/opencv-gui-receiver-headless

Conversation

@MD-Mushfiqur123
Copy link
Copy Markdown

Fixes #230

Wrap get_monitors()[0] in a try-except block so that the application does not crash in headless/CI environments where no display is available. Falls back to a default 1920x1080 monitor when screeninfo cannot detect any monitors.

This resolves the NULL guiReceiver error from OpenCV when running pre-commit hooks or tests on a headless server.

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

Review Summary by Qodo

Handle missing display in headless CI environments gracefully

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Wrap monitor detection in try-except to handle headless environments
• Add fallback monitor with default 1920x1080 resolution
• Prevents OpenCV NULL guiReceiver error in CI/headless servers
Diagram
flowchart LR
  A["get_monitors()[0]"] -->|"try"| B["monitor_window assigned"]
  A -->|"exception"| C["_MonitorFallback"]
  C -->|"1920x1080 default"| B

Loading

Grey Divider

File Changes

1. src/utils/interaction.py 🐞 Bug fix +10/-1

Add headless environment fallback for monitor detection

• Added _MonitorFallback class with default 1920x1080 resolution
• Wrapped get_monitors()[0] call in try-except block
• Falls back to _MonitorFallback when no monitors detected
• Prevents crashes in headless/CI environments without display

src/utils/interaction.py


Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects
Copy link
Copy Markdown

qodo-free-for-open-source-projects Bot commented May 28, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Context used

Grey Divider


Remediation recommended

1. Silent monitor fallback 🐞 Bug ◔ Observability
Description
get_monitors()[0] failures are swallowed by a broad except Exception: and the code silently
falls back to 1920x1080, hiding real display-detection errors and making window placement bugs hard
to diagnose. This module is imported by core entry points, so the silent fallback can affect normal
runs as well as CI/headless runs.
Code

src/utils/interaction.py[R15-18]

Evidence
The new try/except swallows all monitor detection errors without logging, and the resulting
dimensions are used to compute window sizing for the GUI. Since InteractionUtils is imported by
core modules, this behavior occurs broadly and can silently affect window positioning in non-CI runs
too.

src/utils/interaction.py[10-24]
src/core.py[17-20]
src/entry.py[24-31]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`src/utils/interaction.py` catches any `Exception` from `get_monitors()[0]` and silently switches to a hard-coded fallback resolution. This masks unexpected failures (e.g., misconfigured desktop environments) and provides no signal that window sizing is now degraded.

## Issue Context
This code runs at import-time (module global initialization) and is reached in normal executions because `InteractionUtils` is imported from core entry points.

## Fix Focus Areas
- src/utils/interaction.py[10-18]

## Suggested fix
1. Catch only the expected failure modes (e.g., `IndexError` for empty list and `screeninfo.common.ScreenInfoError` for headless detection failures).
2. Log a `logger.warning(...)` when falling back, including the exception (`exc_info=True`) so users can diagnose why monitor detection failed.
3. (Optional) If a headless environment is detected via env (e.g., missing `DISPLAY`/`WAYLAND_DISPLAY` on Linux), skip calling `get_monitors()` entirely and go directly to fallback to avoid noisy underlying errors.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Copy link
Copy Markdown
Owner

@Udayraj123 Udayraj123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will be handling this in v2 in a better way. @MD-Mushfiqur123 can you please cover this change in a test case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Environment] OpenCV NULL guiReceiver error during pre-commit testing .

2 participants