Skip to content

fix: add logging to bare except blocks in browser/core packages#803

Open
dashitongzhi wants to merge 3 commits into
nottelabs:mainfrom
dashitongzhi:fix/add-logging-to-bare-except-blocks
Open

fix: add logging to bare except blocks in browser/core packages#803
dashitongzhi wants to merge 3 commits into
nottelabs:mainfrom
dashitongzhi:fix/add-logging-to-bare-except-blocks

Conversation

@dashitongzhi
Copy link
Copy Markdown

@dashitongzhi dashitongzhi commented May 7, 2026

Summary

Multiple files had bare except Exception: blocks that silently swallowed errors, making it very difficult to diagnose issues in production. This PR adds logger.debug calls with exc_info=True to the most impactful ones.

Changes

csspaths.py (build_csspath)

  • Bare except Exception:except Exception as e: with debug logging
  • When CSS selector construction fails, now logs the error before falling back to the basic selector

form_filling.py (_fill_select_field)

  • Bare except Exception:except Exception as e: with debug logging
  • When exact select_option match fails, now logs the reason before trying case-insensitive match

observation.py (Screenshot.validate_raw)

  • JPEG header parsing exception: logs before falling through to PIL path
  • PIL Image.open exception: logs before returning empty observation screenshot

All logging uses logger.debug with exc_info=True to avoid noise in production while providing full traceback when debug level is enabled.

Summary by CodeRabbit

  • Chores
    • Improved debug logging and diagnostics for CSS selector generation failures, including exception details.
    • Added detailed debug logging when exact form field option selection fails, aiding selection troubleshooting.
    • Enhanced error logging for screenshot validation/decoding failures, providing exception context before fallback handling.

Note

Adds logger.debug(..., exc_info=True) to three bare except Exception: blocks in csspaths.py, form_filling.py, and observation.py to surface previously swallowed errors during debugging. A follow-up commit fixes import sorting to pass ruff pre-commit checks.

Written by Mendral for commit 129ff98.

Several files had bare 'except Exception:' blocks that silently swallowed
errors, making debugging difficult. Added logger.debug calls with
exc_info=True to the most impactful ones:

- csspaths.py: log when build_csspath falls back to basic selector
- form_filling.py: log when exact select_option match fails
- observation.py: log JPEG header parsing and PIL image open failures

All use debug level to avoid noise in production while remaining
available for troubleshooting when needed.
Copilot AI review requested due to automatic review settings May 7, 2026 14:08
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 7, 2026

PR author is not in the allowed authors list.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Walkthrough

Added debug logging (including full traceback via exc_info=True) at failure-handling points in three files: csspaths.py (when build_csspath fails and a fallback selector is returned), form_filling.py (when an exact select_option attempt raises before falling back to case-insensitive matching), and observation.py (two places in Screenshot.validate_raw where JPEG header parsing or PIL.Image.open can fail). No control flow, fallback logic, or public APIs were changed.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: adding debug logging to exception handlers across the codebase in browser/core packages.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make previously silent exception paths in the browser/core stack diagnosable by adding debug-level logging when fallbacks are triggered.

Changes:

  • Added debug logs when JPEG header parsing or PIL decoding fails during screenshot validation.
  • Added debug log when exact select_option fails before attempting a case-insensitive fallback.
  • Added debug log when CSS selector construction fails before falling back to a basic selector.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/notte-core/src/notte_core/browser/observation.py Adds debug logs on screenshot parsing/decoding failure paths.
packages/notte-browser/src/notte_browser/form_filling.py Adds debug log when exact select matching fails before fallback logic.
packages/notte-browser/src/notte_browser/dom/csspaths.py Adds debug log when CSS selector construction fails before fallback selector.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return True
except Exception:
except Exception as e:
logger.debug(f"Exact match failed for {field_type} field, trying case-insensitive match: {e}", exc_info=True)
except Exception:
# Fallback to a more basic selector if something goes wrong
except Exception as e:
logger.debug(f"build_csspath failed, falling back to basic selector: {e}", exc_info=True)
Comment on lines +134 to +140
logger.debug("JPEG header parsing failed, falling through to PIL path", exc_info=True)

# Slow path: use PIL for non-JPEG or images that need padding
try:
img = Image.open(io.BytesIO(v))
except Exception:
logger.debug("PIL Image.open failed for screenshot data, returning empty observation screenshot", exc_info=True)
Comment on lines +134 to +140
logger.debug("JPEG header parsing failed, falling through to PIL path", exc_info=True)

# Slow path: use PIL for non-JPEG or images that need padding
try:
img = Image.open(io.BytesIO(v))
except Exception:
logger.debug("PIL Image.open failed for screenshot data, returning empty observation screenshot", exc_info=True)
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/notte-browser/src/notte_browser/dom/csspaths.py`:
- Around line 2-4: Import block in csspaths.py is not formatted/sorted per Ruff;
reorder the imports so stdlib imports (import re) come first, then a blank line,
then local/package imports (from notte_core.common.logging import logger), or
simply run the suggested auto-fix command to apply Ruff’s import ordering: ruff
check --fix packages/notte-browser/src/notte_browser/dom/csspaths.py; ensure the
top-level symbols "re" and "logger" are separated into proper import groups with
a blank line between them.

In `@packages/notte-core/src/notte_core/browser/observation.py`:
- Around line 15-16: The import order for nuit_core modules is incorrect: move
the `from notte_core.common.logging import logger` import to its alphabetical
position within the existing `notte_core.*` block (so it appears after `from
notte_core.common.config ...` and before any later `notte_core` imports) to
satisfy Ruff I001; locate the `logger` import in this file (it sits alongside
`from notte_core.actions import ActionUnion`) and reorder it accordingly (or run
`ruff check --fix` on this file to auto-fix).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 91d27433-5424-4d1d-b3e7-e5bf753c06cf

📥 Commits

Reviewing files that changed from the base of the PR and between f7ecf75 and 1af3a36.

📒 Files selected for processing (3)
  • packages/notte-browser/src/notte_browser/dom/csspaths.py
  • packages/notte-browser/src/notte_browser/form_filling.py
  • packages/notte-core/src/notte_core/browser/observation.py

Comment thread packages/notte-browser/src/notte_browser/dom/csspaths.py
Comment thread packages/notte-core/src/notte_core/browser/observation.py Outdated
@2027-evals
Copy link
Copy Markdown

2027-evals Bot commented May 7, 2026

⚠️ Couldn't find a preview deployment for commit f405f0c after 10 minutes.

2027 auto-runs evals against preview deployments of your docs. To enable this, install one of:

  • Mintlify — if you use Mintlify docs
  • Vercel — for Next.js / static sites
  • Netlify — for most static docs

Once a preview is deployed, open a new PR and we'll run the eval automatically.


Evaluating agent experience using 2027.dev · View dashboard

mendral-app[bot]

This comment was marked as outdated.

Fixes I001 import sorting in csspaths.py and observation.py,
and reformats 3 files to pass pre-commit ruff hooks.
Copy link
Copy Markdown

@mendral-app mendral-app Bot left a comment

Choose a reason for hiding this comment

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

LGTM

Both previous import-sorting issues are fixed in commit 129ff98. The CI failures are all integration tests hitting the staging cluster (HTTP 529 "Cluster is under heavy load" / 502 Bad Gateway) — a pre-existing infrastructure issue tracked in insight #01KP9XGDY6FQENXZ0W8V6QK5H4, not caused by this PR. Code is ready to merge.

Tag @mendral-app with feedback or questions. View session

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.

2 participants