ok/jj
1
0
Fork 0
forked from mirrors/jj

revset: report unparsable file path with span

This commit is contained in:
Yuya Nishihara 2022-11-01 22:57:31 +09:00
parent 65c903869c
commit fdbd44571d
2 changed files with 52 additions and 1 deletions

View file

@ -220,6 +220,19 @@ impl RevsetParseError {
}
}
fn with_span(kind: RevsetParseErrorKind, span: pest::Span<'_>) -> Self {
let err = pest::error::Error::new_from_span(
pest::error::ErrorVariant::CustomError {
message: kind.to_string(),
},
span,
);
RevsetParseError {
kind,
pest_error: Some(Box::new(err)),
}
}
pub fn kind(&self) -> &RevsetParseErrorKind {
&self.kind
}
@ -738,10 +751,14 @@ fn parse_function_expression(
if let Some(ctx) = workspace_ctx {
let paths = argument_pairs
.map(|arg| {
let span = arg.as_span();
let needle = parse_function_argument_to_string(&name, arg.into_inner())?;
let path = RepoPath::parse_fs_path(ctx.cwd, ctx.workspace_root, &needle)
.map_err(|e| {
RevsetParseError::new(RevsetParseErrorKind::FsPathParseError(e))
RevsetParseError::with_span(
RevsetParseErrorKind::FsPathParseError(e),
span,
)
})?;
Ok(path)
})

View file

@ -0,0 +1,34 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use common::TestEnvironment;
pub mod common;
#[test]
fn test_bad_function_call() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");
let stderr = test_env.jj_cmd_failure(&repo_path, &["log", "-r", r#"file(a, "../out")"#]);
insta::assert_snapshot!(stderr, @r###"
Error: Failed to parse revset: --> 1:9
|
1 | file(a, "../out")
| ^------^
|
= Invalid file pattern: Path "../out" is not in the repo
"###);
}