Add hint for "access denied" message

This commit is contained in:
Laurenz 2023-08-07 16:46:26 +02:00
parent b61eee4306
commit 44e5e9c5f1
5 changed files with 22 additions and 14 deletions

View File

@ -606,7 +606,7 @@ fn load(paths: &BibPaths, data: &[Bytes]) -> StrResult<EcoVec<hayagriva::Entry>>
// We might have multiple bib/yaml files
for (path, bytes) in paths.0.iter().zip(data) {
let src = std::str::from_utf8(bytes).map_err(|_| FileError::InvalidUtf8)?;
let src = std::str::from_utf8(bytes).map_err(FileError::from)?;
let entries = parse_bib(path, src)?;
result.extend(entries);
}

View File

@ -440,7 +440,7 @@ fn load_syntaxes(paths: &SyntaxPaths, bytes: &[Bytes]) -> StrResult<Arc<SyntaxSe
// We might have multiple sublime-syntax/yaml files
for (path, bytes) in paths.0.iter().zip(bytes.iter()) {
let src = std::str::from_utf8(bytes).map_err(|_| FileError::InvalidUtf8)?;
let src = std::str::from_utf8(bytes).map_err(FileError::from)?;
out.add(
SyntaxDefinition::load_from_str(src, false, None)
.map_err(|e| eco_format!("failed to parse syntax file `{path}`: {e}"))?,

View File

@ -133,8 +133,13 @@ impl SourceDiagnostic {
}
/// Adds a single hint to the diagnostic.
pub fn with_hint(mut self, hint: EcoString) -> Self {
self.hints.push(hint);
pub fn hint(&mut self, hint: impl Into<EcoString>) {
self.hints.push(hint.into());
}
/// Adds a single hint to the diagnostic.
pub fn with_hint(mut self, hint: impl Into<EcoString>) -> Self {
self.hint(hint);
self
}
@ -238,7 +243,15 @@ where
S: Into<EcoString>,
{
fn at(self, span: Span) -> SourceResult<T> {
self.map_err(|message| Box::new(vec![SourceDiagnostic::error(span, message)]))
self.map_err(|message| {
let mut diagnostic = SourceDiagnostic::error(span, message);
if diagnostic.message.contains("(access denied)") {
diagnostic.hint("cannot read file outside of project root");
diagnostic
.hint("you can adjust the project root with the --root argument");
}
Box::new(vec![diagnostic])
})
}
}
@ -408,6 +421,7 @@ impl From<PackageError> for EcoString {
eco_format!("{error}")
}
}
/// Format a user-facing error message for an XML-like file format.
pub fn format_xml_like_error(format: &str, error: roxmltree::Error) -> EcoString {
match error {

View File

@ -585,10 +585,8 @@ impl Eval for ast::Strong {
vm.vt
.tracer
.warn(warning!(self.span(), "no text within stars").with_hint(
EcoString::from(
"using multiple consecutive stars (e.g. **) has no additional effect",
),
));
));
}
Ok((vm.items.strong)(body.eval(vm)?))
@ -605,9 +603,7 @@ impl Eval for ast::Emph {
vm.vt
.tracer
.warn(warning!(self.span(), "no text within underscores").with_hint(
EcoString::from(
"using multiple consecutive underscores (e.g. __) has no additional effect",
),
"using multiple consecutive underscores (e.g. __) has no additional effect"
));
}

View File

@ -92,9 +92,7 @@ pub fn typeset(
world.main().root().span(),
"layout did not converge within 5 attempts",
)
.with_hint(
"check if any states or queries are updating themselves".into(),
),
.with_hint("check if any states or queries are updating themselves"),
);
break;
}