Skip to content

Conversation

patrickelectric
Copy link
Member

@patrickelectric patrickelectric commented Sep 10, 2025

To test:
Create a invalid settings-1, run a version that has settings-2, settings-1 is invalid and default settings-2 is created.
Tested with cable-guy

Copy link

sourcery-ai bot commented Sep 10, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Broaden exception handling in PydanticManager and PyksonManager to catch all errors when loading settings files so that any invalid file is skipped and the next candidate is tried.

Sequence diagram for settings file loading with broader exception handling

sequenceDiagram
participant Manager
participant SettingsFile
participant Logger

Manager->>SettingsFile: load_from_file(settings_type, valid_file)
alt Success
    Manager->>Logger: debug("Using valid_file as settings source")
    Manager-->>Manager: return
else Exception
    Manager->>Logger: debug("Invalid settings, going to try another file:", exception)
    Manager->>SettingsFile: load_from_file(settings_type, next_candidate)
end
Loading

File-Level Changes

Change Details Files
Broaden exception handling in settings managers to skip invalid files robustly
  • Replace except SettingsFromTheFuture with except Exception in PydanticManager
  • Replace except SettingsFromTheFuture with except Exception in PyksonManager
core/libs/commonwealth/src/commonwealth/settings/managers/pydantic_manager.py
core/libs/commonwealth/src/commonwealth/settings/managers/pykson_manager.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

@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 there - I've reviewed your changes - here's some feedback:

  • Avoid catching all Exceptions here—narrow the except clause to the specific errors you actually expect (e.g. SettingsFromTheFuture) so you don’t accidentally swallow unrelated failures.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Avoid catching all Exceptions here—narrow the except clause to the specific errors you actually expect (e.g. SettingsFromTheFuture) so you don’t accidentally swallow unrelated failures.

## Individual Comments

### Comment 1
<location> `core/libs/commonwealth/src/commonwealth/settings/managers/pydantic_manager.py:127` </location>
<code_context>
                 logger.debug(f"Using {valid_file} as settings source")
                 return
-            except SettingsFromTheFuture as exception:
+            except Exception as exception:
                 logger.debug("Invalid settings, going to try another file:", exception)

</code_context>

<issue_to_address>
Catching Exception may mask unrelated errors.

Catching Exception instead of SettingsFromTheFuture may hide unrelated errors. Consider handling only relevant exceptions, and add logging or re-raise as needed to prevent silent failures.
</issue_to_address>

### Comment 2
<location> `core/libs/commonwealth/src/commonwealth/settings/managers/pykson_manager.py:123` </location>
<code_context>
                 logger.debug(f"Using {valid_file} as settings source")
                 return
-            except SettingsFromTheFuture as exception:
+            except Exception as exception:
                 logger.debug("Invalid settings, going to try another file:", exception)

</code_context>

<issue_to_address>
Broad exception handling could obscure root causes.

Consider catching only specific exceptions related to settings, or ensure unexpected exceptions are logged or re-raised to aid debugging.
</issue_to_address>

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.

logger.debug(f"Using {valid_file} as settings source")
return
except SettingsFromTheFuture as exception:
except Exception as exception:
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Catching Exception may mask unrelated errors.

Catching Exception instead of SettingsFromTheFuture may hide unrelated errors. Consider handling only relevant exceptions, and add logging or re-raise as needed to prevent silent failures.

logger.debug(f"Using {valid_file} as settings source")
return
except SettingsFromTheFuture as exception:
except Exception as exception:
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Broad exception handling could obscure root causes.

Consider catching only specific exceptions related to settings, or ensure unexpected exceptions are logged or re-raised to aid debugging.

@patrickelectric
Copy link
Member Author

@joaomariolago check now, updates with tests

@patrickelectric patrickelectric force-pushed the board-exception-settings branch 3 times, most recently from e4ae4c7 to acd4cf0 Compare September 11, 2025 12:04
…ngs file

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
…valid files

Signed-off-by: Patrick José Pereira <patrickelectric@gmail.com>
@patrickelectric patrickelectric added the move-to-stable Needs to be cherry-picked and move to stable label Sep 11, 2025
@patrickelectric patrickelectric merged commit 45adc2e into bluerobotics:master Sep 11, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

move-to-stable Needs to be cherry-picked and move to stable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants