Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

quarto.json.decode does not raise on invalid JSON, so pcall cannot catch it

未關閉 適合新手
#15,226 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
84/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
lua
領域
backend

研究方向

從 src/resources/pandoc/datadir/_json.lua 和第 212 行附近的 decode_error 呼叫開始;檢查模組如何從 init.lua 載入,以及 common/log.lua 如何取代全域 error。Issue 提議在載入 _json.lua 時保留 Lua error 的區域參照。完成標準是:解碼和編碼失敗會引發可由 pcall 捕捉的錯誤,同時全域 error 的行為維持不變。

由索引模型根據 Issue 內容生成。

描述

bug lua
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
平均合併
16 小時 45 分鐘
30 天內合併 PR
117

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

quarto-dev/quarto-cli 的其他 Issue

查看 quarto-dev/quarto-cli 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。