Skip to content

Commit 592ba86

Browse files
authored
refactor(rust): Remove thiserror dependency (#20979)
1 parent a2eb8aa commit 592ba86

File tree

7 files changed

+71
-39
lines changed

7 files changed

+71
-39
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ streaming-iterator = "0.1.9"
8080
strength_reduce = "0.2"
8181
strum = "0.26"
8282
strum_macros = "0.26"
83-
thiserror = "2"
8483
tokio = "1.26"
8584
tokio-util = "0.7.8"
8685
unicode-normalization = "0.1.24"

crates/polars-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ regex = { workspace = true, optional = true }
3838
serde = { workspace = true, optional = true }
3939
serde_json = { workspace = true, optional = true }
4040
strum_macros = { workspace = true }
41-
thiserror = { workspace = true }
4241
xxhash-rust = { workspace = true }
4342

4443
[dev-dependencies]

crates/polars-error/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ avro-schema = { workspace = true, optional = true }
1414
object_store = { workspace = true, optional = true }
1515
regex = { workspace = true, optional = true }
1616
simdutf8 = { workspace = true }
17-
thiserror = { workspace = true }
1817

1918
[target.'cfg(not(target_family = "wasm"))'.dependencies]
2019
signal-hook = "0.3"

crates/polars-error/src/lib.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,49 +75,60 @@ impl Display for ErrString {
7575
}
7676
}
7777

78-
#[derive(Debug, Clone, thiserror::Error)]
78+
#[derive(Debug, Clone)]
7979
pub enum PolarsError {
80-
#[error("not found: {0}")]
8180
ColumnNotFound(ErrString),
82-
#[error("{0}")]
8381
ComputeError(ErrString),
84-
#[error("duplicate: {0}")]
8582
Duplicate(ErrString),
86-
#[error("{0}")]
8783
InvalidOperation(ErrString),
88-
#[error("{}", match msg {
89-
Some(msg) => format!("{}", msg),
90-
None => format!("{}", error)
91-
})]
9284
IO {
9385
error: Arc<io::Error>,
9486
msg: Option<ErrString>,
9587
},
96-
#[error("no data: {0}")]
9788
NoData(ErrString),
98-
#[error("{0}")]
9989
OutOfBounds(ErrString),
100-
#[error("field not found: {0}")]
10190
SchemaFieldNotFound(ErrString),
102-
#[error("{0}")]
10391
SchemaMismatch(ErrString),
104-
#[error("lengths don't match: {0}")]
10592
ShapeMismatch(ErrString),
106-
#[error("{0}")]
10793
SQLInterface(ErrString),
108-
#[error("{0}")]
10994
SQLSyntax(ErrString),
110-
#[error("string caches don't match: {0}")]
11195
StringCacheMismatch(ErrString),
112-
#[error("field not found: {0}")]
11396
StructFieldNotFound(ErrString),
114-
#[error("{error}: {msg}")]
11597
Context {
11698
error: Box<PolarsError>,
11799
msg: ErrString,
118100
},
119101
}
120102

103+
impl Error for PolarsError {}
104+
105+
impl Display for PolarsError {
106+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
107+
use PolarsError::*;
108+
match self {
109+
ComputeError(msg)
110+
| InvalidOperation(msg)
111+
| OutOfBounds(msg)
112+
| SchemaMismatch(msg)
113+
| SQLInterface(msg)
114+
| SQLSyntax(msg) => write!(f, "{msg}"),
115+
116+
ColumnNotFound(msg) => write!(f, "not found: {msg}"),
117+
Duplicate(msg) => write!(f, "duplicate: {msg}"),
118+
IO { error, msg } => match msg {
119+
Some(m) => write!(f, "{m}"),
120+
None => write!(f, "{error}"),
121+
},
122+
NoData(msg) => write!(f, "no data: {msg}"),
123+
SchemaFieldNotFound(msg) => write!(f, "field not found: {msg}"),
124+
ShapeMismatch(msg) => write!(f, "lengths don't match: {msg}"),
125+
StringCacheMismatch(msg) => write!(f, "string caches don't match: {msg}"),
126+
StructFieldNotFound(msg) => write!(f, "field not found: {msg}"),
127+
Context { error, msg } => write!(f, "{error}: {msg}"),
128+
}
129+
}
130+
}
131+
121132
impl From<io::Error> for PolarsError {
122133
fn from(value: io::Error) -> Self {
123134
PolarsError::IO {

crates/polars-python/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pyo3 = { workspace = true, features = ["abi3-py39", "chrono", "chrono-tz", "mult
4646
rayon = { workspace = true }
4747
recursive = { workspace = true }
4848
serde_json = { workspace = true, optional = true }
49-
thiserror = { workspace = true }
5049

5150
[dependencies.polars]
5251
workspace = true

crates/polars-python/src/error.rs

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::fmt::{Debug, Formatter};
2-
use std::io::{Error, ErrorKind};
1+
use std::error::Error;
2+
use std::fmt::{Debug, Display, Formatter};
3+
use std::io::{Error as IoError, ErrorKind};
34

45
use polars::prelude::PolarsError;
56
use polars_error::PolarsWarning;
@@ -9,7 +10,6 @@ use pyo3::exceptions::{
910
};
1011
use pyo3::prelude::*;
1112
use pyo3::PyTypeInfo;
12-
use thiserror::Error;
1313

1414
use crate::exceptions::{
1515
CategoricalRemappingWarning, ColumnNotFoundError, ComputeError, DuplicateError,
@@ -19,23 +19,51 @@ use crate::exceptions::{
1919
};
2020
use crate::Wrap;
2121

22-
#[derive(Error)]
2322
pub enum PyPolarsErr {
24-
#[error(transparent)]
25-
Polars(#[from] PolarsError),
26-
#[error(transparent)]
27-
Python(#[from] PyErr),
28-
#[error("{0}")]
23+
Polars(PolarsError),
24+
Python(PyErr),
2925
Other(String),
3026
}
3127

32-
impl std::convert::From<std::io::Error> for PyPolarsErr {
33-
fn from(value: Error) -> Self {
34-
PyPolarsErr::Other(format!("{value:?}"))
28+
impl Error for PyPolarsErr {
29+
fn source(&self) -> Option<&(dyn Error + 'static)> {
30+
match self {
31+
Self::Polars(err) => Some(err),
32+
Self::Python(err) => Some(err),
33+
Self::Other(_) => None,
34+
}
35+
}
36+
}
37+
38+
impl std::fmt::Display for PyPolarsErr {
39+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
40+
match self {
41+
Self::Polars(err) => Display::fmt(err, f),
42+
Self::Python(err) => Display::fmt(err, f),
43+
Self::Other(err) => write!(f, "{err}"),
44+
}
45+
}
46+
}
47+
48+
impl From<PolarsError> for PyPolarsErr {
49+
fn from(err: PolarsError) -> Self {
50+
PyPolarsErr::Polars(err)
51+
}
52+
}
53+
54+
impl From<PyErr> for PyPolarsErr {
55+
fn from(err: PyErr) -> Self {
56+
PyPolarsErr::Python(err)
57+
}
58+
}
59+
60+
impl From<IoError> for PyPolarsErr {
61+
fn from(err: IoError) -> Self {
62+
PyPolarsErr::Other(format!("{err:?}"))
3563
}
3664
}
3765

38-
impl std::convert::From<PyPolarsErr> for PyErr {
66+
impl From<PyPolarsErr> for PyErr {
3967
fn from(err: PyPolarsErr) -> PyErr {
4068
use PyPolarsErr::*;
4169
match err {

0 commit comments

Comments
 (0)