Skip to content

🧹 Refactor: Remove bare except Exception: suppressing errors silently#227

Merged
bashandbone merged 2 commits intomainfrom
fix/remove-bare-except-in-search-api-4193187016987027480
Mar 16, 2026
Merged

🧹 Refactor: Remove bare except Exception: suppressing errors silently#227
bashandbone merged 2 commits intomainfrom
fix/remove-bare-except-in-search-api-4193187016987027480

Conversation

@bashandbone
Copy link
Contributor

@bashandbone bashandbone commented Mar 16, 2026

🎯 What: The code health issue addressed was a bare except Exception: clause in _resolve_indexer_from_container that silently swallowed any exceptions thrown during DI container resolution, returning None without leaving a trace.
💡 Why: This improves maintainability by ensuring that any actual errors (e.g. issues during container resolution) are properly logged as warnings instead of failing silently. This provides essential context for debugging should the IndexingService fail to resolve.
Verification: Verified by inspecting the file to confirm logger is imported and set up. Executed uv run pytest tests/unit/server/agent_api/find_code/ --no-cov ensuring all 9 unit tests still pass successfully with no regressions.
Result: The system will now emit a warning log with the actual exception details when container resolution fails, while correctly preserving the original fallback logic (returning None).


PR created automatically by Jules for task 4193187016987027480 started by @bashandbone

Summary by Sourcery

Enhancements:

  • Log a warning with exception details when IndexingService resolution from the DI container fails, while preserving the None fallback behavior.

Modifies `_resolve_indexer_from_container` in `src/codeweaver/server/agent_api/search/__init__.py` to capture exceptions as `e` and log them using `logger.warning`. This improves observability and code health by preventing silent failures without changing the return logic.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 16, 2026 03:29
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 16, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR refactors the error handling in _resolve_indexer_from_container so that failures during DI container resolution of IndexingService are logged as warnings instead of being silently swallowed, while preserving the existing fallback behavior of returning None on failure.

Sequence diagram for IndexingService resolution with logging

sequenceDiagram
    participant Caller
    participant _resolve_indexer_from_container
    participant Container as DIContainer
    participant IndexingService
    participant Logger

    Caller->>_resolve_indexer_from_container: call
    activate _resolve_indexer_from_container
    _resolve_indexer_from_container->>Container: get_container()
    activate Container
    Container-->>_resolve_indexer_from_container: container
    deactivate Container

    _resolve_indexer_from_container->>Container: resolve(IndexingService)
    alt resolution_succeeds
        Container-->>_resolve_indexer_from_container: IndexingService instance
        _resolve_indexer_from_container-->>Caller: IndexingService instance
    else resolution_raises_exception
        Container--x _resolve_indexer_from_container: Exception e
        _resolve_indexer_from_container->>Logger: warning(Failed to resolve IndexingService from container: e)
        _resolve_indexer_from_container-->>Caller: None
    end
    deactivate _resolve_indexer_from_container
Loading

File-Level Changes

Change Details Files
Log DI container resolution failures for IndexingService instead of silently swallowing exceptions while keeping the None fallback.
  • Capture the thrown exception in _resolve_indexer_from_container by binding it as e in the except Exception clause.
  • Log a warning with the error details when resolving IndexingService from the container fails.
  • Retain the existing behavior of returning None when resolution fails so downstream logic remains unchanged.
src/codeweaver/server/agent_api/search/__init__.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Consider including exc_info=True in the warning log so that the full traceback is captured for easier debugging when IndexingService resolution fails.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider including `exc_info=True` in the warning log so that the full traceback is captured for easier debugging when `IndexingService` resolution fails.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Contributor

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

Refactors _resolve_indexer_from_container to avoid silently swallowing DI container resolution errors by logging failures while preserving the None fallback.

Changes:

  • Captures the thrown exception during container resolution and logs a warning.
  • Keeps the existing fallback behavior by returning None when resolution fails.

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

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
Copilot AI review requested due to automatic review settings March 16, 2026 03:38
@bashandbone bashandbone merged commit 21b57a9 into main Mar 16, 2026
12 of 18 checks passed
@bashandbone bashandbone deleted the fix/remove-bare-except-in-search-api-4193187016987027480 branch March 16, 2026 03:38
Copy link
Contributor

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

Refactors DI container resolution to avoid silently swallowing exceptions by logging warning details while preserving the existing None fallback behavior.

Changes:

  • Log warnings (with stack traces) when resolving IndexingService from the DI container fails.
  • Include exception tracebacks in the existing “Auto-indexing failed” warning.
Comments suppressed due to low confidence (1)

src/codeweaver/server/agent_api/search/init.py:1

  • Catching Exception in an async def can inadvertently swallow task cancellation on Python versions where asyncio.CancelledError subclasses Exception, preventing cooperative cancellation. Prefer handling cancellation explicitly (e.g., except asyncio.CancelledError: raise) before the broad except Exception block.
# SPDX-FileCopyrightText: 2026 Knitli Inc.

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

Comment on lines 205 to +208
# We enable reconciliation by default to fix any partial indexes
await indexer.index_project(add_dense=True, add_sparse=True)
except Exception as e:
logger.warning("Auto-indexing failed: %s", e)
logger.warning("Auto-indexing failed: %s", e, exc_info=True)
Comment on lines +182 to +185
"Failed to resolve IndexingService from container: %s",
e,
exc_info=True,
)
Copilot AI pushed a commit that referenced this pull request Mar 17, 2026
…ly (#227)

* Refactor: Remove bare `except Exception:` suppressing errors silently

Modifies `_resolve_indexer_from_container` in `src/codeweaver/server/agent_api/search/__init__.py` to capture exceptions as `e` and log them using `logger.warning`. This improves observability and code health by preventing silent failures without changing the return logic.

Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com>

* Potential fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>

---------

Signed-off-by: Adam Poulemanos <89049923+bashandbone@users.noreply.github.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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