mirror of
https://github.com/typst/typst
synced 2025-06-28 16:22:53 +08:00
Add hint for "access denied" message
This commit is contained in:
parent
b61eee4306
commit
44e5e9c5f1
@ -606,7 +606,7 @@ fn load(paths: &BibPaths, data: &[Bytes]) -> StrResult<EcoVec<hayagriva::Entry>>
|
|||||||
|
|
||||||
// We might have multiple bib/yaml files
|
// We might have multiple bib/yaml files
|
||||||
for (path, bytes) in paths.0.iter().zip(data) {
|
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)?;
|
let entries = parse_bib(path, src)?;
|
||||||
result.extend(entries);
|
result.extend(entries);
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ fn load_syntaxes(paths: &SyntaxPaths, bytes: &[Bytes]) -> StrResult<Arc<SyntaxSe
|
|||||||
|
|
||||||
// We might have multiple sublime-syntax/yaml files
|
// We might have multiple sublime-syntax/yaml files
|
||||||
for (path, bytes) in paths.0.iter().zip(bytes.iter()) {
|
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(
|
out.add(
|
||||||
SyntaxDefinition::load_from_str(src, false, None)
|
SyntaxDefinition::load_from_str(src, false, None)
|
||||||
.map_err(|e| eco_format!("failed to parse syntax file `{path}`: {e}"))?,
|
.map_err(|e| eco_format!("failed to parse syntax file `{path}`: {e}"))?,
|
||||||
|
@ -133,8 +133,13 @@ impl SourceDiagnostic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a single hint to the diagnostic.
|
/// Adds a single hint to the diagnostic.
|
||||||
pub fn with_hint(mut self, hint: EcoString) -> Self {
|
pub fn hint(&mut self, hint: impl Into<EcoString>) {
|
||||||
self.hints.push(hint);
|
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
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +243,15 @@ where
|
|||||||
S: Into<EcoString>,
|
S: Into<EcoString>,
|
||||||
{
|
{
|
||||||
fn at(self, span: Span) -> SourceResult<T> {
|
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}")
|
eco_format!("{error}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format a user-facing error message for an XML-like file format.
|
/// Format a user-facing error message for an XML-like file format.
|
||||||
pub fn format_xml_like_error(format: &str, error: roxmltree::Error) -> EcoString {
|
pub fn format_xml_like_error(format: &str, error: roxmltree::Error) -> EcoString {
|
||||||
match error {
|
match error {
|
||||||
|
@ -585,9 +585,7 @@ impl Eval for ast::Strong {
|
|||||||
vm.vt
|
vm.vt
|
||||||
.tracer
|
.tracer
|
||||||
.warn(warning!(self.span(), "no text within stars").with_hint(
|
.warn(warning!(self.span(), "no text within stars").with_hint(
|
||||||
EcoString::from(
|
|
||||||
"using multiple consecutive stars (e.g. **) has no additional effect",
|
"using multiple consecutive stars (e.g. **) has no additional effect",
|
||||||
),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,9 +603,7 @@ impl Eval for ast::Emph {
|
|||||||
vm.vt
|
vm.vt
|
||||||
.tracer
|
.tracer
|
||||||
.warn(warning!(self.span(), "no text within underscores").with_hint(
|
.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",
|
|
||||||
),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,9 +92,7 @@ pub fn typeset(
|
|||||||
world.main().root().span(),
|
world.main().root().span(),
|
||||||
"layout did not converge within 5 attempts",
|
"layout did not converge within 5 attempts",
|
||||||
)
|
)
|
||||||
.with_hint(
|
.with_hint("check if any states or queries are updating themselves"),
|
||||||
"check if any states or queries are updating themselves".into(),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user