enshort common error name

This commit is contained in:
yggverse 2024-11-30 04:05:31 +02:00
parent 809e54b887
commit a06e4e9eff
16 changed files with 49 additions and 49 deletions

View file

@ -37,7 +37,7 @@ impl Connection {
server_identity.as_ref(),
) {
Ok(tls_client_connection) => Some(tls_client_connection),
Err(reason) => return Err(reason),
Err(e) => return Err(e),
}
}
None => None,
@ -52,14 +52,14 @@ impl Connection {
pub fn close(&self, cancellable: Option<&Cancellable>) -> Result<(), Error> {
if let Some(ref tls_client_connection) = self.tls_client_connection {
if !tls_client_connection.is_closed() {
if let Err(reason) = tls_client_connection.close(cancellable) {
return Err(Error::TlsClientConnection(reason));
if let Err(e) = tls_client_connection.close(cancellable) {
return Err(Error::TlsClientConnection(e));
}
}
}
if !self.socket_connection.is_closed() {
if let Err(reason) = self.socket_connection.close(cancellable) {
return Err(Error::SocketConnection(reason));
if let Err(e) = self.socket_connection.close(cancellable) {
return Err(Error::SocketConnection(e));
}
}
Ok(())
@ -90,7 +90,7 @@ impl Connection {
self.server_identity.as_ref(),
) {
Ok(tls_client_connection) => Ok(tls_client_connection),
Err(reason) => Err(Error::TlsClientConnection(reason)),
Err(e) => Err(Error::TlsClientConnection(e)),
}
}
}
@ -99,7 +99,7 @@ impl Connection {
pub fn rehandshake(&self) -> Result<(), Error> {
match self.tls_client_connection()?.handshake(Cancellable::NONE) {
Ok(()) => Ok(()),
Err(reason) => Err(Error::Rehandshake(reason)),
Err(e) => Err(Error::Rehandshake(e)),
}
}
}
@ -131,6 +131,6 @@ pub fn new_tls_client_connection(
Ok(tls_client_connection)
}
Err(reason) => Err(Error::TlsClientConnection(reason)),
Err(e) => Err(Error::TlsClientConnection(e)),
}
}

View file

@ -29,7 +29,7 @@ impl Response {
Meta::from_stream_async(connection.stream(), priority, cancellable, |result| {
callback(match result {
Ok(meta) => Ok(Self { connection, meta }),
Err(reason) => Err(Error::Meta(reason)),
Err(e) => Err(Error::Meta(e)),
})
})
}

View file

@ -44,7 +44,7 @@ impl Text {
pub fn from_utf8(buffer: &[u8]) -> Result<Self, Error> {
match GString::from_utf8(buffer.into()) {
Ok(data) => Ok(Self::from_string(&data)),
Err(reason) => Err(Error::Decode(reason)),
Err(e) => Err(Error::Decode(e)),
}
}
@ -68,7 +68,7 @@ impl Text {
},
|result| match result {
Ok(buffer) => on_complete(Self::from_utf8(&buffer)),
Err(reason) => on_complete(Err(reason)),
Err(e) => on_complete(Err(e)),
},
);
}
@ -111,7 +111,7 @@ pub fn read_all_from_stream_async(
// Continue bytes reading
read_all_from_stream_async(buffer, stream, cancelable, priority, callback);
}
Err(reason) => callback(Err(Error::InputStream(reason))),
Err(e) => callback(Err(Error::InputStream(e))),
},
);
}

View file

@ -13,11 +13,11 @@ impl Display for Error {
Self::BufferOverflow => {
write!(f, "Buffer overflow")
}
Self::Decode(reason) => {
write!(f, "Decode error: {reason}")
Self::Decode(e) => {
write!(f, "Decode error: {e}")
}
Self::InputStream(reason) => {
write!(f, "Input stream read error: {reason}")
Self::InputStream(e) => {
write!(f, "Input stream read error: {e}")
}
}
}

View file

@ -9,8 +9,8 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Meta(reason) => {
write!(f, "Meta read error: {reason}")
Self::Meta(e) => {
write!(f, "Meta read error: {e}")
}
Self::Stream => {
write!(f, "I/O stream error")

View file

@ -45,24 +45,24 @@ impl Meta {
// Parse data
let data = Data::from_utf8(slice);
if let Err(reason) = data {
return Err(Error::Data(reason));
if let Err(e) = data {
return Err(Error::Data(e));
}
// MIME
let mime = Mime::from_utf8(slice);
if let Err(reason) = mime {
return Err(Error::Mime(reason));
if let Err(e) = mime {
return Err(Error::Mime(e));
}
// Status
let status = Status::from_utf8(slice);
if let Err(reason) = status {
return Err(Error::Status(reason));
if let Err(e) = status {
return Err(Error::Status(e));
}
Ok(Self {
@ -95,7 +95,7 @@ impl Meta {
},
|result| match result {
Ok(buffer) => on_complete(Self::from_utf8(&buffer)),
Err(reason) => on_complete(Err(reason)),
Err(e) => on_complete(Err(e)),
},
);
}
@ -147,7 +147,7 @@ pub fn read_from_stream_async(
// Continue
read_from_stream_async(buffer, stream, cancellable, priority, on_complete);
}
Err((data, reason)) => on_complete(Err(Error::InputStream(data, reason))),
Err((data, e)) => on_complete(Err(Error::InputStream(data, e))),
},
);
}

View file

@ -52,7 +52,7 @@ impl Data {
false => Some(Self { value }),
true => None,
}),
Err(reason) => Err(Error::Decode(reason)),
Err(e) => Err(Error::Decode(e)),
}
}
None => Err(Error::Protocol),

View file

@ -9,8 +9,8 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Decode(reason) => {
write!(f, "Decode error: {reason}")
Self::Decode(e) => {
write!(f, "Decode error: {e}")
}
Self::Protocol => {
write!(f, "Protocol error")

View file

@ -12,21 +12,21 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Data(reason) => {
write!(f, "Data error: {reason}")
Self::Data(e) => {
write!(f, "Data error: {e}")
}
Self::InputStream(_, reason) => {
Self::InputStream(_, e) => {
// @TODO
write!(f, "Input stream error: {reason}")
write!(f, "Input stream error: {e}")
}
Self::Mime(reason) => {
write!(f, "MIME error: {reason}")
Self::Mime(e) => {
write!(f, "MIME error: {e}")
}
Self::Protocol => {
write!(f, "Protocol error")
}
Self::Status(reason) => {
write!(f, "Status error: {reason}")
Self::Status(e) => {
write!(f, "Status error: {e}")
}
}
}

View file

@ -47,7 +47,7 @@ impl Mime {
match buffer.get(..if len > MAX_LEN { MAX_LEN } else { len }) {
Some(value) => match GString::from_utf8(value.into()) {
Ok(string) => Self::from_string(string.as_str()),
Err(reason) => Err(Error::Decode(reason)),
Err(e) => Err(Error::Decode(e)),
},
None => Err(Error::Protocol),
}

View file

@ -10,8 +10,8 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Decode(reason) => {
write!(f, "Decode error: {reason}")
Self::Decode(e) => {
write!(f, "Decode error: {e}")
}
Self::Protocol => {
write!(f, "Protocol error")

View file

@ -43,7 +43,7 @@ impl Status {
match buffer.get(0..2) {
Some(value) => match GString::from_utf8(value.to_vec()) {
Ok(string) => Self::from_string(string.as_str()),
Err(reason) => Err(Error::Decode(reason)),
Err(e) => Err(Error::Decode(e)),
},
None => Err(Error::Protocol),
}

View file

@ -10,8 +10,8 @@ pub enum Error {
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Decode(reason) => {
write!(f, "Decode error: {reason}")
Self::Decode(e) => {
write!(f, "Decode error: {e}")
}
Self::Protocol => {
write!(f, "Protocol error")

View file

@ -69,8 +69,8 @@ impl Session {
}
// Close connection if active yet
if let Err(reason) = connection.close(Cancellable::NONE) {
return Err(Error::Connection(reason));
if let Err(e) = connection.close(Cancellable::NONE) {
return Err(Error::Connection(e));
}
}
Ok(())

View file

@ -84,8 +84,8 @@ pub fn read_all_from_stream_async(
(on_chunk, on_complete),
);
}
Err(reason) => {
on_complete(Err(Error::InputStream(reason)));
Err(e) => {
on_complete(Err(Error::InputStream(e)));
}
},
);

View file

@ -12,8 +12,8 @@ impl Display for Error {
Self::BytesTotal(total, limit) => {
write!(f, "Bytes total limit reached: {total} / {limit}")
}
Self::InputStream(reason) => {
write!(f, "Input stream error: {reason}")
Self::InputStream(e) => {
write!(f, "Input stream error: {e}")
}
}
}