mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 18:28:02 +00:00
fix: enhance error handling (#1758)
This commit is contained in:
parent
5bf177637a
commit
28d416b852
3 changed files with 14 additions and 4 deletions
|
@ -237,7 +237,10 @@ impl Typlite {
|
|||
let mut world = world.task(task_inputs).html_task().into_owned();
|
||||
|
||||
let markdown_id = FileId::new(
|
||||
Some(typst_syntax::package::PackageSpec::from_str("@local/markdown:0.1.0").unwrap()),
|
||||
Some(
|
||||
typst_syntax::package::PackageSpec::from_str("@local/markdown:0.1.0")
|
||||
.context_ut("failed to import markdown package")?,
|
||||
),
|
||||
VirtualPath::new("lib.typ"),
|
||||
);
|
||||
|
||||
|
@ -261,7 +264,10 @@ impl Typlite {
|
|||
r#"#import "@local/markdown:0.1.0": md-doc, example
|
||||
#show: md-doc
|
||||
{}"#,
|
||||
world.source(current).unwrap().text()
|
||||
world
|
||||
.source(current)
|
||||
.context_ut("failed to get main file content")?
|
||||
.text()
|
||||
)),
|
||||
)
|
||||
.context_ut("cannot map source for main file")?;
|
||||
|
|
|
@ -90,7 +90,9 @@ fn run(args: CompileArgs, world: Arc<LspWorld>) -> tinymist_std::Result<()> {
|
|||
};
|
||||
|
||||
if is_stdout {
|
||||
std::io::stdout().write_all(result.as_slice()).unwrap();
|
||||
std::io::stdout()
|
||||
.write_all(result.as_slice())
|
||||
.context("failed to write to stdout")?;
|
||||
} else if let Err(err) = std::fs::write(&output_path, result.as_slice()) {
|
||||
bail!("failed to write file {output_path:?}: {err}");
|
||||
}
|
||||
|
|
|
@ -20,7 +20,9 @@ impl MarkdownWriter {
|
|||
impl FormatWriter for MarkdownWriter {
|
||||
fn write_eco(&mut self, document: &Node, output: &mut EcoString) -> Result<()> {
|
||||
let mut writer = CommonMarkWriter::new();
|
||||
writer.write(document).expect("Failed to write document");
|
||||
writer
|
||||
.write(document)
|
||||
.map_err(|e| format!("failed to write document: {}", e))?;
|
||||
output.push_str(&writer.into_string());
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue