Skip to content

Commit

Permalink
Improve error message under YAML parse errors. Closes #6825 (#6832)
Browse files Browse the repository at this point in the history
  • Loading branch information
cscheid authored Sep 14, 2023
1 parent 15378af commit f955128
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/changelog-1.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 14 additions & 4 deletions src/execute/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit f955128

Please sign in to comment.