Skip to content

Commit

Permalink
refactor: remove location_opt and DebugFormat (#3830)
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored Apr 28, 2024
1 parent 0826399 commit 3dac7cb
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 248 deletions.
8 changes: 0 additions & 8 deletions src/common/base/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ impl ErrorExt for Error {
fn as_any(&self) -> &dyn Any {
self
}

fn location_opt(&self) -> Option<common_error::snafu::Location> {
match self {
Error::Overflow { location, .. } => Some(*location),
Error::Underflow { location, .. } => Some(*location),
Error::Eof { location, .. } => Some(*location),
}
}
}

macro_rules! impl_read_le {
Expand Down
30 changes: 0 additions & 30 deletions src/common/datasource/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,34 +213,4 @@ impl ErrorExt for Error {
fn as_any(&self) -> &dyn Any {
self
}

fn location_opt(&self) -> Option<common_error::snafu::Location> {
use Error::*;
match self {
OrcReader { location, .. } => Some(*location),
BuildBackend { location, .. } => Some(*location),
ReadObject { location, .. } => Some(*location),
ListObjects { location, .. } => Some(*location),
InferSchema { location, .. } => Some(*location),
ReadParquetSnafu { location, .. } => Some(*location),
ParquetToSchema { location, .. } => Some(*location),
JoinHandle { location, .. } => Some(*location),
ParseFormat { location, .. } => Some(*location),
MergeSchema { location, .. } => Some(*location),
WriteObject { location, .. } => Some(*location),
ReadRecordBatch { location, .. } => Some(*location),
WriteRecordBatch { location, .. } => Some(*location),
AsyncWrite { location, .. } => Some(*location),
EncodeRecordBatch { location, .. } => Some(*location),
BufferedWriterClosed { location, .. } => Some(*location),

UnsupportedBackendProtocol { location, .. } => Some(*location),
EmptyHostPath { location, .. } => Some(*location),
InvalidUrl { location, .. } => Some(*location),
InvalidConnection { location, .. } => Some(*location),
UnsupportedCompressionType { location, .. } => Some(*location),
UnsupportedFormat { location, .. } => Some(*location),
WriteParquet { location, .. } => Some(*location),
}
}
}
8 changes: 0 additions & 8 deletions src/common/decimal/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ impl ErrorExt for Error {
}
}

fn location_opt(&self) -> Option<common_error::snafu::Location> {
match self {
Error::BigDecimalOutOfRange { location, .. } => Some(*location),
Error::InvalidPrecisionOrScale { location, .. } => Some(*location),
Error::ParseRustDecimalStr { .. } | Error::ParseBigDecimalStr { .. } => None,
}
}

fn as_any(&self) -> &dyn std::any::Any {
self
}
Expand Down
21 changes: 3 additions & 18 deletions src/common/error/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ pub trait ErrorExt: StackError {
StatusCode::Unknown
}

// TODO(ruihang): remove this default implementation
/// Get the location of this error, None if the location is unavailable.
/// Add `_opt` suffix to avoid confusing with similar method in `std::error::Error`
fn location_opt(&self) -> Option<crate::snafu::Location> {
None
}

/// Returns the error as [Any](std::any::Any) so that it can be
/// downcast to a specific implementation.
fn as_any(&self) -> &dyn Any;
Expand Down Expand Up @@ -116,9 +109,9 @@ impl BoxedError {

impl std::fmt::Debug for BoxedError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Use the pretty debug format of inner error for opaque error.
let debug_format = crate::format::DebugFormat::new(&*self.inner);
debug_format.fmt(f)
let mut buf = vec![];
self.debug_fmt(0, &mut buf);
write!(f, "{}", buf.join("\n"))
}
}

Expand All @@ -139,10 +132,6 @@ impl crate::ext::ErrorExt for BoxedError {
self.inner.status_code()
}

fn location_opt(&self) -> Option<crate::snafu::Location> {
self.inner.location_opt()
}

fn as_any(&self) -> &dyn std::any::Any {
self.inner.as_any()
}
Expand Down Expand Up @@ -196,10 +185,6 @@ impl crate::ext::ErrorExt for PlainError {
self.status_code
}

fn location_opt(&self) -> Option<crate::snafu::Location> {
None
}

fn as_any(&self) -> &dyn std::any::Any {
self as _
}
Expand Down
154 changes: 0 additions & 154 deletions src/common/error/src/format.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/common/error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#![feature(error_iter)]

pub mod ext;
pub mod format;
pub mod mock;
pub mod status_code;

Expand Down
6 changes: 0 additions & 6 deletions src/common/error/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
use std::any::Any;
use std::fmt;

use snafu::Location;

use crate::ext::{ErrorExt, StackError};
use crate::status_code::StatusCode;

Expand Down Expand Up @@ -61,10 +59,6 @@ impl ErrorExt for MockError {
self.code
}

fn location_opt(&self) -> Option<Location> {
None
}

fn as_any(&self) -> &dyn Any {
self
}
Expand Down
8 changes: 0 additions & 8 deletions src/common/runtime/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,4 @@ impl ErrorExt for Error {
fn as_any(&self) -> &dyn Any {
self
}

fn location_opt(&self) -> Option<common_error::snafu::Location> {
match self {
Error::BuildRuntime { location, .. }
| Error::IllegalState { location, .. }
| Error::WaitGcTaskStop { location, .. } => Some(*location),
}
}
}
15 changes: 0 additions & 15 deletions src/common/time/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,6 @@ impl ErrorExt for Error {
fn as_any(&self) -> &dyn Any {
self
}

fn location_opt(&self) -> Option<common_error::snafu::Location> {
match self {
Error::ParseTimestamp { location, .. }
| Error::Format { location, .. }
| Error::TimestampOverflow { location, .. }
| Error::ArithmeticOverflow { location, .. } => Some(*location),
Error::ParseDateStr { .. }
| Error::InvalidTimezoneOffset { .. }
| Error::ParseOffsetStr { .. }
| Error::ParseTimezoneName { .. } => None,
Error::InvalidDateStr { location, .. } => Some(*location),
Error::ParseInterval { location, .. } => Some(*location),
}
}
}

pub type Result<T> = std::result::Result<T, Error>;

0 comments on commit 3dac7cb

Please sign in to comment.