1
0
Fork 0
mirror of https://github.com/haraldh/chainerror.git synced 2025-06-22 06:14:35 +02:00

docs: use new names

Signed-off-by: Harald Hoyer <harald@hoyer.xyz>
This commit is contained in:
Harald Hoyer 2023-07-28 16:21:22 +02:00
parent 55c16d7867
commit 82257c881a
Signed by: harald
GPG key ID: 900F3C4971086004
27 changed files with 74 additions and 76 deletions

View file

@ -1,8 +1,7 @@
use chainerror::prelude::v2::*;
use std::error::Error;
use std::fmt;
use std::io;
use std::result::Result;
use chainerror::prelude::v1::*;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;
@ -15,9 +14,9 @@ fn func3() -> Result<(), Box<dyn Error + Send + Sync>> {
Ok(())
}
derive_str_context!(Func2Error);
chainerror::str_context!(Func2Error);
fn func2() -> ChainResult<(), Func2Error> {
fn func2() -> chainerror::Result<(), Func2Error> {
func3().context(Func2Error("func2 error: calling func3".to_string()))?;
Ok(())
}
@ -27,8 +26,8 @@ enum Func1Error {
IO(String),
}
impl ::std::fmt::Display for Func1Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
impl fmt::Display for Func1Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Func1Error::Func2 => write!(f, "func1 error calling func2"),
Func1Error::IO(filename) => write!(f, "Error reading '{}'", filename),
@ -36,13 +35,13 @@ impl ::std::fmt::Display for Func1Error {
}
}
impl ::std::fmt::Debug for Func1Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
impl fmt::Debug for Func1Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self)
}
}
fn func1() -> ChainResult<(), Func1Error> {
fn func1() -> chainerror::Result<(), Func1Error> {
func2().context(Func1Error::Func2)?;
let filename = String::from("bar.txt");
do_some_io().context(Func1Error::IO(filename))?;

View file

@ -3,7 +3,6 @@
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;

View file

@ -1,14 +1,14 @@
use chainerror::prelude::v1::*;
use chainerror::Context as _;
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;
Ok(())
}
derive_str_context!(Func2Error);
chainerror::str_context!(Func2Error);
fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
let filename = "foo.txt";
@ -32,7 +32,7 @@ impl ::std::fmt::Display for Func1ErrorKind {
}
impl ::std::error::Error for Func1ErrorKind {}
fn func1() -> ChainResult<(), Func1ErrorKind> {
fn func1() -> chainerror::Result<(), Func1ErrorKind> {
func2().context(Func1ErrorKind::Func2)?;
let filename = String::from("bar.txt");
do_some_io().context(Func1ErrorKind::IO(filename))?;

View file

@ -1,14 +1,14 @@
use chainerror::prelude::v1::*;
use chainerror::Context as _;
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;
Ok(())
}
derive_str_context!(Func2Error);
chainerror::str_context!(Func2Error);
fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
let filename = "foo.txt";
@ -38,7 +38,7 @@ impl ::std::fmt::Debug for Func1ErrorKind {
impl ::std::error::Error for Func1ErrorKind {}
fn func1() -> ChainResult<(), Func1ErrorKind> {
fn func1() -> chainerror::Result<(), Func1ErrorKind> {
func2().context(Func1ErrorKind::Func2)?;
let filename = String::from("bar.txt");
do_some_io().context(Func1ErrorKind::IO(filename))?;

View file

@ -1,14 +1,14 @@
use chainerror::prelude::v1::*;
use chainerror::Context as _;
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;
Ok(())
}
derive_str_context!(Func2Error);
chainerror::str_context!(Func2Error);
fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
let filename = "foo.txt";
@ -38,7 +38,7 @@ impl ::std::fmt::Debug for Func1ErrorKind {
impl ::std::error::Error for Func1ErrorKind {}
fn func1() -> ChainResult<(), Func1ErrorKind> {
fn func1() -> chainerror::Result<(), Func1ErrorKind> {
func2().context(Func1ErrorKind::Func2)?;
let filename = String::from("bar.txt");
do_some_io().context(Func1ErrorKind::IO(filename))?;

View file

@ -2,7 +2,8 @@
#![allow(clippy::redundant_pattern_matching)]
pub mod mycrate {
use chainerror::prelude::v1::*;
use chainerror::Context as _;
use std::io;
fn do_some_io() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
@ -10,7 +11,7 @@ pub mod mycrate {
Ok(())
}
derive_str_context!(Func2Error);
chainerror::str_context!(Func2Error);
fn func2() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
let filename = "foo.txt";
@ -24,7 +25,7 @@ pub mod mycrate {
IO(String),
}
derive_err_kind!(Error, ErrorKind);
chainerror::err_kind!(Error, ErrorKind);
pub type Result<T> = std::result::Result<T, Error>;

View file

@ -2,7 +2,8 @@
#![allow(clippy::redundant_pattern_matching)]
pub mod mycrate {
use chainerror::prelude::v1::*;
use chainerror::{Context as _, ErrorDown as _};
use std::io;
fn do_some_io(_f: &str) -> std::result::Result<(), io::Error> {
@ -10,7 +11,7 @@ pub mod mycrate {
Ok(())
}
derive_str_context!(Func2Error);
chainerror::str_context!(Func2Error);
fn func2() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync>> {
let filename = "foo.txt";
@ -26,7 +27,7 @@ pub mod mycrate {
Unknown,
}
derive_err_kind!(Error, ErrorKind);
chainerror::err_kind!(Error, ErrorKind);
pub type Result<T> = std::result::Result<T, Error>;
impl std::fmt::Display for ErrorKind {

View file

@ -1,8 +1,7 @@
use chainerror::prelude::v1::*;
use chainerror::Context as _;
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;

View file

@ -1,8 +1,7 @@
use chainerror::prelude::v1::*;
use chainerror::Context as _;
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;

View file

@ -1,7 +1,7 @@
use chainerror::prelude::v1::*;
use chainerror::Context as _;
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;

View file

@ -1,7 +1,7 @@
use chainerror::prelude::v1::*;
use chainerror::Context as _;
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;

View file

@ -1,10 +1,10 @@
#![allow(clippy::single_match)]
#![allow(clippy::redundant_pattern_matching)]
use chainerror::prelude::v1::*;
use chainerror::Context as _;
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;

View file

@ -1,10 +1,10 @@
#![allow(clippy::single_match)]
#![allow(clippy::redundant_pattern_matching)]
use chainerror::prelude::v1::*;
use chainerror::{Context as _, ErrorDown as _};
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;

View file

@ -1,14 +1,14 @@
use chainerror::prelude::v1::*;
use chainerror::{Context as _, ErrorDown as _};
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;
Ok(())
}
derive_str_context!(Func2Error);
chainerror::str_context!(Func2Error);
fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
let filename = "foo.txt";
@ -16,7 +16,7 @@ fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
Ok(())
}
derive_str_context!(Func1Error);
chainerror::str_context!(Func1Error);
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
func2().context(Func1Error("func1 error".to_string()))?;
@ -28,7 +28,7 @@ fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
eprintln!("Func1Error: {}", f1err);
if let Some(f2err) = f1err.find_cause::<ChainError<Func2Error>>() {
if let Some(f2err) = f1err.find_cause::<chainerror::Error<Func2Error>>() {
eprintln!("Func2Error: {}", f2err);
}

View file

@ -1,14 +1,14 @@
use chainerror::prelude::v1::*;
use chainerror::{Context as _, ErrorDown};
use std::error::Error;
use std::io;
use std::result::Result;
fn do_some_io() -> Result<(), Box<dyn Error + Send + Sync>> {
Err(io::Error::from(io::ErrorKind::NotFound))?;
Ok(())
}
derive_str_context!(Func2Error);
chainerror::str_context!(Func2Error);
fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
let filename = "foo.txt";
@ -16,8 +16,8 @@ fn func2() -> Result<(), Box<dyn Error + Send + Sync>> {
Ok(())
}
derive_str_context!(Func1ErrorFunc2);
derive_str_context!(Func1ErrorIO);
chainerror::str_context!(Func1ErrorFunc2);
chainerror::str_context!(Func1ErrorIO);
fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
func2().context(Func1ErrorFunc2("func1 error calling func2".to_string()))?;
@ -28,7 +28,7 @@ fn func1() -> Result<(), Box<dyn Error + Send + Sync>> {
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
if let Err(e) = func1() {
if let Some(s) = e.downcast_ref::<ChainError<Func1ErrorIO>>() {
if let Some(s) = e.downcast_ref::<chainerror::Error<Func1ErrorIO>>() {
eprintln!("Func1ErrorIO:\n{:?}", s);
}