Skip to content

Keep the code and help of espflash errors - #1148

Open
SergioGasquez wants to merge 3 commits into
esp-rs:mainfrom
SergioGasquez:fix/keep-diagnostic-help
Open

SergioGasquez wants to merge 3 commits into
esp-rs:mainfrom
SergioGasquez:fix/keep-diagnostic-help

Conversation

@SergioGasquez

Copy link
Copy Markdown
Member

Description

Fixes #1136.

Several CLI paths converted espflash's own errors, which implement miette::Diagnostic, with .into_diagnostic(). That wraps them as plain std::error::Errors and drops their code(...) and help(...), so users only saw the one-line message. They're now converted with .into() / ?, which go through From<E: Diagnostic> for Report and keep both.

Affected errors:

  • espflash: StubRequired (erase-region), InvalidEraseRegionArgument, ImageFormatMismatch, FirmwareChipMismatch, AppDescriptorNotPresent, ParseChipRevError, the errors of Flasher::erase_region (erase-parts) and Flasher::verify_minimum_revision.
  • cargo-espflash: StubRequired (erase-parts), NoPackage, Flasher::verify_minimum_revision.

The remaining .into_diagnostic() calls convert errors of other crates (I/O, serialport, toml, esp-idf-part, cargo_metadata), which don't implement Diagnostic.

Also removes the double space before "and/or" in the InvalidEraseRegionArgument message.

An AI tool generated a significant part of this change. It is tested on the host, see Testing.

Testing

  • New unit test test_errors_keep_code_and_help: erase_region with an unaligned address and with --no-stub, and resolve_image_format with a contradicting format, return reports with their code and help. It fails if erase_region goes back to .into_diagnostic().
  • The reproductions from Help texts are lost when espflash errors are converted with .into_diagnostic() #1136 now print the code and help, e.g.:
    $ espflash erase-region 0x1001 0x1000
    Error: espflash::erase_region::invalid_argument
    
      × Invalid `address`(4097) and/or `size`(4096) argument(s)
      help: `address` (4097) and `size` (4096) must be multiples of 0x1000 (4096)
    
    Same for espflash erase-region --no-stub, espflash erase-parts --no-stub, espflash flash --format esp-idf <direct-boot ELF>, cargo espflash erase-parts --no-stub and cargo espflash save-image in a workspace without a default package (cargo_espflash::no_package).
  • cargo +nightly fmt --check, cargo clippy --all-targets -- -D warnings, cargo clippy -p espflash --no-default-features [--features cli] -- -D warnings and cargo test -p espflash --lib.

No HIL run needed: only error reporting changes, and the affected paths fail before or independently of device interaction.

@SergioGasquez
SergioGasquez force-pushed the fix/keep-diagnostic-help branch from 5092342 to 6d34af4 Compare November 20, 2026 14:09

@MabezDev MabezDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

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.

Help texts are lost when espflash errors are converted with .into_diagnostic()

2 participants