Skip to content

Commit

Permalink
ARROW-7312: [Rust] Implement std::error::Error for ArrowError.
Browse files Browse the repository at this point in the history
Add this implementation so that others can handle errors from arrow crate better.

Closes apache#5959 from liurenjie1024/arrow-7312 and squashes the following commits:

f27683a <Renjie Liu> Fix comment
d3e238d <Renjie Liu> Implement error

Authored-by: Renjie Liu <liurenjie2008@gmail.com>
Signed-off-by: Neville Dipale <nevilledips@gmail.com>
  • Loading branch information
liurenjie1024 authored and nevi-me committed Dec 7, 2019
1 parent 3410b11 commit a7c897e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions rust/arrow/src/error.rs
Expand Up @@ -17,6 +17,7 @@

//! Defines `ArrowError` for representing failures in various Arrow operations
use std::error::Error;
use std::fmt::{Display, Formatter};

use csv as csv_crate;

Expand Down Expand Up @@ -70,4 +71,26 @@ impl From<::std::string::FromUtf8Error> for ArrowError {
}
}

impl Display for ArrowError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
&ArrowError::MemoryError(ref desc) => write!(f, "Memory error: {}", desc),
&ArrowError::ParseError(ref desc) => write!(f, "Parser error: {}", desc),
&ArrowError::ComputeError(ref desc) => write!(f, "Compute error: {}", desc),
&ArrowError::DivideByZero => write!(f, "Divide by zero error"),
&ArrowError::CsvError(ref desc) => write!(f, "Csv error: {}", desc),
&ArrowError::JsonError(ref desc) => write!(f, "Json error: {}", desc),
&ArrowError::IoError(ref desc) => write!(f, "Io error: {}", desc),
&ArrowError::InvalidArgumentError(ref desc) => {
write!(f, "Invalid argument error: {}", desc)
}
&ArrowError::ParquetError(ref desc) => {
write!(f, "Parquet argument error: {}", desc)
}
}
}
}

impl Error for ArrowError {}

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

0 comments on commit a7c897e

Please sign in to comment.