@@ -5,22 +5,21 @@ use std::{
5
5
io,
6
6
} ;
7
7
8
+ use miette:: Diagnostic ;
9
+ use slip_codec:: SlipError ;
10
+ use strum:: { FromRepr , VariantNames } ;
11
+ use thiserror:: Error ;
12
+
8
13
#[ cfg( feature = "cli" ) ]
9
14
use crate :: cli:: monitor:: parser:: esp_defmt:: DefmtError ;
10
15
#[ cfg( feature = "serialport" ) ]
11
16
use crate :: interface:: SerialConfigError ;
12
17
use crate :: {
13
18
command:: CommandType ,
14
19
flasher:: { FlashFrequency , FlashSize } ,
15
- image_format:: ImageFormatKind ,
16
20
targets:: Chip ,
17
21
} ;
18
22
19
- use miette:: Diagnostic ;
20
- use slip_codec:: SlipError ;
21
- use strum:: { FromRepr , VariantNames } ;
22
- use thiserror:: Error ;
23
-
24
23
/// All possible errors returned by espflash
25
24
#[ derive( Debug , Diagnostic , Error ) ]
26
25
#[ non_exhaustive]
@@ -107,16 +106,6 @@ pub enum Error {
107
106
#[ diagnostic( code( espflash:: invalid_bootloader_path) ) ]
108
107
InvalidBootloaderPath ,
109
108
110
- #[ error( "Binary is not set up correctly to support direct boot" ) ]
111
- #[ diagnostic(
112
- code( espflash:: invalid_direct_boot) ,
113
- help(
114
- "See the following page for documentation on how to set up your binary for direct boot:\
115
- https://github.com/espressif/esp32c3-direct-boot-example"
116
- )
117
- ) ]
118
- InvalidDirectBootBinary ,
119
-
120
109
#[ error( "The flash size '{0}' is invalid" ) ]
121
110
#[ diagnostic(
122
111
code( espflash:: invalid_flash_size) ,
@@ -165,13 +154,6 @@ pub enum Error {
165
154
) ]
166
155
SerialNotFound ( String ) ,
167
156
168
- #[ error( "Unrecognized image format '{0}'" ) ]
169
- #[ diagnostic(
170
- code( espflash:: unknown_format) ,
171
- help( "The following image formats are supported: {}" , ImageFormatKind :: VARIANTS . join( ", " ) )
172
- ) ]
173
- UnknownImageFormat ( String ) ,
174
-
175
157
#[ error( "The {chip} does not support {feature}" ) ]
176
158
#[ diagnostic( code( espflash:: unsupported_feature) ) ]
177
159
UnsupportedFeature { chip : Chip , feature : String } ,
@@ -221,10 +203,6 @@ pub enum Error {
221
203
#[ diagnostic( transparent) ]
222
204
RomError ( #[ from] RomError ) ,
223
205
224
- #[ error( transparent) ]
225
- #[ diagnostic( transparent) ]
226
- UnsupportedImageFormat ( #[ from] UnsupportedImageFormatError ) ,
227
-
228
206
#[ cfg( feature = "serialport" ) ]
229
207
#[ error( transparent) ]
230
208
#[ diagnostic( transparent) ]
@@ -517,80 +495,6 @@ impl From<&'static str> for ElfError {
517
495
}
518
496
}
519
497
520
- /// Unsupported image format error
521
- #[ derive( Debug ) ]
522
- pub struct UnsupportedImageFormatError {
523
- format : ImageFormatKind ,
524
- chip : Chip ,
525
- revision : Option < ( u32 , u32 ) > ,
526
- context : Option < String > ,
527
- }
528
-
529
- impl UnsupportedImageFormatError {
530
- pub fn new ( format : ImageFormatKind , chip : Chip , revision : Option < ( u32 , u32 ) > ) -> Self {
531
- Self {
532
- format,
533
- chip,
534
- revision,
535
- context : None ,
536
- }
537
- }
538
-
539
- /// Return a comma-separated list of supported image formats
540
- fn supported_formats ( & self ) -> String {
541
- self . chip
542
- . into_target ( )
543
- . supported_image_formats ( )
544
- . iter ( )
545
- . map ( |format| format. into ( ) )
546
- . collect :: < Vec < & ' static str > > ( )
547
- . join ( ", " )
548
- }
549
-
550
- /// Update the context of the unsupported image format error
551
- pub fn with_context ( mut self , ctx : String ) -> Self {
552
- self . context . replace ( ctx) ;
553
-
554
- self
555
- }
556
- }
557
-
558
- impl std:: error:: Error for UnsupportedImageFormatError { }
559
-
560
- impl Display for UnsupportedImageFormatError {
561
- fn fmt ( & self , f : & mut Formatter ) -> std:: fmt:: Result {
562
- write ! (
563
- f,
564
- "Image format {} is not supported by the {}" ,
565
- self . format, self . chip
566
- ) ?;
567
-
568
- if let Some ( ( major, minor) ) = self . revision {
569
- write ! ( f, " revision v{major}.{minor}" ) ?;
570
- }
571
-
572
- Ok ( ( ) )
573
- }
574
- }
575
-
576
- impl Diagnostic for UnsupportedImageFormatError {
577
- fn code < ' a > ( & ' a self ) -> Option < Box < dyn Display + ' a > > {
578
- Some ( Box :: new ( "espflash::unsupported_image_format" ) )
579
- }
580
-
581
- fn help < ' a > ( & ' a self ) -> Option < Box < dyn Display + ' a > > {
582
- if let Some ( ref ctx) = self . context {
583
- Some ( Box :: new ( ctx) )
584
- } else {
585
- Some ( Box :: new ( format ! (
586
- "The following image formats are supported by the {}: {}" ,
587
- self . chip,
588
- self . supported_formats( )
589
- ) ) )
590
- }
591
- }
592
- }
593
-
594
498
pub ( crate ) trait ResultExt {
595
499
/// Mark an error as having occurred during the flashing stage
596
500
fn flashing ( self ) -> Self ;
0 commit comments