Skip to content

Commit

Permalink
simplify error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-1 committed Apr 22, 2022
1 parent 7cdd417 commit 248f752
Show file tree
Hide file tree
Showing 131 changed files with 28 additions and 17 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .gitpod.yml
100644 → 100755
Empty file.
Empty file modified .vscode/settings.json
100644 → 100755
Empty file.
Empty file modified Cargo.lock
100644 → 100755
Empty file.
Empty file modified Cargo.toml
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified azalea-auth/Cargo.toml
100644 → 100755
Empty file.
Empty file modified azalea-auth/src/game_profile.rs
100644 → 100755
Empty file.
Empty file modified azalea-auth/src/lib.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/Cargo.toml
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/README.md
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/arguments/argument_type.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/arguments/integer_argument_type.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/arguments/mod.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/builder/argument_builder.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/builder/literal_argument_builder.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/builder/mod.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/builder/required_argument_builder.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/command_dispatcher.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/context/command_context.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/context/command_context_builder.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/context/mod.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/context/parsed_argument.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/context/parsed_command_node.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/context/string_range.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/exceptions/builtin_exceptions.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/exceptions/command_syntax_exception.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/exceptions/mod.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/lib.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/message.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/modifier.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/parse_results.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/string_reader.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/src/tree/mod.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/arguments/bool_argument_type_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/arguments/double_argument_type_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/arguments/float_argument_type_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/arguments/integer_argument_type_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/arguments/long_argument_type_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/arguments/string_argument_type_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/builder/argument_builder_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/builder/literal_argument_builder_test.rs
100644 → 100755
Empty file.
Empty file.
Empty file modified azalea-brigadier/tests/command_dispatcher_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/command_dispatcher_usages_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/command_suggestions_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/context/command_context_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/context/parsed_argument_test.rs
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file modified azalea-brigadier/tests/string_reader_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/suggestion/suggestion_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/suggestion/suggestions_builder_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/suggestion/suggestions_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/tree/abstract_command_node_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/tree/argument_command_node_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/tree/literal_command_node_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-brigadier/tests/tree/root_command_node_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-chat/Cargo.toml
100644 → 100755
Empty file.
Empty file modified azalea-chat/README.md
100644 → 100755
Empty file.
Empty file modified azalea-chat/src/base_component.rs
100644 → 100755
Empty file.
Empty file modified azalea-chat/src/component.rs
100644 → 100755
Empty file.
Empty file modified azalea-chat/src/events.rs
100644 → 100755
Empty file.
Empty file modified azalea-chat/src/lib.rs
100644 → 100755
Empty file.
Empty file modified azalea-chat/src/style.rs
100644 → 100755
Empty file.
Empty file modified azalea-chat/src/text_component.rs
100644 → 100755
Empty file.
Empty file modified azalea-chat/src/translatable_component.rs
100644 → 100755
Empty file.
Empty file modified azalea-chat/tests/integration_test.rs
100644 → 100755
Empty file.
Empty file modified azalea-client/Cargo.toml
100644 → 100755
Empty file.
Empty file modified azalea-client/README.md
100644 → 100755
Empty file.
Empty file modified azalea-client/src/connect.rs
100644 → 100755
Empty file.
Empty file modified azalea-client/src/crypt.rs
100644 → 100755
Empty file.
Empty file modified azalea-client/src/lib.rs
100644 → 100755
Empty file.
Empty file modified azalea-client/src/ping.rs
100644 → 100755
Empty file.
Empty file modified azalea-core/Cargo.toml
100644 → 100755
Empty file.
Empty file modified azalea-core/src/difficulty.rs
100644 → 100755
Empty file.
Empty file modified azalea-core/src/game_type.rs
100644 → 100755
Empty file.
Empty file modified azalea-core/src/lib.rs
100644 → 100755
Empty file.
Empty file modified azalea-core/src/resource_location.rs
100644 → 100755
Empty file.
Empty file modified azalea-core/src/serializable_uuid.rs
100644 → 100755
Empty file.
Empty file modified azalea-nbt/Cargo.toml
100644 → 100755
Empty file.
Empty file modified azalea-nbt/README.md
100644 → 100755
Empty file.
Empty file modified azalea-nbt/benches/my_benchmark.rs
100644 → 100755
Empty file.
34 changes: 17 additions & 17 deletions azalea-nbt/src/decode.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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?);
Expand All @@ -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)
}
Expand Down
Empty file modified azalea-nbt/src/encode.rs
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions azalea-nbt/src/error.rs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Empty file modified azalea-nbt/src/lib.rs
100644 → 100755
Empty file.
Empty file modified azalea-nbt/src/tag.rs
100644 → 100755
Empty file.
Empty file modified azalea-nbt/tests/bigtest.nbt
100644 → 100755
Empty file.
Empty file modified azalea-nbt/tests/complex_player.dat
100644 → 100755
Empty file.
Empty file modified azalea-nbt/tests/hello_world.nbt
100644 → 100755
Empty file.
Empty file modified azalea-nbt/tests/inttest.nbt
100644 → 100755
Empty file.
Empty file modified azalea-nbt/tests/level.dat
100644 → 100755
Empty file.
Empty file modified azalea-nbt/tests/simple_player.dat
100644 → 100755
Empty file.
Empty file modified azalea-nbt/tests/stringtest.nbt
100644 → 100755
Empty file.
Empty file modified azalea-nbt/tests/tests.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/Cargo.toml
100644 → 100755
Empty file.
Empty file modified azalea-protocol/README.md
100644 → 100755
Empty file.
Empty file modified azalea-protocol/packet-macros/Cargo.toml
100644 → 100755
Empty file.
Empty file modified azalea-protocol/packet-macros/src/lib.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/src/connect.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/src/lib.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/src/mc_buf/mod.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/src/mc_buf/read.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/src/mc_buf/write.rs
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified azalea-protocol/src/packets/game/clientbound_login_packet.rs
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file modified azalea-protocol/src/packets/game/mod.rs
100644 → 100755
Empty file.
Empty file.
Empty file modified azalea-protocol/src/packets/handshake/mod.rs
100644 → 100755
Empty file.
Empty file.
Empty file.
Empty file modified azalea-protocol/src/packets/login/clientbound_hello_packet.rs
100644 → 100755
Empty file.
Empty file.
Empty file modified azalea-protocol/src/packets/login/mod.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/src/packets/login/serverbound_hello_packet.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/src/packets/mod.rs
100644 → 100755
Empty file.
Empty file.
Empty file modified azalea-protocol/src/packets/status/mod.rs
100644 → 100755
Empty file.
Empty file.
Empty file modified azalea-protocol/src/read.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/src/resolver.rs
100644 → 100755
Empty file.
Empty file modified azalea-protocol/src/write.rs
100644 → 100755
Empty file.
Empty file modified bot/Cargo.toml
100644 → 100755
Empty file.
Empty file modified bot/src/main.rs
100644 → 100755
Empty file.

0 comments on commit 248f752

Please sign in to comment.