@@ -17,7 +17,6 @@ use std::{
1717use esp_idf_part:: PartitionTable ;
1818use log:: { debug, info, warn} ;
1919use md5:: { Digest , Md5 } ;
20- use miette:: { Context , IntoDiagnostic , Result } ;
2120use serde:: { Deserialize , Serialize } ;
2221#[ cfg( feature = "serialport" ) ]
2322use serialport:: UsbPortInfo ;
@@ -332,7 +331,7 @@ impl<'a> FlashDataBuilder<'a> {
332331 }
333332
334333 /// Builds a [`FlashData`] object.
335- pub fn build ( self ) -> Result < FlashData > {
334+ pub fn build ( self ) -> Result < FlashData , Error > {
336335 FlashData :: new (
337336 self . bootloader_path ,
338337 self . partition_table_path ,
@@ -364,12 +363,13 @@ impl FlashData {
364363 target_app_partition : Option < String > ,
365364 flash_settings : FlashSettings ,
366365 min_chip_rev : u16 ,
367- ) -> Result < Self > {
366+ ) -> Result < Self , Error > {
368367 // If the '--bootloader' option is provided, load the binary file at the
369368 // specified path.
370369 let bootloader = if let Some ( path) = bootloader {
371- let path = fs:: canonicalize ( path) . into_diagnostic ( ) ?;
372- let data: Vec < u8 > = fs:: read ( path) . into_diagnostic ( ) ?;
370+ let data = fs:: canonicalize ( path)
371+ . and_then ( fs:: read)
372+ . map_err ( |e| Error :: FileOpenError ( path. display ( ) . to_string ( ) , e) ) ?;
373373
374374 Some ( data)
375375 } else {
@@ -1176,10 +1176,8 @@ pub(crate) fn checksum(data: &[u8], mut checksum: u8) -> u8 {
11761176}
11771177
11781178/// Parse a [PartitionTable] from the provided path
1179- pub fn parse_partition_table ( path : & Path ) -> Result < PartitionTable > {
1180- let data = fs:: read ( path)
1181- . into_diagnostic ( )
1182- . wrap_err ( "Failed to open partition table" ) ?;
1179+ pub fn parse_partition_table ( path : & Path ) -> Result < PartitionTable , Error > {
1180+ let data = fs:: read ( path) . map_err ( |e| Error :: FileOpenError ( path. display ( ) . to_string ( ) , e) ) ?;
11831181
1184- PartitionTable :: try_from ( data) . into_diagnostic ( )
1182+ Ok ( PartitionTable :: try_from ( data) ? )
11851183}
0 commit comments