quarto.json.decode does not raise on invalid JSON, so pcall cannot catch it
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 src/resources/pandoc/datadir/_json.lua 和第212行附近的 decode_error 调用开始;检查模块如何从 init.lua 加载,以及 common/log.lua 如何替换全局 error。Issue 提议在加载 _json.lua 时保留对 Lua 的 error 的本地引用。完成标准是:解码和编码失败会引发可由 pcall 捕获的错误,同时全局 error 的行为保持不变。
由索引模型根据 Issue 内容生成。
描述
I have:
- searched the issue tracker for similar issues
- installed the latest version of Quarto CLI
- formatted my issue following the Bug Reports guide
Bug description
quarto.json.decode does not raise an error on invalid JSON.
It prints ERROR (...) lines to the console, then returns nil.
A filter that wraps the call in pcall gets ok = true, so it cannot tell that the decode failed, and it cannot keep the lines out of the console.
The cause is in src/resources/filters/common/log.lua.
It replaces the global error with a function that only prints, which affects every Lua filter.
src/resources/pandoc/datadir/_json.lua calls that global error when it reports a decode failure (decode_error, line 212), and when encode meets a value it cannot encode.
A small fix would be for _json.lua to keep its own reference when it loads: local error = error at the top of the file.
init.lua requires _json at line 151, before main.lua imports common/log.lua, so the reference would point to Lua's own error.
quarto.json.decode and quarto.json.encode would then raise as pandoc.json does.
The global stays as it is, so the change has no effect on code that relies on the global error not stopping the render.
Quarto 2 already behaves this way: pcall(quarto.json.decode, 'not json') returns false and JSON decode error: expected ident at line 1 column 2.
Steps to reproduce
repro.lua, in the same directory as the document:
function Meta(meta)
local ok, result = pcall(quarto.json.decode, 'not json')
quarto.log.output('decode: ok=' .. tostring(ok) .. ', result=' .. tostring(result))
ok, result = pcall(error, 'boom')
quarto.log.output('error: ok=' .. tostring(ok) .. ', result=' .. tostring(result))
end
---
title: "pcall and quarto.json.decode"
format: html
filters:
- at: pre-ast
type: lua
path: repro.lua
---
Text.
Run quarto render repro.qmd.
Actual behavior
ERROR (<quarto>/share/pandoc/datadir/_json.lua:212) invalid literal 'not' at line 1 col 1
ERROR (<quarto>/share/pandoc/datadir/_json.lua:212) trailing garbage at line 1 col 5
decode: ok=true, result=nil
ERROR ([C]:-1) boom
error: ok=true, result=nil
Expected behavior
pcall(quarto.json.decode, 'not json') returns false and the error message, and nothing is printed.
The second call shows the global error itself, for context.
Your environment
- Quarto 1.11.8 (also the development build at
2bd9f23c9). - macOS on Apple silicon.
- No IDE involved: rendered from the terminal.
Quarto check output
Quarto 1.11.8
[✓] Checking environment information...
Quarto cache location: /Users/mcanouil/Library/Caches/quarto
Project: none found (single-file mode)
[✓] Checking versions of quarto binary dependencies...
Pandoc version 3.10.0: OK
Dart Sass version 1.101.0: OK
Deno version 2.9.8: OK
Typst version 0.15.1: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
Version: 1.11.8
Path: <quarto>/bin
[✓] Checking tools....................OK
TinyTeX: v2026.07
Chrome Headless Shell: (not installed)
VeraPDF: (not installed)
[✓] Checking LaTeX....................OK
Using: TinyTex
Path: /Users/mcanouil/Library/TinyTeX/bin/universal-darwin
Version: 2026
[✓] Checking Chrome Headless....................OK
Using: Chrome from QUARTO_CHROMIUM
Path: /Applications/Brave Browser.app/Contents/MacOS/Brave Browser
[✓] Checking basic markdown render....OK
[✓] Checking R installation...........OK
Version: 4.6.1
Path: /Library/Frameworks/R.framework/Versions/4.6/Resources
knitr: 1.51
rmarkdown: 2.31
[✓] Checking Knitr engine render......OK
[✓] Checking Python 3 installation....OK
Version: 3.9.6
Path: /Library/Developer/CommandLineTools/usr/bin/python3
Jupyter: (None)
- 主要语言
- JavaScript
- 星标
- 6.1k
- 派生
- 476
- 平均合并
- 17 小时 16 分钟
- 30 天内合并 PR
- 112
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
quarto-dev/quarto-cli 的其他 Issue
-
accessibility bug themes
难度 1/5 1 小时以内 新手友好度 88/100
quarto-dev/quarto-cli#15222 ·
维护者通常 1 天内回复
-
bug code-annotation
难度 2/5 1-3 小时 新手友好度 76/100
quarto-dev/quarto-cli#15215 ·
维护者通常 1 天内回复
-
accessibility bug website-navigation
难度 2/5 1-3 小时 新手友好度 83/100
quarto-dev/quarto-cli#15190 ·
维护者通常 1 天内回复
-
Navbar dropdown toggles have `role="link"`可能已有人在做 @Mittalnew 于 3 天前认领。 未关闭accessibility bug website-navigation
难度 2/5 1-3 小时 新手友好度 88/100
quarto-dev/quarto-cli#15188 · 1 条评论 ·
维护者通常 1 天内回复
-
accessibility bug html websites
难度 2/5 1-3 小时 新手友好度 75/100
quarto-dev/quarto-cli#15187 ·
维护者通常 1 天内回复
查看 quarto-dev/quarto-cli 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
help wanted
难度 2/5 1-3 小时 新手友好度 77/100
Aethelgard-Systems/agent-postbox#32 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
SamuelNDCE/plume#42 ·
维护者通常 1 天内回复
-
[UI] Theme Provider Props table overflows on mobile viewports可能已有人在做 @SajanBisht 今天认领。 未关闭framework/gatsby help wanted kind/bug
难度 2/5 1-3 小时 新手友好度 78/100
layer5io/layer5#8264 · 1 条评论 ·
维护者通常 3 天内回复