@@ -5,20 +5,22 @@ 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
+ #[ cfg( feature = "cli" ) ]
9
+ use crate :: cli:: monitor:: parser:: esp_defmt:: DefmtError ;
10
+ #[ cfg( feature = "serialport" ) ]
11
+ use crate :: interface:: SerialConfigError ;
13
12
use crate :: {
14
- cli:: monitor:: parser:: esp_defmt:: DefmtError ,
15
13
command:: CommandType ,
16
14
flasher:: { FlashFrequency , FlashSize } ,
17
15
image_format:: ImageFormatKind ,
18
- interface:: SerialConfigError ,
19
16
targets:: Chip ,
20
17
} ;
21
18
19
+ use miette:: Diagnostic ;
20
+ use slip_codec:: SlipError ;
21
+ use strum:: { FromRepr , VariantNames } ;
22
+ use thiserror:: Error ;
23
+
22
24
/// All possible errors returned by espflash
23
25
#[ derive( Debug , Diagnostic , Error ) ]
24
26
#[ non_exhaustive]
@@ -88,6 +90,10 @@ pub enum Error {
88
90
) ]
89
91
InvalidFlashSize ( String ) ,
90
92
93
+ #[ cfg( not( feature = "serialport" ) ) ]
94
+ #[ error( transparent) ]
95
+ IoError ( #[ from] std:: io:: Error ) ,
96
+
91
97
#[ error( "No serial ports could be detected" ) ]
92
98
#[ diagnostic(
93
99
code( espflash:: no_serial) ,
@@ -102,6 +108,7 @@ pub enum Error {
102
108
) ]
103
109
StubRequiredToEraseFlash ,
104
110
111
+ #[ cfg( feature = "serialport" ) ]
105
112
#[ error( "Incorrect serial port configuration" ) ]
106
113
#[ diagnostic(
107
114
code( espflash:: serial_config) ,
@@ -176,6 +183,7 @@ pub enum Error {
176
183
#[ diagnostic( transparent) ]
177
184
UnsupportedImageFormat ( #[ from] UnsupportedImageFormatError ) ,
178
185
186
+ #[ cfg( feature = "serialport" ) ]
179
187
#[ error( transparent) ]
180
188
#[ diagnostic( transparent) ]
181
189
Defmt ( #[ from] DefmtError ) ,
@@ -188,6 +196,7 @@ pub enum Error {
188
196
InternalError ,
189
197
}
190
198
199
+ #[ cfg( feature = "serialport" ) ]
191
200
impl From < io:: Error > for Error {
192
201
fn from ( err : io:: Error ) -> Self {
193
202
Self :: Connection ( err. into ( ) )
@@ -202,12 +211,14 @@ impl From<serialport::Error> for Error {
202
211
}
203
212
}
204
213
214
+ #[ cfg( feature = "serialport" ) ]
205
215
impl From < SlipError > for Error {
206
216
fn from ( err : SlipError ) -> Self {
207
217
Self :: Connection ( err. into ( ) )
208
218
}
209
219
}
210
220
221
+ #[ cfg( feature = "serialport" ) ]
211
222
impl From < SerialConfigError > for Error {
212
223
fn from ( err : SerialConfigError ) -> Self {
213
224
Self :: SerialConfiguration ( err)
@@ -259,6 +270,7 @@ pub enum ConnectionError {
259
270
Serial ( #[ source] serialport:: Error ) ,
260
271
}
261
272
273
+ #[ cfg( feature = "serialport" ) ]
262
274
impl From < io:: Error > for ConnectionError {
263
275
fn from ( err : io:: Error ) -> Self {
264
276
from_error_kind ( err. kind ( ) , err)
@@ -279,6 +291,7 @@ impl From<serialport::Error> for ConnectionError {
279
291
}
280
292
}
281
293
294
+ #[ cfg( feature = "serialport" ) ]
282
295
impl From < SlipError > for ConnectionError {
283
296
fn from ( err : SlipError ) -> Self {
284
297
match err {
0 commit comments