quarto.json.decode does not raise on invalid JSON, so pcall cannot catch it
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 84/100
Direção de pesquisa
Comece por src/resources/pandoc/datadir/_json.lua e pela chamada decode_error por volta da linha 212; verifique como o módulo é carregado por init.lua antes de common/log.lua substituir o error global. A issue propõe manter uma referência local ao error do Lua quando _json.lua é carregado. O trabalho está concluído quando as falhas de decodificação e codificação geram erros que podem ser capturados por pcall, enquanto o comportamento do error global permanece inalterado.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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)
- Linguagem predominante
- JavaScript
- Estrelas
- 6.1k
- Forks
- 476
- Merge médio
- 16h 42min
- PRs com merge (30d)
- 115
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de quarto-dev/quarto-cli
-
accessibility bug websites
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 88/100
quarto-dev/quarto-cli#15235 ·
Mantenedores costumam responder em até 1 dia
-
accessibility bug themes
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
quarto-dev/quarto-cli#15222 ·
Mantenedores costumam responder em até 1 dia
-
bug code-annotation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
quarto-dev/quarto-cli#15215 ·
Mantenedores costumam responder em até 1 dia
-
accessibility bug website-navigation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
quarto-dev/quarto-cli#15190 ·
Mantenedores costumam responder em até 1 dia
-
Navbar dropdown toggles have `role="link"`Talvez já em andamento @Mittalnew assumiu há 5 dias. Abertaaccessibility bug website-navigation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
quarto-dev/quarto-cli#15188 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de quarto-dev/quarto-cli
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 85/100
pigeon189/zcode-fox-widget#17 · 1 comentário ·
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia
-
Let TypeScript accept an initial object in ReactiveDictTalvez já em andamento @yograj-vijay-yadav assumiu hoje. Abertabug good first issue help wanted workshop
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 92/100
meteor/meteor#14919 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
akitaonrails/FrankMD#268 ·
Mantenedores costumam responder em até 1 dia
-
good first issue
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia