forked from mirrors/jj
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:
parent
d439de073d
commit
a0cefb8b7b
2 changed files with 12 additions and 16 deletions
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue