diff --git a/cli/src/template_parser.rs b/cli/src/template_parser.rs index 33186410c..61df1506d 100644 --- a/cli/src/template_parser.rs +++ b/cli/src/template_parser.rs @@ -14,7 +14,7 @@ use std::collections::HashMap; use std::num::ParseIntError; -use std::{error, fmt}; +use std::{error, fmt, iter}; use itertools::Itertools as _; use pest::iterators::{Pair, Pairs}; @@ -39,7 +39,7 @@ pub struct TemplateParseError { pub enum TemplateParseErrorKind { #[error("Syntax error")] SyntaxError, - #[error("Invalid integer literal: {0}")] + #[error("Invalid integer literal")] ParseIntError(#[source] ParseIntError), #[error(r#"Keyword "{0}" doesn't exist"#)] NoSuchKeyword(String), @@ -61,10 +61,9 @@ pub enum TemplateParseErrorKind { impl TemplateParseError { pub fn with_span(kind: TemplateParseErrorKind, span: pest::Span<'_>) -> Self { + let message = iter::successors(Some(&kind as &dyn error::Error), |e| e.source()).join(": "); let pest_error = Box::new(pest::error::Error::new_from_span( - pest::error::ErrorVariant::CustomError { - message: kind.to_string(), - }, + pest::error::ErrorVariant::CustomError { message }, span, )); TemplateParseError { @@ -79,10 +78,9 @@ impl TemplateParseError { span: pest::Span<'_>, origin: Self, ) -> Self { + let message = iter::successors(Some(&kind as &dyn error::Error), |e| e.source()).join(": "); let pest_error = Box::new(pest::error::Error::new_from_span( - pest::error::ErrorVariant::CustomError { - message: kind.to_string(), - }, + pest::error::ErrorVariant::CustomError { message }, span, )); TemplateParseError { diff --git a/lib/src/revset.rs b/lib/src/revset.rs index f5fee3ebd..1144dde3b 100644 --- a/lib/src/revset.rs +++ b/lib/src/revset.rs @@ -21,7 +21,7 @@ use std::path::Path; use std::rc::Rc; use std::str::FromStr; use std::sync::Arc; -use std::{error, fmt}; +use std::{error, fmt, iter}; use itertools::Itertools; use once_cell::sync::Lazy; @@ -174,7 +174,7 @@ pub enum RevsetParseErrorKind { }, #[error("Invalid arguments to revset function \"{name}\": {message}")] InvalidFunctionArguments { name: String, message: String }, - #[error("Invalid file pattern: {0}")] + #[error("Invalid file pattern")] FsPathParseError(#[source] FsPathParseError), #[error("Cannot resolve file pattern without workspace")] FsPathWithoutWorkspace, @@ -198,10 +198,9 @@ impl RevsetParseError { } fn with_span(kind: RevsetParseErrorKind, span: pest::Span<'_>) -> Self { + let message = iter::successors(Some(&kind as &dyn error::Error), |e| e.source()).join(": "); let err = pest::error::Error::new_from_span( - pest::error::ErrorVariant::CustomError { - message: kind.to_string(), - }, + pest::error::ErrorVariant::CustomError { message }, span, ); RevsetParseError { @@ -216,10 +215,9 @@ impl RevsetParseError { span: pest::Span<'_>, origin: Self, ) -> Self { + let message = iter::successors(Some(&kind as &dyn error::Error), |e| e.source()).join(": "); let err = pest::error::Error::new_from_span( - pest::error::ErrorVariant::CustomError { - message: kind.to_string(), - }, + pest::error::ErrorVariant::CustomError { message }, span, ); RevsetParseError {