From 0d303d5de2a467c7ac5bf36bc9312d1d802e9d4c Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Fri, 14 Jul 2023 11:04:17 -0300 Subject: [PATCH 1/2] improve error message when attempting to run a JSON filter --- src/resources/filters/common/wrapped-filter.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/resources/filters/common/wrapped-filter.lua b/src/resources/filters/common/wrapped-filter.lua index 0466bfc22e..4226d767e4 100644 --- a/src/resources/filters/common/wrapped-filter.lua +++ b/src/resources/filters/common/wrapped-filter.lua @@ -113,7 +113,21 @@ function makeWrappedJsonFilter(scriptFile, filterHandler) return meta end }) - local result = pandoc.utils.run_json_filter(doc, path) + local success, result = pcall(pandoc.utils.run_json_filter, doc, path) + if not success then + local pandoc_error = tostring(result) + local filename = pandoc.path.filename(path) + local message = { + "Could not run " .. path .. " as a JSON filter.", + "Please make sure the file exists and is executable.", + "\nDid you intend '" .. filename .. "' as a Lua filter in an extension?", + "If so, make sure you've spelled the name of the extension correctly.", + "\nThe original Pandoc error follows below.", + pandoc_error + } + fail(table.concat(message, "\n")) + return nil + end if has_custom_nodes then doc:walk({ Meta = function(meta) From ade4b8abb06688d71c3548a1f0ef51fd2eda9190 Mon Sep 17 00:00:00 2001 From: Carlos Scheidegger Date: Fri, 14 Jul 2023 12:14:53 -0300 Subject: [PATCH 2/2] changelog --- news/changelog-1.4.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/changelog-1.4.md b/news/changelog-1.4.md index dee4628c33..c2f42d25a3 100644 --- a/news/changelog-1.4.md +++ b/news/changelog-1.4.md @@ -115,6 +115,7 @@ - Add support for relative paths in `require()` calls. - ([#5242](https://github.com/quarto-dev/quarto-cli/issues/5242)): Add line numbers to error messages. - Add support `quarto.doc.add_resource` and `quarto.doc.add_supporting`. `add_resource` will add a resource file to the current render, copying that file to the same relative location in the output directory. `add_supporting` will add a supporting file to the current render, moving that file file to the same relative location in the output directory. +- ([#6211](https://github.com/quarto-dev/quarto-cli/pull/6211)): Improve error message when a JSON filter (or a potentially misspelled Lua filter from an extension) is not found. ## Books