creek_core/write/error.rs
1use std::error::Error;
2
3/// A fatal error occurred and the stream cannot continue.
4#[derive(Debug)]
5pub enum FatalWriteError<FatalEncoderError: Error> {
6 /// The stream is closed and thus cannot continue.
7 StreamClosed,
8 /// A fatal encoder error occurred. The stream cannot continue.
9 EncoderError(FatalEncoderError),
10}
11
12/// An error writing the file.
13#[derive(Debug)]
14pub enum WriteError<FatalEncoderError: Error> {
15 /// A fatal error occurred. The stream cannot continue.
16 FatalError(FatalWriteError<FatalEncoderError>),
17 /// There are no more blocks left in the buffer because the server was
18 /// too slow writing previous ones. Make sure there are enough write blocks
19 /// available to the stream.
20 ///
21 /// In theory this should not happen, but if it does, try writing again
22 /// later.
23 ///
24 /// If this is returned, then no data in the given buffer will be written
25 /// to the file.
26 Underflow,
27 /// The given buffer is too long. The length of the buffer cannot exceed
28 /// `block_size`. The value of `block_size` can be retrieved using
29 /// `WriteDiskStream::block_size()`.
30 ///
31 /// If this is returned, then no data in the given buffer will be written
32 /// to the file.
33 BufferTooLong {
34 buffer_len: usize,
35 block_size: usize,
36 },
37 /// The given buffer does not match the internal layout of the stream. Check
38 /// that the number of channels in both are the same.
39 ///
40 /// If this is returned, then no data in the given buffer will be written
41 /// to the file.
42 InvalidBuffer,
43 /// The message channel to the IO server was full.
44 ///
45 /// In theory this should not happen, but if it does, try writing again
46 /// later.
47 ///
48 /// If this is returned, then no data in the given buffer will be written
49 /// to the file.
50 IOServerChannelFull,
51}
52
53impl<FatalError: Error> std::error::Error for WriteError<FatalError> {}
54
55impl<FatalError: Error> std::fmt::Display for WriteError<FatalError> {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 match self {
58 WriteError::FatalError(e) => {
59 match e {
60 FatalWriteError::StreamClosed => write!(f, "Fatal error: stream is closed"),
61 FatalWriteError::EncoderError(ee) => write!(f, "Fatal encoder error: {:?}", ee),
62 }
63 }
64 WriteError::Underflow => write!(f, "Data could not be written because there are no more blocks left in the pool. Please make sure the number of write blocks allocated to this stream is sufficiently large enough."),
65 WriteError::BufferTooLong { buffer_len, block_size } => write!(f, "Buffer with len {} is longer than the block size {}", buffer_len, block_size),
66 WriteError::InvalidBuffer => write!(f, "Buffer does not match internal buffer layout"),
67 WriteError::IOServerChannelFull => write!(f, "The message channel to the IO server is full."),
68 }
69 }
70}