mirror of
https://github.com/dtolnay/cargo-expand.git
synced 2025-04-03 21:07:37 +03:00
commit
95d6e65d4e
2 changed files with 23 additions and 6 deletions
20
src/error.rs
20
src/error.rs
|
@ -1,6 +1,8 @@
|
|||
use std::error::Error as StdError;
|
||||
use std::fmt::{self, Display};
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
Io(io::Error),
|
||||
TomlSer(toml::ser::Error),
|
||||
|
@ -29,12 +31,20 @@ impl From<toml::de::Error> for Error {
|
|||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::Error::*;
|
||||
|
||||
match self {
|
||||
Io(e) => e.fmt(formatter),
|
||||
TomlSer(e) => e.fmt(formatter),
|
||||
TomlDe(e) => e.fmt(formatter),
|
||||
Error::Io(e) => e.fmt(formatter),
|
||||
Error::TomlSer(e) => e.fmt(formatter),
|
||||
Error::TomlDe(e) => e.fmt(formatter),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl StdError for Error {
|
||||
fn source(&self) -> Option<&(dyn StdError + 'static)> {
|
||||
match self {
|
||||
Error::Io(e) => e.source(),
|
||||
Error::TomlSer(e) => e.source(),
|
||||
Error::TomlDe(e) => e.source(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ use bat::{PagingMode, PrettyPrinter};
|
|||
use clap::{Parser, ValueEnum};
|
||||
use quote::quote;
|
||||
use std::env;
|
||||
use std::error::Error as StdError;
|
||||
use std::ffi::OsString;
|
||||
use std::fs;
|
||||
use std::io::{self, BufRead, IsTerminal, Write};
|
||||
|
@ -54,7 +55,13 @@ fn main() {
|
|||
process::exit(match result {
|
||||
Ok(code) => code,
|
||||
Err(err) => {
|
||||
let _ = writeln!(io::stderr(), "{}", err);
|
||||
let mut stderr = io::stderr().lock();
|
||||
let _ = writeln!(stderr, "{}", err);
|
||||
let mut err = &err as &dyn StdError;
|
||||
while let Some(source) = err.source() {
|
||||
let _ = writeln!(stderr, "\nCaused by:\n {}", source);
|
||||
err = source;
|
||||
}
|
||||
1
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue