revset, template: remove ": {source}" from parse error message template

These error types are special because the message is embedded in ASCII art. I
think it would be a source of bugs if some error types had ": {source}" but
others don't. So I'm going to remove all ": {source}"s, and let the callers
concatenate them when needed.
This commit is contained in:
Yuya Nishihara 2024-02-03 17:03:58 +09:00
parent d439de073d
commit a0cefb8b7b
2 changed files with 12 additions and 16 deletions

View file

@ -14,7 +14,7 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::num::ParseIntError; use std::num::ParseIntError;
use std::{error, fmt}; use std::{error, fmt, iter};
use itertools::Itertools as _; use itertools::Itertools as _;
use pest::iterators::{Pair, Pairs}; use pest::iterators::{Pair, Pairs};
@ -39,7 +39,7 @@ pub struct TemplateParseError {
pub enum TemplateParseErrorKind { pub enum TemplateParseErrorKind {
#[error("Syntax error")] #[error("Syntax error")]
SyntaxError, SyntaxError,
#[error("Invalid integer literal: {0}")] #[error("Invalid integer literal")]
ParseIntError(#[source] ParseIntError), ParseIntError(#[source] ParseIntError),
#[error(r#"Keyword "{0}" doesn't exist"#)] #[error(r#"Keyword "{0}" doesn't exist"#)]
NoSuchKeyword(String), NoSuchKeyword(String),
@ -61,10 +61,9 @@ pub enum TemplateParseErrorKind {
impl TemplateParseError { impl TemplateParseError {
pub fn with_span(kind: TemplateParseErrorKind, span: pest::Span<'_>) -> Self { 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( let pest_error = Box::new(pest::error::Error::new_from_span(
pest::error::ErrorVariant::CustomError { pest::error::ErrorVariant::CustomError { message },
message: kind.to_string(),
},
span, span,
)); ));
TemplateParseError { TemplateParseError {
@ -79,10 +78,9 @@ impl TemplateParseError {
span: pest::Span<'_>, span: pest::Span<'_>,
origin: Self, origin: Self,
) -> 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( let pest_error = Box::new(pest::error::Error::new_from_span(
pest::error::ErrorVariant::CustomError { pest::error::ErrorVariant::CustomError { message },
message: kind.to_string(),
},
span, span,
)); ));
TemplateParseError { TemplateParseError {

View file

@ -21,7 +21,7 @@ use std::path::Path;
use std::rc::Rc; use std::rc::Rc;
use std::str::FromStr; use std::str::FromStr;
use std::sync::Arc; use std::sync::Arc;
use std::{error, fmt}; use std::{error, fmt, iter};
use itertools::Itertools; use itertools::Itertools;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -174,7 +174,7 @@ pub enum RevsetParseErrorKind {
}, },
#[error("Invalid arguments to revset function \"{name}\": {message}")] #[error("Invalid arguments to revset function \"{name}\": {message}")]
InvalidFunctionArguments { name: String, message: String }, InvalidFunctionArguments { name: String, message: String },
#[error("Invalid file pattern: {0}")] #[error("Invalid file pattern")]
FsPathParseError(#[source] FsPathParseError), FsPathParseError(#[source] FsPathParseError),
#[error("Cannot resolve file pattern without workspace")] #[error("Cannot resolve file pattern without workspace")]
FsPathWithoutWorkspace, FsPathWithoutWorkspace,
@ -198,10 +198,9 @@ impl RevsetParseError {
} }
fn with_span(kind: RevsetParseErrorKind, span: pest::Span<'_>) -> Self { 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( let err = pest::error::Error::new_from_span(
pest::error::ErrorVariant::CustomError { pest::error::ErrorVariant::CustomError { message },
message: kind.to_string(),
},
span, span,
); );
RevsetParseError { RevsetParseError {
@ -216,10 +215,9 @@ impl RevsetParseError {
span: pest::Span<'_>, span: pest::Span<'_>,
origin: Self, origin: Self,
) -> Self { ) -> Self {
let message = iter::successors(Some(&kind as &dyn error::Error), |e| e.source()).join(": ");
let err = pest::error::Error::new_from_span( let err = pest::error::Error::new_from_span(
pest::error::ErrorVariant::CustomError { pest::error::ErrorVariant::CustomError { message },
message: kind.to_string(),
},
span, span,
); );
RevsetParseError { RevsetParseError {