Slightly clean up error reporting
This commit is contained in:
parent
b8d222384b
commit
47e1301180
3 changed files with 24 additions and 17 deletions
|
@ -14,7 +14,6 @@ use yuck::{
|
|||
config::{file_provider::YuckFiles, validate::ValidationError},
|
||||
error::AstError,
|
||||
format_diagnostic::ToDiagnostic,
|
||||
gen_diagnostic,
|
||||
};
|
||||
|
||||
use crate::error::DiagError;
|
||||
|
@ -26,11 +25,16 @@ pub fn clear_files() {
|
|||
}
|
||||
|
||||
pub fn print_error(err: anyhow::Error) {
|
||||
match stringify_diagnostic(anyhow_err_to_diagnostic(&err)) {
|
||||
Ok(diag) => {
|
||||
eprintln!("{:?}\n{}", err, diag);
|
||||
}
|
||||
Err(_) => {
|
||||
match anyhow_err_to_diagnostic(&err) {
|
||||
Some(diag) => match stringify_diagnostic(diag) {
|
||||
Ok(diag) => {
|
||||
eprintln!("{}", diag);
|
||||
}
|
||||
Err(_) => {
|
||||
log::error!("{:?}", err);
|
||||
}
|
||||
},
|
||||
None => {
|
||||
log::error!("{:?}", err);
|
||||
}
|
||||
}
|
||||
|
@ -40,23 +44,22 @@ pub fn format_error(err: &anyhow::Error) -> String {
|
|||
for err in err.chain() {
|
||||
format!("chain: {}", err);
|
||||
}
|
||||
let diag = anyhow_err_to_diagnostic(err);
|
||||
stringify_diagnostic(diag).unwrap_or_else(|_| format!("{}", err))
|
||||
anyhow_err_to_diagnostic(err).and_then(|diag| stringify_diagnostic(diag).ok()).unwrap_or_else(|| format!("{:?}", err))
|
||||
}
|
||||
|
||||
pub fn anyhow_err_to_diagnostic(err: &anyhow::Error) -> Diagnostic<usize> {
|
||||
pub fn anyhow_err_to_diagnostic(err: &anyhow::Error) -> Option<Diagnostic<usize>> {
|
||||
if let Some(err) = err.downcast_ref::<DiagError>() {
|
||||
err.diag.clone()
|
||||
Some(err.diag.clone())
|
||||
} else if let Some(err) = err.downcast_ref::<AstError>() {
|
||||
err.to_diagnostic()
|
||||
Some(err.to_diagnostic())
|
||||
} else if let Some(err) = err.downcast_ref::<ConversionError>() {
|
||||
err.to_diagnostic()
|
||||
Some(err.to_diagnostic())
|
||||
} else if let Some(err) = err.downcast_ref::<ValidationError>() {
|
||||
err.to_diagnostic()
|
||||
Some(err.to_diagnostic())
|
||||
} else if let Some(err) = err.downcast_ref::<EvalError>() {
|
||||
err.to_diagnostic()
|
||||
Some(err.to_diagnostic())
|
||||
} else {
|
||||
gen_diagnostic!(format!("{:?}", err))
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -206,10 +206,11 @@ impl ListenVarHandler {
|
|||
let mut handle = tokio::process::Command::new("sh")
|
||||
.args(&["-c", &var.command])
|
||||
.stdout(std::process::Stdio::piped())
|
||||
.stderr(std::process::Stdio::inherit())
|
||||
.stderr(std::process::Stdio::piped())
|
||||
.stdin(std::process::Stdio::null())
|
||||
.spawn()?;
|
||||
let mut stdout_lines = BufReader::new(handle.stdout.take().unwrap()).lines();
|
||||
let mut stderr_lines = BufReader::new(handle.stderr.take().unwrap()).lines();
|
||||
crate::loop_select_exiting! {
|
||||
_ = handle.wait() => break,
|
||||
_ = cancellation_token.cancelled() => break,
|
||||
|
@ -217,6 +218,9 @@ impl ListenVarHandler {
|
|||
let new_value = DynVal::from_string(line.to_owned());
|
||||
evt_send.send(DaemonCommand::UpdateVars(vec![(var.name.to_owned(), new_value)]))?;
|
||||
}
|
||||
Ok(Some(line)) = stderr_lines.next_line() => {
|
||||
log::warn!("stderr of `{}`: {}", var.name, line);
|
||||
}
|
||||
else => break,
|
||||
}
|
||||
let _ = handle.kill().await;
|
||||
|
|
|
@ -593,7 +593,7 @@ fn build_gtk_literal(bargs: &mut BuilderArgs) -> Result<gtk::Box> {
|
|||
.map_err(|e| AstError::ErrorContext {
|
||||
label_span: literal_use_span,
|
||||
context: "Error in the literal used here".to_string(),
|
||||
main_err: Box::new(error_handling_ctx::anyhow_err_to_diagnostic(&e))
|
||||
main_err: Box::new(error_handling_ctx::anyhow_err_to_diagnostic(&e).unwrap_or_else(|| gen_diagnostic!(e)))
|
||||
})?;
|
||||
gtk_widget.add(&child_widget);
|
||||
child_widget.show();
|
||||
|
|
Loading…
Add table
Reference in a new issue