mirror of https://github.com/zkat/miette.git
Merge 2d1c63f897 into b466948965
This commit is contained in:
commit
f0aefc034d
|
|
@ -78,7 +78,7 @@ impl Diagnostic for MietteError {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) mod tests {
|
pub(crate) mod tests {
|
||||||
use std::{error::Error, io::ErrorKind};
|
use std::error::Error;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
@ -99,9 +99,9 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn io_error() {
|
fn io_error() {
|
||||||
let inner_error = io::Error::new(ErrorKind::Other, "halt and catch fire");
|
let inner_error = io::Error::other("halt and catch fire");
|
||||||
let outer_error = TestError(inner_error);
|
let outer_error = TestError(inner_error);
|
||||||
let io_error = io::Error::new(ErrorKind::Other, outer_error);
|
let io_error = io::Error::other(outer_error);
|
||||||
|
|
||||||
let miette_error = MietteError::from(io_error);
|
let miette_error = MietteError::from(io_error);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ impl<T, E: std::error::Error + Send + Sync + 'static> IntoDiagnostic<T, E> for R
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::io::{self, ErrorKind};
|
use std::io;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn diagnostic_error() {
|
fn diagnostic_error() {
|
||||||
let inner_error = io::Error::new(ErrorKind::Other, "halt and catch fire");
|
let inner_error = io::Error::other("halt and catch fire");
|
||||||
let outer_error: Result<(), _> = Err(TestError(inner_error));
|
let outer_error: Result<(), _> = Err(TestError(inner_error));
|
||||||
|
|
||||||
let diagnostic_error = outer_error.into_diagnostic().unwrap_err();
|
let diagnostic_error = outer_error.into_diagnostic().unwrap_err();
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,27 @@ impl MietteDiagnostic {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<Box<dyn Diagnostic>> for MietteDiagnostic {
|
||||||
|
fn from(diag: Box<dyn Diagnostic>) -> Self {
|
||||||
|
let message = diag.to_string();
|
||||||
|
|
||||||
|
let code = diag.code().map(|c| c.to_string());
|
||||||
|
let severity = diag.severity();
|
||||||
|
let help = diag.help().map(|h| h.to_string());
|
||||||
|
let url = diag.url().map(|u| u.to_string());
|
||||||
|
let labels = diag.labels().map(|l| l.collect::<Vec<_>>());
|
||||||
|
|
||||||
|
MietteDiagnostic {
|
||||||
|
message,
|
||||||
|
code,
|
||||||
|
severity,
|
||||||
|
help,
|
||||||
|
url,
|
||||||
|
labels,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serialize_miette_diagnostic() {
|
fn test_serialize_miette_diagnostic() {
|
||||||
|
|
|
||||||
|
|
@ -10,5 +10,5 @@ pub fn bail_fmt() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bail_error() -> Result<()> {
|
pub fn bail_error() -> Result<()> {
|
||||||
bail!(io::Error::new(io::ErrorKind::Other, "oh no!"));
|
bail!(io::Error::other("oh no!"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,13 +42,13 @@ fn test_boxed_str_stderr() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_boxed_thiserror() {
|
fn test_boxed_thiserror() {
|
||||||
let error = MyError {
|
let error = MyError {
|
||||||
source: io::Error::new(io::ErrorKind::Other, "oh no!"),
|
source: io::Error::other("oh no!"),
|
||||||
};
|
};
|
||||||
let report: Report = miette!(error);
|
let report: Report = miette!(error);
|
||||||
assert_eq!("oh no!", report.source().unwrap().to_string());
|
assert_eq!("oh no!", report.source().unwrap().to_string());
|
||||||
|
|
||||||
let error = MyError {
|
let error = MyError {
|
||||||
source: io::Error::new(io::ErrorKind::Other, "oh no!!!!"),
|
source: io::Error::other("oh no!!!!"),
|
||||||
};
|
};
|
||||||
let error: Box<dyn Diagnostic + Send + Sync + 'static> = Box::new(error);
|
let error: Box<dyn Diagnostic + Send + Sync + 'static> = Box::new(error);
|
||||||
let report = Report::new_boxed(error);
|
let report = Report::new_boxed(error);
|
||||||
|
|
@ -203,7 +203,7 @@ fn test_boxed_custom_diagnostic() {
|
||||||
|
|
||||||
let related = CustomDiagnostic::new();
|
let related = CustomDiagnostic::new();
|
||||||
let main_diagnostic = CustomDiagnostic::new()
|
let main_diagnostic = CustomDiagnostic::new()
|
||||||
.with_source(io::Error::new(io::ErrorKind::Other, "oh no!"))
|
.with_source(io::Error::other("oh no!"))
|
||||||
.with_related(related);
|
.with_related(related);
|
||||||
|
|
||||||
let report = Report::new_boxed(Box::new(main_diagnostic));
|
let report = Report::new_boxed(Box::new(main_diagnostic));
|
||||||
|
|
@ -211,7 +211,7 @@ fn test_boxed_custom_diagnostic() {
|
||||||
|
|
||||||
let related = CustomDiagnostic::new();
|
let related = CustomDiagnostic::new();
|
||||||
let main_diagnostic = CustomDiagnostic::new()
|
let main_diagnostic = CustomDiagnostic::new()
|
||||||
.with_source(io::Error::new(io::ErrorKind::Other, "oh no!"))
|
.with_source(io::Error::other("oh no!"))
|
||||||
.with_related(related);
|
.with_related(related);
|
||||||
let main_diagnostic = Box::new(main_diagnostic) as Box<dyn Diagnostic + Send + Sync + 'static>;
|
let main_diagnostic = Box::new(main_diagnostic) as Box<dyn Diagnostic + Send + Sync + 'static>;
|
||||||
let report = miette!(main_diagnostic);
|
let report = miette!(main_diagnostic);
|
||||||
|
|
@ -228,7 +228,7 @@ fn test_boxed_custom_diagnostic() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_boxed_sources() {
|
fn test_boxed_sources() {
|
||||||
let error = MyError {
|
let error = MyError {
|
||||||
source: io::Error::new(io::ErrorKind::Other, "oh no!"),
|
source: io::Error::other("oh no!"),
|
||||||
};
|
};
|
||||||
let error = Box::<dyn Diagnostic + Send + Sync>::from(error);
|
let error = Box::<dyn Diagnostic + Send + Sync>::from(error);
|
||||||
let error: Report = miette!(error).wrap_err("it failed");
|
let error: Report = miette!(error).wrap_err("it failed");
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ fn test_fmt_source() {
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore = "Again with the io::Error source issue?"]
|
#[ignore = "Again with the io::Error source issue?"]
|
||||||
fn test_io_source() {
|
fn test_io_source() {
|
||||||
let io = io::Error::new(io::ErrorKind::Other, "oh no!");
|
let io = io::Error::other("oh no!");
|
||||||
let error: Report = miette!(TestError::Io(io));
|
let error: Report = miette!(TestError::Io(io));
|
||||||
assert_eq!("oh no!", error.source().unwrap().to_string());
|
assert_eq!("oh no!", error.source().unwrap().to_string());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue