@@ -158,77 +158,107 @@ macro_rules! warn {
158158
159159/// All the ways the functions in this crate can fail.
160160#[ cfg_attr( feature = "defmt-log" , derive( defmt:: Format ) ) ]
161- #[ derive( Debug , Clone ) ]
161+ #[ derive( Debug , Clone , thiserror :: Error ) ]
162162pub enum Error < E >
163163where
164- E : core:: fmt :: Debug ,
164+ E : core:: error :: Error ,
165165{
166166 /// The underlying block device threw an error.
167- DeviceError ( E ) ,
167+ #[ error( "error from underlying block device: {0}" ) ]
168+ DeviceError ( #[ from] E ) ,
168169 /// The filesystem is badly formatted (or this code is buggy).
170+ #[ error( "filesystem is badly formatted: {0}" ) ]
169171 FormatError ( & ' static str ) ,
170172 /// The given `VolumeIdx` was bad,
173+ #[ error( "no such volume" ) ]
171174 NoSuchVolume ,
172175 /// The given filename was bad
176+ #[ error( "bad filename" ) ]
173177 FilenameError ( FilenameError ) ,
174178 /// Out of memory opening volumes
179+ #[ error( "too many open volumes" ) ]
175180 TooManyOpenVolumes ,
176181 /// Out of memory opening directories
182+ #[ error( "too many open directories" ) ]
177183 TooManyOpenDirs ,
178184 /// Out of memory opening files
185+ #[ error( "too many open files" ) ]
179186 TooManyOpenFiles ,
180187 /// Bad handle given
188+ #[ error( "bad handle" ) ]
181189 BadHandle ,
182190 /// That file or directory doesn't exist
191+ #[ error( "file or directory does not exist" ) ]
183192 NotFound ,
184193 /// You can't open a file twice or delete an open file
194+ #[ error( "file already open" ) ]
185195 FileAlreadyOpen ,
186196 /// You can't open a directory twice
197+ #[ error( "directory already open" ) ]
187198 DirAlreadyOpen ,
188199 /// You can't open a directory as a file
200+ #[ error( "cannot open directory as file" ) ]
189201 OpenedDirAsFile ,
190202 /// You can't open a file as a directory
203+ #[ error( "cannot open file as directory" ) ]
191204 OpenedFileAsDir ,
192205 /// You can't delete a non-empty directory
206+ #[ error( "cannot delete a non-empty directory" ) ]
193207 DeleteNonEmptyDir ,
194208 /// You can't close a volume with open files or directories
209+ #[ error( "volume is still in use" ) ]
195210 VolumeStillInUse ,
196211 /// You can't open a volume twice
212+ #[ error( "cannot open volume twice" ) ]
197213 VolumeAlreadyOpen ,
198214 /// We can't do that yet
215+ #[ error( "unsupported operation" ) ]
199216 Unsupported ,
200217 /// Tried to read beyond end of file
218+ #[ error( "end of file" ) ]
201219 EndOfFile ,
202220 /// Found a bad cluster
221+ #[ error( "bad cluster" ) ]
203222 BadCluster ,
204223 /// Error while converting types
224+ #[ error( "type conversion failed" ) ]
205225 ConversionError ,
206226 /// The device does not have enough space for the operation
227+ #[ error( "not enough space on device" ) ]
207228 NotEnoughSpace ,
208229 /// Cluster was not properly allocated by the library
230+ #[ error( "cluster not properly allocated" ) ]
209231 AllocationError ,
210232 /// Jumped to free space during FAT traversing
233+ #[ error( "FAT chain unterminated" ) ]
211234 UnterminatedFatChain ,
212235 /// Tried to open Read-Only file with write mode
236+ #[ error( "file is read-only" ) ]
213237 ReadOnly ,
214238 /// Tried to create an existing file
239+ #[ error( "file already exists" ) ]
215240 FileAlreadyExists ,
216241 /// Bad block size - only 512 byte blocks supported
242+ #[ error( "bad block size: {0} (only 512 byte blocks supported)" ) ]
217243 BadBlockSize ( u16 ) ,
218244 /// Bad offset given when seeking
245+ #[ error( "invalid seek offset" ) ]
219246 InvalidOffset ,
220247 /// Disk is full
248+ #[ error( "disk full" ) ]
221249 DiskFull ,
222250 /// A directory with that name already exists
251+ #[ error( "directory already exists" ) ]
223252 DirAlreadyExists ,
224253 /// The filesystem tried to gain a lock whilst already locked.
225254 ///
226255 /// This is either a bug in the filesystem, or you tried to access the
227256 /// filesystem API from inside a directory iterator (that isn't allowed).
257+ #[ error( "already locked" ) ]
228258 LockError ,
229259}
230260
231- impl < E : Debug > embedded_io:: Error for Error < E > {
261+ impl < E : core :: error :: Error + ' static > embedded_io:: Error for Error < E > {
232262 fn kind ( & self ) -> ErrorKind {
233263 match self {
234264 Error :: DeviceError ( _)
@@ -263,59 +293,6 @@ impl<E: Debug> embedded_io::Error for Error<E> {
263293 }
264294}
265295
266- impl < E > From < E > for Error < E >
267- where
268- E : core:: fmt:: Debug ,
269- {
270- fn from ( value : E ) -> Error < E > {
271- Error :: DeviceError ( value)
272- }
273- }
274-
275- impl < E > core:: fmt:: Display for Error < E >
276- where
277- E : core:: fmt:: Debug + core:: fmt:: Display ,
278- {
279- fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
280- match self {
281- Error :: DeviceError ( e) => write ! ( f, "error from underlying block device: {e}" ) ,
282- Error :: FormatError ( s) => write ! ( f, "filesystem is badly formatted: {s}" ) ,
283- Error :: NoSuchVolume => write ! ( f, "no such volume" ) ,
284- Error :: FilenameError ( _) => write ! ( f, "bad filename" ) ,
285- Error :: TooManyOpenVolumes => write ! ( f, "too many open volumes" ) ,
286- Error :: TooManyOpenDirs => write ! ( f, "too many open directories" ) ,
287- Error :: TooManyOpenFiles => write ! ( f, "too many open files" ) ,
288- Error :: BadHandle => write ! ( f, "bad handle" ) ,
289- Error :: NotFound => write ! ( f, "file or directory does not exist" ) ,
290- Error :: FileAlreadyOpen => write ! ( f, "file already open" ) ,
291- Error :: DirAlreadyOpen => write ! ( f, "directory already open" ) ,
292- Error :: OpenedDirAsFile => write ! ( f, "cannot open directory as file" ) ,
293- Error :: OpenedFileAsDir => write ! ( f, "cannot open file as directory" ) ,
294- Error :: DeleteNonEmptyDir => write ! ( f, "cannot delete a non-empty directory" ) ,
295- Error :: VolumeStillInUse => write ! ( f, "volume is still in use" ) ,
296- Error :: VolumeAlreadyOpen => write ! ( f, "cannot open volume twice" ) ,
297- Error :: Unsupported => write ! ( f, "unsupported operation" ) ,
298- Error :: EndOfFile => write ! ( f, "end of file" ) ,
299- Error :: BadCluster => write ! ( f, "bad cluster" ) ,
300- Error :: ConversionError => write ! ( f, "type conversion failed" ) ,
301- Error :: NotEnoughSpace => write ! ( f, "not enough space on device" ) ,
302- Error :: AllocationError => write ! ( f, "cluster not properly allocated" ) ,
303- Error :: UnterminatedFatChain => write ! ( f, "FAT chain unterminated" ) ,
304- Error :: ReadOnly => write ! ( f, "file is read-only" ) ,
305- Error :: FileAlreadyExists => write ! ( f, "file already exists" ) ,
306- Error :: BadBlockSize ( size) => {
307- write ! ( f, "bad block size: {size} (only 512 byte blocks supported)" )
308- }
309- Error :: InvalidOffset => write ! ( f, "invalid seek offset" ) ,
310- Error :: DiskFull => write ! ( f, "disk full" ) ,
311- Error :: DirAlreadyExists => write ! ( f, "directory already exists" ) ,
312- Error :: LockError => write ! ( f, "already locked" ) ,
313- }
314- }
315- }
316-
317- impl < E > core:: error:: Error for Error < E > where E : core:: fmt:: Debug + core:: fmt:: Display { }
318-
319296/// A handle to a volume.
320297///
321298/// A volume is a partition with a filesystem within it.
0 commit comments