mirror of
https://github.com/mat-1/azalea.git
synced 2024-11-04 16:34:00 +00:00
simplify error handling
This commit is contained in:
parent
7cdd417145
commit
248f752748
131 changed files with 28 additions and 17 deletions
0
.gitignore
vendored
Normal file → Executable file
0
.gitignore
vendored
Normal file → Executable file
0
.gitpod.yml
Normal file → Executable file
0
.gitpod.yml
Normal file → Executable file
0
.vscode/settings.json
vendored
Normal file → Executable file
0
.vscode/settings.json
vendored
Normal file → Executable file
0
Cargo.lock
generated
Normal file → Executable file
0
Cargo.lock
generated
Normal file → Executable file
0
Cargo.toml
Normal file → Executable file
0
Cargo.toml
Normal file → Executable file
0
README.md
Normal file → Executable file
0
README.md
Normal file → Executable file
0
azalea-auth/Cargo.toml
Normal file → Executable file
0
azalea-auth/Cargo.toml
Normal file → Executable file
0
azalea-auth/src/game_profile.rs
Normal file → Executable file
0
azalea-auth/src/game_profile.rs
Normal file → Executable file
0
azalea-auth/src/lib.rs
Normal file → Executable file
0
azalea-auth/src/lib.rs
Normal file → Executable file
0
azalea-brigadier/Cargo.toml
Normal file → Executable file
0
azalea-brigadier/Cargo.toml
Normal file → Executable file
0
azalea-brigadier/README.md
Normal file → Executable file
0
azalea-brigadier/README.md
Normal file → Executable file
0
azalea-brigadier/src/arguments/argument_type.rs
Normal file → Executable file
0
azalea-brigadier/src/arguments/argument_type.rs
Normal file → Executable file
0
azalea-brigadier/src/arguments/integer_argument_type.rs
Normal file → Executable file
0
azalea-brigadier/src/arguments/integer_argument_type.rs
Normal file → Executable file
0
azalea-brigadier/src/arguments/mod.rs
Normal file → Executable file
0
azalea-brigadier/src/arguments/mod.rs
Normal file → Executable file
0
azalea-brigadier/src/builder/argument_builder.rs
Normal file → Executable file
0
azalea-brigadier/src/builder/argument_builder.rs
Normal file → Executable file
0
azalea-brigadier/src/builder/literal_argument_builder.rs
Normal file → Executable file
0
azalea-brigadier/src/builder/literal_argument_builder.rs
Normal file → Executable file
0
azalea-brigadier/src/builder/mod.rs
Normal file → Executable file
0
azalea-brigadier/src/builder/mod.rs
Normal file → Executable file
0
azalea-brigadier/src/builder/required_argument_builder.rs
Normal file → Executable file
0
azalea-brigadier/src/builder/required_argument_builder.rs
Normal file → Executable file
0
azalea-brigadier/src/command_dispatcher.rs
Normal file → Executable file
0
azalea-brigadier/src/command_dispatcher.rs
Normal file → Executable file
0
azalea-brigadier/src/context/command_context.rs
Normal file → Executable file
0
azalea-brigadier/src/context/command_context.rs
Normal file → Executable file
0
azalea-brigadier/src/context/command_context_builder.rs
Normal file → Executable file
0
azalea-brigadier/src/context/command_context_builder.rs
Normal file → Executable file
0
azalea-brigadier/src/context/mod.rs
Normal file → Executable file
0
azalea-brigadier/src/context/mod.rs
Normal file → Executable file
0
azalea-brigadier/src/context/parsed_argument.rs
Normal file → Executable file
0
azalea-brigadier/src/context/parsed_argument.rs
Normal file → Executable file
0
azalea-brigadier/src/context/parsed_command_node.rs
Normal file → Executable file
0
azalea-brigadier/src/context/parsed_command_node.rs
Normal file → Executable file
0
azalea-brigadier/src/context/string_range.rs
Normal file → Executable file
0
azalea-brigadier/src/context/string_range.rs
Normal file → Executable file
0
azalea-brigadier/src/exceptions/builtin_exceptions.rs
Normal file → Executable file
0
azalea-brigadier/src/exceptions/builtin_exceptions.rs
Normal file → Executable file
0
azalea-brigadier/src/exceptions/command_syntax_exception.rs
Normal file → Executable file
0
azalea-brigadier/src/exceptions/command_syntax_exception.rs
Normal file → Executable file
0
azalea-brigadier/src/exceptions/mod.rs
Normal file → Executable file
0
azalea-brigadier/src/exceptions/mod.rs
Normal file → Executable file
0
azalea-brigadier/src/lib.rs
Normal file → Executable file
0
azalea-brigadier/src/lib.rs
Normal file → Executable file
0
azalea-brigadier/src/message.rs
Normal file → Executable file
0
azalea-brigadier/src/message.rs
Normal file → Executable file
0
azalea-brigadier/src/modifier.rs
Normal file → Executable file
0
azalea-brigadier/src/modifier.rs
Normal file → Executable file
0
azalea-brigadier/src/parse_results.rs
Normal file → Executable file
0
azalea-brigadier/src/parse_results.rs
Normal file → Executable file
0
azalea-brigadier/src/string_reader.rs
Normal file → Executable file
0
azalea-brigadier/src/string_reader.rs
Normal file → Executable file
0
azalea-brigadier/src/tree/mod.rs
Normal file → Executable file
0
azalea-brigadier/src/tree/mod.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/bool_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/bool_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/double_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/double_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/float_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/float_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/integer_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/integer_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/long_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/long_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/string_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/arguments/string_argument_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/builder/argument_builder_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/builder/argument_builder_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/builder/literal_argument_builder_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/builder/literal_argument_builder_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/builder/required_argument_builder_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/builder/required_argument_builder_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/command_dispatcher_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/command_dispatcher_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/command_dispatcher_usages_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/command_dispatcher_usages_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/command_suggestions_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/command_suggestions_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/context/command_context_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/context/command_context_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/context/parsed_argument_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/context/parsed_argument_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/exceptions/dynamic_command_syntax_exception_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/exceptions/dynamic_command_syntax_exception_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/exceptions/simple_command_syntax_exception_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/exceptions/simple_command_syntax_exception_type_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/string_reader_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/string_reader_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/suggestion/suggestion_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/suggestion/suggestion_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/suggestion/suggestions_builder_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/suggestion/suggestions_builder_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/suggestion/suggestions_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/suggestion/suggestions_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/tree/abstract_command_node_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/tree/abstract_command_node_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/tree/argument_command_node_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/tree/argument_command_node_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/tree/literal_command_node_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/tree/literal_command_node_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/tree/root_command_node_test.rs
Normal file → Executable file
0
azalea-brigadier/tests/tree/root_command_node_test.rs
Normal file → Executable file
0
azalea-chat/Cargo.toml
Normal file → Executable file
0
azalea-chat/Cargo.toml
Normal file → Executable file
0
azalea-chat/README.md
Normal file → Executable file
0
azalea-chat/README.md
Normal file → Executable file
0
azalea-chat/src/base_component.rs
Normal file → Executable file
0
azalea-chat/src/base_component.rs
Normal file → Executable file
0
azalea-chat/src/component.rs
Normal file → Executable file
0
azalea-chat/src/component.rs
Normal file → Executable file
0
azalea-chat/src/events.rs
Normal file → Executable file
0
azalea-chat/src/events.rs
Normal file → Executable file
0
azalea-chat/src/lib.rs
Normal file → Executable file
0
azalea-chat/src/lib.rs
Normal file → Executable file
0
azalea-chat/src/style.rs
Normal file → Executable file
0
azalea-chat/src/style.rs
Normal file → Executable file
0
azalea-chat/src/text_component.rs
Normal file → Executable file
0
azalea-chat/src/text_component.rs
Normal file → Executable file
0
azalea-chat/src/translatable_component.rs
Normal file → Executable file
0
azalea-chat/src/translatable_component.rs
Normal file → Executable file
0
azalea-chat/tests/integration_test.rs
Normal file → Executable file
0
azalea-chat/tests/integration_test.rs
Normal file → Executable file
0
azalea-client/Cargo.toml
Normal file → Executable file
0
azalea-client/Cargo.toml
Normal file → Executable file
0
azalea-client/README.md
Normal file → Executable file
0
azalea-client/README.md
Normal file → Executable file
0
azalea-client/src/connect.rs
Normal file → Executable file
0
azalea-client/src/connect.rs
Normal file → Executable file
0
azalea-client/src/crypt.rs
Normal file → Executable file
0
azalea-client/src/crypt.rs
Normal file → Executable file
0
azalea-client/src/lib.rs
Normal file → Executable file
0
azalea-client/src/lib.rs
Normal file → Executable file
0
azalea-client/src/ping.rs
Normal file → Executable file
0
azalea-client/src/ping.rs
Normal file → Executable file
0
azalea-core/Cargo.toml
Normal file → Executable file
0
azalea-core/Cargo.toml
Normal file → Executable file
0
azalea-core/src/difficulty.rs
Normal file → Executable file
0
azalea-core/src/difficulty.rs
Normal file → Executable file
0
azalea-core/src/game_type.rs
Normal file → Executable file
0
azalea-core/src/game_type.rs
Normal file → Executable file
0
azalea-core/src/lib.rs
Normal file → Executable file
0
azalea-core/src/lib.rs
Normal file → Executable file
0
azalea-core/src/resource_location.rs
Normal file → Executable file
0
azalea-core/src/resource_location.rs
Normal file → Executable file
0
azalea-core/src/serializable_uuid.rs
Normal file → Executable file
0
azalea-core/src/serializable_uuid.rs
Normal file → Executable file
0
azalea-nbt/Cargo.toml
Normal file → Executable file
0
azalea-nbt/Cargo.toml
Normal file → Executable file
0
azalea-nbt/README.md
Normal file → Executable file
0
azalea-nbt/README.md
Normal file → Executable file
0
azalea-nbt/benches/my_benchmark.rs
Normal file → Executable file
0
azalea-nbt/benches/my_benchmark.rs
Normal file → Executable file
34
azalea-nbt/src/decode.rs
Normal file → Executable file
34
azalea-nbt/src/decode.rs
Normal file → Executable file
|
@ -11,13 +11,13 @@ async fn read_string<R>(stream: &mut R) -> Result<String, Error>
|
|||
where
|
||||
R: AsyncRead + std::marker::Unpin,
|
||||
{
|
||||
let length = stream.read_u16().await.map_err(|_| Error::InvalidTag)?;
|
||||
let length = stream.read_u16().await?;
|
||||
|
||||
let mut buf = Vec::with_capacity(length as usize);
|
||||
for _ in 0..length {
|
||||
buf.push(stream.read_u8().await.map_err(|_| Error::InvalidTag)?);
|
||||
buf.push(stream.read_u8().await?);
|
||||
}
|
||||
String::from_utf8(buf).map_err(|_| Error::InvalidTag)
|
||||
Ok(String::from_utf8(buf)?)
|
||||
}
|
||||
|
||||
impl Tag {
|
||||
|
@ -31,26 +31,26 @@ impl Tag {
|
|||
// a TAG_Compound, and is not named despite being in a TAG_Compound
|
||||
0 => Tag::End,
|
||||
// A single signed byte
|
||||
1 => Tag::Byte(stream.read_i8().await.map_err(|_| Error::InvalidTag)?),
|
||||
1 => Tag::Byte(stream.read_i8().await?),
|
||||
// A single signed, big endian 16 bit integer
|
||||
2 => Tag::Short(stream.read_i16().await.map_err(|_| Error::InvalidTag)?),
|
||||
2 => Tag::Short(stream.read_i16().await?),
|
||||
// A single signed, big endian 32 bit integer
|
||||
3 => Tag::Int(stream.read_i32().await.map_err(|_| Error::InvalidTag)?),
|
||||
3 => Tag::Int(stream.read_i32().await?),
|
||||
// A single signed, big endian 64 bit integer
|
||||
4 => Tag::Long(stream.read_i64().await.map_err(|_| Error::InvalidTag)?),
|
||||
4 => Tag::Long(stream.read_i64().await?),
|
||||
// A single, big endian IEEE-754 single-precision floating point
|
||||
// number (NaN possible)
|
||||
5 => Tag::Float(stream.read_f32().await.map_err(|_| Error::InvalidTag)?),
|
||||
5 => Tag::Float(stream.read_f32().await?),
|
||||
// A single, big endian IEEE-754 double-precision floating point
|
||||
// number (NaN possible)
|
||||
6 => Tag::Double(stream.read_f64().await.map_err(|_| Error::InvalidTag)?),
|
||||
6 => Tag::Double(stream.read_f64().await?),
|
||||
// A length-prefixed array of signed bytes. The prefix is a signed
|
||||
// integer (thus 4 bytes)
|
||||
7 => {
|
||||
let length = stream.read_i32().await.map_err(|_| Error::InvalidTag)?;
|
||||
let length = stream.read_i32().await?;
|
||||
let mut bytes = Vec::with_capacity(length as usize);
|
||||
for _ in 0..length {
|
||||
bytes.push(stream.read_i8().await.map_err(|_| Error::InvalidTag)?);
|
||||
bytes.push(stream.read_i8().await?);
|
||||
}
|
||||
Tag::ByteArray(bytes)
|
||||
}
|
||||
|
@ -67,8 +67,8 @@ impl Tag {
|
|||
// another reference implementation by Mojang uses 1 instead;
|
||||
// parsers should accept any type if the length is <= 0).
|
||||
9 => {
|
||||
let type_id = stream.read_u8().await.map_err(|_| Error::InvalidTag)?;
|
||||
let length = stream.read_i32().await.map_err(|_| Error::InvalidTag)?;
|
||||
let type_id = stream.read_u8().await?;
|
||||
let length = stream.read_i32().await?;
|
||||
let mut list = Vec::with_capacity(length as usize);
|
||||
for _ in 0..length {
|
||||
list.push(Tag::read_known(stream, type_id).await?);
|
||||
|
@ -94,20 +94,20 @@ impl Tag {
|
|||
// signed integer (thus 4 bytes) and indicates the number of 4 byte
|
||||
// integers.
|
||||
11 => {
|
||||
let length = stream.read_i32().await.map_err(|_| Error::InvalidTag)?;
|
||||
let length = stream.read_i32().await?;
|
||||
let mut ints = Vec::with_capacity(length as usize);
|
||||
for _ in 0..length {
|
||||
ints.push(stream.read_i32().await.map_err(|_| Error::InvalidTag)?);
|
||||
ints.push(stream.read_i32().await?);
|
||||
}
|
||||
Tag::IntArray(ints)
|
||||
}
|
||||
// A length-prefixed array of signed longs. The prefix is a signed
|
||||
// integer (thus 4 bytes) and indicates the number of 8 byte longs.
|
||||
12 => {
|
||||
let length = stream.read_i32().await.map_err(|_| Error::InvalidTag)?;
|
||||
let length = stream.read_i32().await?;
|
||||
let mut longs = Vec::with_capacity(length as usize);
|
||||
for _ in 0..length {
|
||||
longs.push(stream.read_i64().await.map_err(|_| Error::InvalidTag)?);
|
||||
longs.push(stream.read_i64().await?);
|
||||
}
|
||||
Tag::LongArray(longs)
|
||||
}
|
||||
|
|
0
azalea-nbt/src/encode.rs
Normal file → Executable file
0
azalea-nbt/src/encode.rs
Normal file → Executable file
11
azalea-nbt/src/error.rs
Normal file → Executable file
11
azalea-nbt/src/error.rs
Normal file → Executable file
|
@ -14,3 +14,14 @@ impl std::fmt::Display for Error {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for Error {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Error::WriteError
|
||||
}
|
||||
}
|
||||
impl From<std::string::FromUtf8Error> for Error {
|
||||
fn from(err: std::string::FromUtf8Error) -> Self {
|
||||
Error::WriteError
|
||||
}
|
||||
}
|
0
azalea-nbt/src/lib.rs
Normal file → Executable file
0
azalea-nbt/src/lib.rs
Normal file → Executable file
0
azalea-nbt/src/tag.rs
Normal file → Executable file
0
azalea-nbt/src/tag.rs
Normal file → Executable file
0
azalea-nbt/tests/bigtest.nbt
Normal file → Executable file
0
azalea-nbt/tests/bigtest.nbt
Normal file → Executable file
0
azalea-nbt/tests/complex_player.dat
Normal file → Executable file
0
azalea-nbt/tests/complex_player.dat
Normal file → Executable file
0
azalea-nbt/tests/hello_world.nbt
Normal file → Executable file
0
azalea-nbt/tests/hello_world.nbt
Normal file → Executable file
0
azalea-nbt/tests/inttest.nbt
Normal file → Executable file
0
azalea-nbt/tests/inttest.nbt
Normal file → Executable file
0
azalea-nbt/tests/level.dat
Normal file → Executable file
0
azalea-nbt/tests/level.dat
Normal file → Executable file
0
azalea-nbt/tests/simple_player.dat
Normal file → Executable file
0
azalea-nbt/tests/simple_player.dat
Normal file → Executable file
0
azalea-nbt/tests/stringtest.nbt
Normal file → Executable file
0
azalea-nbt/tests/stringtest.nbt
Normal file → Executable file
0
azalea-nbt/tests/tests.rs
Normal file → Executable file
0
azalea-nbt/tests/tests.rs
Normal file → Executable file
0
azalea-protocol/Cargo.toml
Normal file → Executable file
0
azalea-protocol/Cargo.toml
Normal file → Executable file
0
azalea-protocol/README.md
Normal file → Executable file
0
azalea-protocol/README.md
Normal file → Executable file
0
azalea-protocol/packet-macros/Cargo.toml
Normal file → Executable file
0
azalea-protocol/packet-macros/Cargo.toml
Normal file → Executable file
0
azalea-protocol/packet-macros/src/lib.rs
Normal file → Executable file
0
azalea-protocol/packet-macros/src/lib.rs
Normal file → Executable file
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue