Skip to content

Conversation

gaojulong
Copy link

@gaojulong gaojulong commented Aug 18, 2025

For burning custom firmware, the validation of 'GenericSerial' should be skipped. Resolve the error 'Could not install firmware.'

Summary by Sourcery

Skip board_id validation for GenericSerial platform and improve firmware file load error handling to resolve 'Could not install firmware' error.

Bug Fixes:

  • Skip board_id validation for GenericSerial platform to allow custom firmware burning without errors.

Enhancements:

  • Improve error message when firmware file cannot be loaded for validation.

…3195

For burning custom firmware, the validation of 'GenericSerial' should be skipped. Resolve the error 'Could not install firmware.'
Copy link

sourcery-ai bot commented Aug 18, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR refactors _validate_apj to skip board_id checks for GenericSerial devices, replaces broad exception handling with specific catches and improved error messages, and reorganizes the validation flow for better readability.

Class diagram for updated _validate_apj logic in FirmwareInstall

classDiagram
    class FirmwareInstall {
        +_validate_apj(firmware_path: pathlib.Path, platform: Platform)
    }
    class Platform {
        <<enumeration>>
        GenericSerial
        // ... other platform types
    }
    FirmwareInstall --> Platform: uses
Loading

Flow diagram for firmware validation with GenericSerial skip

flowchart TD
    A[Start firmware validation] --> B{Platform == GenericSerial?}
    B -- Yes --> C[Skip board_id validation]
    C --> D[Return]
    B -- No --> E[Get expected_board_id]
    E --> F{expected_board_id == -1?}
    F -- Yes --> G[Raise UnsupportedPlatform]
    F -- No --> H{firm_board_id == -1?}
    H -- Yes --> I[Raise InvalidFirmwareFile: missing board_id]
    H -- No --> J{firm_board_id != expected_board_id?}
    J -- Yes --> K[Raise InvalidFirmwareFile: board_id mismatch]
    J -- No --> L[Return]
Loading

File-Level Changes

Change Details Files
Skip board_id validation for GenericSerial platform
  • Add explicit check for Platform.GenericSerial
  • Log a warning and return early in that branch
  • Confine remaining validation to non-GenericSerial platforms
core/services/ardupilot_manager/firmware/FirmwareInstall.py
Refactor exception handling in _validate_apj
  • Catch OSError and JSONDecodeError instead of a generic Exception
  • Enhance error message to include firmware_path for diagnostics
  • Remove outdated broad except clause
core/services/ardupilot_manager/firmware/FirmwareInstall.py
Restructure validation flow for clarity
  • Reposition return statements to separate platform skip from full validation
  • Reorder validation checks for board_id retrieval and comparison
  • Adjust indentation and code blocks to reflect new control flow
core/services/ardupilot_manager/firmware/FirmwareInstall.py

Possibly linked issues


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

@CLAassistant
Copy link

CLAassistant commented Aug 18, 2025

CLA assistant check
All committers have signed the CLA.

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:

  • The unindented return after the GenericSerial skip will short-circuit validation for all platforms—move it inside the if platform == Platform.GenericSerial block so only GenericSerial avoids the board_id checks.
  • Consider restructuring the JSON load and board_id logic into a clear sequence (load → generic-skip → validate) to reduce nested blocks and improve readability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The unindented `return` after the GenericSerial skip will short-circuit validation for all platforms—move it inside the `if platform == Platform.GenericSerial` block so only GenericSerial avoids the board_id checks.
- Consider restructuring the JSON load and board_id logic into a clear sequence (load → generic-skip → validate) to reduce nested blocks and improve readability.

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.

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