Skip to content

Commit

Permalink
Change Error (breaking change)
Browse files Browse the repository at this point in the history
* Add `#[non_exhaustive]` to `Error`
* Remove deprecated trait method `Error::description` implemented for `Error`
* Add `#[drive(Debug)]` for `Error` instead of explicitly implementing `Debug` for `Error`
* Implement `Error::source` for `Error`
  • Loading branch information
kubo committed Mar 31, 2024
1 parent 4eb1ae1 commit 959ccb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 56 deletions.
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Breaking changes:
* Add a new variant [`OracleType::Xml`]
* Add a lifetime parameter to [`SqlValue`]
* Remove [`SqlValue::dup`]
* Add [`#[non_exhaustive]`] to [`Error`]
* Remove deprecated trait method [`Error::description`] implemented for [`Error`]

New features:

Expand All @@ -28,6 +30,8 @@ Changes:
* Update minimum supported Rust version to 1.60.0
* Update rust edition to 2021
* Change a undocumented method of the sealed trait [`ColumnIndex`]
* Add `#[drive(Debug)]` for [`Error`] instead of explicitly implementing `Debug` for `Error`
* Implement `Error::source` for `Error`

## 0.5.7 (2023-01-30)

Expand Down Expand Up @@ -412,6 +416,9 @@ Incompatible changes:
[GH-54]: https://github.com/kubo/rust-oracle/issues/54
[GH-62]: https://github.com/kubo/rust-oracle/pull/62
[chrono]: https://docs.rs/chrono/latest/chrono/index.html
[`#[non_exhaustive]`]: https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute
[`Error::description`]: https://doc.rust-lang.org/std/error/trait.Error.html#method.description
[`Error::source`]: https://doc.rust-lang.org/std/error/trait.Error.html#method.source
[`pool`]: https://www.jiubao.org/rust-oracle/oracle/pool/index.html
[`Batch`]: https://www.jiubao.org/rust-oracle/oracle/struct.Batch.html
[`Collection`]: https://www.jiubao.org/rust-oracle/oracle/sql_type/struct.Collection.html
Expand Down Expand Up @@ -451,6 +458,7 @@ Incompatible changes:
[`DbError::message()`]: https://www.jiubao.org/rust-oracle/oracle/struct.DbError.html#method.message
[`DbError::offset()`]: https://www.jiubao.org/rust-oracle/oracle/struct.DbError.html#method.offset
[`Eq`]: https://doc.rust-lang.org/std/cmp/trait.Eq.html
[`Error`]: https://www.jiubao.org/rust-oracle/oracle/enum.Error.html
[`Error::NoDataFound`]: https://www.jiubao.org/rust-oracle/oracle/enum.Error.html#variant.NoDataFound
[`Error::OutOfRange`]: https://www.jiubao.org/rust-oracle/oracle/enum.Error.html#variant.OutOfRange
[`FromSql::from_sql`]: https://www.jiubao.org/rust-oracle/oracle/sql_type/trait.FromSql.html#method.from_sql
Expand Down
61 changes: 5 additions & 56 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ use std::str;
use std::sync;

/// Enum listing possible errors from rust-oracle.
#[non_exhaustive]
#[derive(Debug)]
pub enum Error {
// TODO: add #[non_exhaustive] at timing when incompatible changes are introduced.
/// Error from an underlying Oracle client library.
OciError(DbError),

Expand Down Expand Up @@ -211,62 +212,10 @@ impl fmt::Display for Error {
}
}

impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::OciError(ref err) => write!(f, "OciError({:?})", err),
Error::DpiError(ref err) => write!(f, "DpiError({:?})", err),
Error::NullValue => write!(f, "NullValue"),
Error::ParseError(ref err) => write!(f, "ParseError({:?})", err),
Error::OutOfRange(ref msg) => write!(f, "OutOfRange({:?})", msg),
Error::InvalidTypeConversion(ref from, ref to) => {
write!(f, "InvalidTypeConversion(from: {:?}, to: {:?})", from, to)
}
Error::InvalidBindIndex(ref idx) => write!(f, "InvalidBindIndex({:?})", idx),
Error::InvalidBindName(ref name) => write!(f, "InvalidBindName({:?})", name),
Error::InvalidColumnIndex(ref idx) => write!(f, "InvalidColumnIndex({:?})", idx),
Error::InvalidColumnName(ref name) => write!(f, "InvalidColumnName({:?})", name),
Error::InvalidAttributeName(ref name) => write!(f, "InvalidAttributeName({:?})", name),
Error::InvalidOperation(ref msg) => write!(f, "InvalidOperation({:?})", msg),
Error::UninitializedBindValue => write!(f, "UninitializedBindValue"),
Error::NoDataFound => write!(f, "NoDataFound"),
Error::BatchErrors(ref errs) => {
write!(f, "BatchErrors(")?;
for err in errs {
write!(f, "{:?}, ", err)?;
}
write!(f, ")")
}
Error::InternalError(ref msg) => write!(f, "InternalError({:?})", msg),
}
}
}

impl error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::OciError(_) => "Oracle OCI error",
Error::DpiError(_) => "ODPI-C error",
Error::NullValue => "NULL value",
Error::ParseError(_) => "parse error",
Error::OutOfRange(_) => "out of range",
Error::InvalidTypeConversion(_, _) => "invalid type conversion",
Error::InvalidBindIndex(_) => "invalid bind index",
Error::InvalidBindName(_) => "invalid bind name",
Error::InvalidColumnIndex(_) => "invalid column index",
Error::InvalidColumnName(_) => "invalid column name",
Error::InvalidAttributeName(_) => "invalid attribute name",
Error::InvalidOperation(_) => "invalid operation",
Error::UninitializedBindValue => "uninitialided bind value error",
Error::NoDataFound => "no data found",
Error::BatchErrors(_) => "batch errors",
Error::InternalError(_) => "internal error",
}
}

fn cause(&self) -> Option<&dyn error::Error> {
match *self {
Error::ParseError(ref err) => Some(err.as_ref()),
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match self {
Error::ParseError(err) => Some(err.as_ref()),
_ => None,
}
}
Expand Down

0 comments on commit 959ccb7

Please sign in to comment.