From f955128beedc9597846d689bc3859a2cf4e6a811 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger <285675+cscheid@users.noreply.github.com> Date: Thu, 14 Sep 2023 09:33:32 -0700 Subject: [PATCH] Improve error message under YAML parse errors. Closes #6825 (#6832) --- news/changelog-1.4.md | 1 + src/execute/engine.ts | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/news/changelog-1.4.md b/news/changelog-1.4.md index e724fd61b9..e31ef52238 100644 --- a/news/changelog-1.4.md +++ b/news/changelog-1.4.md @@ -189,3 +189,4 @@ - ([#6705](https://github.com/quarto-dev/quarto-cli/pull/6705)): Fix issue with gfm output being removed when rendered with other formats. - ([#6746](https://github.com/quarto-dev/quarto-cli/issues/6746)): Let stdout and stderr finish independently to avoid deadlock. - ([#6807](https://github.com/quarto-dev/quarto-cli/pull/6807)): Improve sourcemapping reference cleanup in generated CSS files. +- ([#6825](https://github.com/quarto-dev/quarto-cli/issues/6825)): Show filename when YAML parsing error occurs. diff --git a/src/execute/engine.ts b/src/execute/engine.ts index 1d3028c464..deabace737 100644 --- a/src/execute/engine.ts +++ b/src/execute/engine.ts @@ -180,10 +180,20 @@ export function fileExecutionEngine( // if we were passed a transformed markdown, use that for the text instead // of the contents of the file. if (kMdExtensions.includes(ext) || kQmdExtensions.includes(ext)) { - return markdownExecutionEngine( - markdown ? markdown.value : Deno.readTextFileSync(file), - flags, - ); + // https://github.com/quarto-dev/quarto-cli/issues/6825 + // In case the YAML _parsing_ fails, we need to annotate the error + // with the filename so that the user knows which file is the problem. + try { + return markdownExecutionEngine( + markdown ? markdown.value : Deno.readTextFileSync(file), + flags, + ); + } catch (error) { + if (error.name === "YAMLError") { + error.message = `${file}:\n${error.message}`; + } + throw error; + } } else { return undefined; }