quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.97k stars 328 forks source link

Quarto render / preview immediately reports "SyntaxError: Unexpected end of JSON input" #6392

Open pranavmishra90 opened 1 year ago

pranavmishra90 commented 1 year ago

Bug description

Hi all,

I've been using quarto successfully for some time now. On my main machine, I can't seem to perform any quarto render or quarto preview commands. Using VSCode's quarto plugin produces the same error. I also have quarto installed inside of a docker container which produces an error, though a different one.

Do not know why a previously functioning quarto is no longer working (details below)

Steps to reproduce

My directory consists of a Git repository with several submodules. The parent / root directory contains a _quarto.yml file with the following contents

project:
  type: website
  output-dir: ./notebook/_site
  render:
    - "*.qmd"
    - "*.md"
    - "*.ipynb"
  preview:
    port: 3333
    browser: true
    watch-inputs: true
    timeout: 300

bibliography:
  - ./notebook/references.bib
csl: ./notebook/ama.csl

citation: false
google-scholar: true

website:
  title: "redacted Project"
  navbar:
    left:
      - href: index.qmd
        text: Home
      - href: https://github.com/redacted
        text: GitHub
      - href: notebook/external/redacted
    search: true
  open-graph: true
  sidebar:
    style: "docked"
    contents: auto
    repo-url: https://github.com/redacted
    repo-actions: [issue, edit]
  reader-mode: true
  repo-url: https://github.com/redacted
  repo-actions: [issue, edit]
  page-footer: "redacted"

format:
  html:
    theme:
      light: flatly
      dark: darkly
    toc: true
    lang: en-US
    email-obfuscation: javascript
    code-fold: true
    code-line-numbers: true
    code-overflow: wrap
    grid:
      sidebar-width: 350px
    default-image-extension: svg

  # pdf:
  #   # pdf-engine: latexmk
  #   documentclass: scrartcl
  #   toc: true
  #   code-fold: true
  #   papersize: letter
  # #   toc-depth: 2
  # #   lof: true
  # #   lot: true
  #   margin-left: 30mm
  #   margin-right: 30mm
  #   highlight-style: github
  #   colorlinks: true
  #   default-image-extension: png  

execute:
  freeze: auto
  cache: true
  error: true

I use quarto to build a static website, which is rendered in ./notebook/_site.

Command

quarto render

Expected behavior

Begin rendering the website by going into the subdirectories and rendering .ipynb, .qmd, etc.

Output to notebook/_site/

Actual behavior

Debian

(scRNAseq) pranav@singulab prrx1 (main) : quarto render
ERROR: SyntaxError: Unexpected end of JSON input

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.target (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:55201:27)
    at fileExecutionEngineAndTarget (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:58033:33)
    at renderContexts (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:82635:40)
    at Object.renderFormats (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:82688:32)
    at inputTargetIndex (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:83504:35)
    at entryFromHref (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:92762:25)
    at nodesToEntries (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:92733:36)
    at async nodesToEntries (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:92729:35)
    at async nodesToEntries (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:92729:35)

I also get a similar same output when trying quarto preview

(scRNAseq) pranav@singulab prrx1 (main) : quarto preview
Preparing to preview
ERROR: SyntaxError: Unexpected end of JSON input

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Object.target (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:55201:27)
    at fileExecutionEngineAndTarget (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:58033:33)
    at renderContexts (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:82635:40)
    at Object.renderFormats (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:82688:32)
    at inputTargetIndex (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:83504:35)
    at resolveInputTarget (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:83583:25)
    at serveFiles (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:103550:30)
    at async serveProject (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:103188:30)
    at async Command.fn (file:///home/pranav/opt/quarto-1.3.433/bin/quarto.js:103749:13)

Docker

root@f00ca38999ac:/home/rstudio/work# quarto render
ERROR: Include directive needs filename as a parameter

VSCode

Produces the same error as listed under 'Debian'.

Your environment

OS: Debian 12 IDE: VSCode 1.80.2 Quarto: 1.3.433

Quarto check output

As a sanity check, I even uninstalled and reinstalled quarto

(scRNAseq) pranav@singulab prrx1 (main) : quarto check

[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.1: OK
      Dart Sass version 1.55.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.3.433
      Path: /home/pranav/opt/quarto-1.3.433/bin

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.10.12 (Conda)
      Path: /home/pranav/mambaforge/envs/scRNAseq/bin/python
      Jupyter: 5.3.1
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.3.1
      Path: /home/pranav/mambaforge/envs/scRNAseq/lib/R
      LibPaths:
        - /home/pranav/mambaforge/envs/scRNAseq/lib/R/library
      knitr: (None)
      rmarkdown: (None)

      The rmarkdown package is not available in this R installation.
      Install with install.packages("rmarkdown")
dragonstyle commented 1 year ago

Quarto keeps an index of all project inputs in the .quarto hidden directory, which for some reason we appear to be having trouble reading.

One thing that is confusing me - in the docker section, there is an error indicating that an include has been specified without a file name. Can you clarify what this error is? I'm wondering whether you perhaps have an error in an include shortcode and that has somehow caused a problem for us when attempting to resolve an input using that index...

pranavmishra90 commented 1 year ago

Thanks for the quick reply. I was able to find the source of the error with your comment. I'll document it below, along with a possible feature recommendation / enhancement.

TLDR: Source of error was an empty jupyter notebook

There was a jupyter notebook which had a single empty code cell inside. After deleting this file, the quarto preview and quarto render commands executed as intended.


Steps to reproduce

Investigating the .quarto/ directory

I tried several variations on:

None of these fixed the issue.

Testing on a entirely new directory / project

Created a new directory at ~/testing, made a simple index.qmd file, and tried a quarto render index.qmd. It worked, showing that quarto itself was not at fault

Trying to see which file in my project was causing the error

Starting over with an empty .quarto/, I reran quarto render, which produced the JSON error. I then tried to determine which file was the offending one by looking at "what was the most recently modified thing inside of the .quarto/ directory:

# adapted from: https://stackoverflow.com/questions/5566310/how-to-recursively-find-and-list-the-latest-modified-files-in-a-directory-with-s
find . -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2- | head

The output was 2023-08-01 07:26:33.749877086 -0500 ./idx/code/python/scvi/phase_2/03 - cell_annotation.ipynb.json, which I incorrectly assumed was the offending file. This should be considered as the "last correctly processed file". (Foreshadowing) The next file in the directory is the offending one.

Specifically prevented the rendering of that notebook with:

# from _quarto.yml
project:
  type: website
  output-dir: ./notebook/_site
  render:
    - "*.qmd"
    - "*.md"
    - "*.ipynb"
    - "!code/python/scvi/phase_2/03 - cell_annotation.ipynb"

This did not work, but blocking the render to the all jupyter notebooks, then specifically just the parent directory did. I had recently created copies of multiple notebooks while testing something, so the titles were all the same, but filenames were different. Thinking this may lead to some sort of error when building the sidebar (though it hasn't before with copies of files), I changed all of the yaml headers.

While going file by file, that's when I reached the empty file. I deleted it and quarto began functioning as intended.

Recommendation

To end users:

# cd inside of your projects .quarto/ directory
find . -exec stat --format '%Y :%y %n' "{}" \; | sort -nr | cut -d: -f2- | head

The top result is the most recently modified file. Find the file that comes next in the directory. This is the cause of the problem

To quarto devs

As an enhancement, can quarto possibly provide the file it was working on rendering which produced the error. This would give an end user a place to start debugging. The JSON error with javascript lines does not provide this level of specificity.

I actually did not know that there is a rapid JSON conversion of the files until digging into this issue. I assumed that it went file by file, as shown by the printed output (STOUT)

quarto preview
Preparing to preview
[ 1/39] notebook/presentations/gene_expression_vs_cluster.qmd

Starting python3 kernel...Done
 (continues)

If there was a way to show an error message at the initial quarto preview / quarto render stage, it could be helpful

cscheid commented 1 year ago

Thanks for the report. We should definitely improve this error.

cscheid commented 1 year ago

Pushing this to 1.5 when we'll have better information about which file is being processed by what part of the code.

fredguth commented 9 months ago

I just would like to add that I am also experiencing the same problem. I was following the instructions of the new Manuscript guide when it happened. I "solved it" by restoring the repo to the original.