Remove verbose-errors cargo feature

pull/551/head
Pascal Hertleif 5 years ago
parent 99ddfb3f93
commit c704643296

@ -64,12 +64,6 @@ jobs:
command: test command: test
args: --all --features unstable args: --all --features unstable
- name: tests with verbose errors
uses: actions-rs/cargo@v1
with:
command: test
args: --all --features 'unstable verbose-errors'
check_fmt_and_docs: check_fmt_and_docs:
name: Checking fmt and docs name: Checking fmt and docs
runs-on: ubuntu-latest runs-on: ubuntu-latest

@ -48,7 +48,6 @@ std = [
"pin-utils", "pin-utils",
"slab", "slab",
] ]
verbose-errors = []
[dependencies] [dependencies]
async-attributes = { version = "1.1.1", optional = true } async-attributes = { version = "1.1.1", optional = true }

@ -9,7 +9,7 @@ use std::sync::{Arc, Mutex};
use crate::fs::{Metadata, Permissions}; use crate::fs::{Metadata, Permissions};
use crate::future; use crate::future;
use crate::utils::VerboseErrorExt; use crate::utils::Context as _;
use crate::io::{self, Read, Seek, SeekFrom, Write}; use crate::io::{self, Read, Seek, SeekFrom, Write};
use crate::path::Path; use crate::path::Path;
use crate::prelude::*; use crate::prelude::*;
@ -115,7 +115,7 @@ impl File {
let path = path.as_ref().to_owned(); let path = path.as_ref().to_owned();
let file = spawn_blocking(move || { let file = spawn_blocking(move || {
std::fs::File::open(&path) std::fs::File::open(&path)
.verbose_context(|| format!("Could not open {}", path.display())) .context(|| format!("Could not open {}", path.display()))
}) })
.await?; .await?;
Ok(File::new(file, true)) Ok(File::new(file, true))
@ -154,7 +154,7 @@ impl File {
let path = path.as_ref().to_owned(); let path = path.as_ref().to_owned();
let file = spawn_blocking(move || { let file = spawn_blocking(move || {
std::fs::File::create(&path) std::fs::File::create(&path)
.verbose_context(|| format!("Could not create {}", path.display())) .context(|| format!("Could not create {}", path.display()))
}) })
.await?; .await?;
Ok(File::new(file, true)) Ok(File::new(file, true))

@ -1,46 +1,41 @@
use crate::utils::VerboseErrorExt; use crate::utils::Context;
/// Wrap `std::io::Error` with additional message /// Wrap `std::io::Error` with additional message
/// ///
/// *Note* Only active when `verbose-errors` feature is enabled for this crate!
///
/// Keeps the original error kind and stores the original I/O error as `source`. /// Keeps the original error kind and stores the original I/O error as `source`.
impl<T> VerboseErrorExt for Result<T, std::io::Error> { impl<T> Context for Result<T, std::io::Error> {
#[cfg(feature = "verbose-errors")] fn context(self, message: impl Fn() -> String) -> Self {
fn verbose_context(self, message: impl Fn() -> String) -> Self { self.map_err(|e| VerboseError::wrap(e, message()))
self.map_err(|e| verbose::Error::wrap(e, message()))
} }
} }
#[cfg(feature = "verbose-errors")] use std::{error::Error as StdError, fmt, io};
mod verbose {
use std::{error::Error as StdError, fmt, io};
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct Error { pub(crate) struct VerboseError {
source: io::Error, source: io::Error,
message: String, message: String,
} }
impl Error { impl VerboseError {
pub(crate) fn wrap(source: io::Error, message: impl Into<String>) -> io::Error { pub(crate) fn wrap(source: io::Error, message: impl Into<String>) -> io::Error {
io::Error::new( io::Error::new(
source.kind(), source.kind(),
Error { VerboseError {
source, source,
message: message.into(), message: message.into(),
}, },
) )
} }
} }
impl fmt::Display for Error { impl fmt::Display for VerboseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.message) write!(f, "{}", self.message)
} }
} }
impl StdError for Error { impl StdError for VerboseError {
fn description(&self) -> &str { fn description(&self) -> &str {
self.source.description() self.source.description()
} }
@ -48,5 +43,4 @@ mod verbose {
fn source(&self) -> Option<&(dyn StdError + 'static)> { fn source(&self) -> Option<&(dyn StdError + 'static)> {
Some(&self.source) Some(&self.source)
} }
}
} }

@ -53,17 +53,8 @@ pub fn random(n: u32) -> u32 {
} }
/// Add additional context to errors /// Add additional context to errors
/// pub(crate) trait Context {
/// *Note for implementors:* The given closure must only be executed when fn context(self, message: impl Fn() -> String) -> Self;
/// `verbose-errors` feature is enabled for this crate!
pub(crate) trait VerboseErrorExt: Sized {
#[cfg(feature = "verbose-errors")]
fn verbose_context(self, message: impl Fn() -> String) -> Self;
#[cfg(not(feature = "verbose-errors"))]
fn verbose_context(self, _: impl Fn() -> String) -> Self {
self
}
} }
/// Defers evaluation of a block of code until the end of the scope. /// Defers evaluation of a block of code until the end of the scope.

@ -1,12 +1,9 @@
#[cfg(feature = "verbose-errors")] use async_std::{fs, task};
mod verbose_tests {
use async_std::{fs, task};
#[test] #[test]
fn open_file() { fn open_file() {
task::block_on(async { task::block_on(async {
let non_existing_file = let non_existing_file = "/ashjudlkahasdasdsikdhajik/asdasdasdasdasdasd/fjuiklashdbflasas";
"/ashjudlkahasdasdsikdhajik/asdasdasdasdasdasd/fjuiklashdbflasas";
let res = fs::File::open(non_existing_file).await; let res = fs::File::open(non_existing_file).await;
match res { match res {
Ok(_) => panic!("Found file with random name: We live in a simulation"), Ok(_) => panic!("Found file with random name: We live in a simulation"),
@ -16,5 +13,4 @@ mod verbose_tests {
), ),
} }
}) })
}
} }

Loading…
Cancel
Save