anvil_region/error.rs
1use crate::position::RegionChunkPosition;
2use nbt::decode::TagDecodeError;
3use std::io;
4
5/// Possible errors while loading the chunk.
6#[derive(Debug)]
7pub enum ChunkReadError {
8 /// Chunk at specified coordinates inside region not found.
9 ChunkNotFound { position: RegionChunkPosition },
10 /// Chunk length overlaps declared maximum.
11 ///
12 /// This should not occur under normal conditions.
13 ///
14 /// Region file are corrupted.
15 LengthExceedsMaximum {
16 /// Chunk length.
17 length: u32,
18 /// Chunk maximum expected length.
19 maximum_length: u32,
20 },
21 /// Currently are only 2 types of compression: Gzip and Zlib.
22 ///
23 /// This should not occur under normal conditions.
24 ///
25 /// Region file are corrupted or was introduced new compression type.
26 UnsupportedCompressionScheme {
27 /// Compression scheme type id.
28 compression_scheme: u8,
29 },
30 /// I/O Error which happened while were reading chunk data from region file.
31 IOError { io_error: io::Error },
32 /// Error while decoding binary data to NBT tag.
33 ///
34 /// This should not occur under normal conditions.
35 ///
36 /// Region file are corrupted or a developer error in the NBT library.
37 TagDecodeError { tag_decode_error: TagDecodeError },
38}
39
40impl From<io::Error> for ChunkReadError {
41 fn from(io_error: io::Error) -> Self {
42 ChunkReadError::IOError { io_error }
43 }
44}
45
46impl From<TagDecodeError> for ChunkReadError {
47 fn from(tag_decode_error: TagDecodeError) -> Self {
48 ChunkReadError::TagDecodeError { tag_decode_error }
49 }
50}
51
52/// Possible errors while saving the chunk.
53#[derive(Debug)]
54pub enum ChunkWriteError {
55 /// Chunk length exceeds 1 MB.
56 ///
57 /// This should not occur under normal conditions.
58 LengthExceedsMaximum {
59 /// Chunk length.
60 length: u32,
61 },
62 /// I/O Error which happened while were writing chunk data to region.
63 IOError { io_error: io::Error },
64}
65
66impl From<io::Error> for ChunkWriteError {
67 fn from(io_error: io::Error) -> Self {
68 ChunkWriteError::IOError { io_error }
69 }
70}