quarto-dev / quarto-cli

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

Mermaid diagram to pdf lead to Segmentation fault #11066

Closed lrrichter closed 3 weeks ago

lrrichter commented 1 month ago

Bug description

Rendering of a Mermaid diagram to pdf leads to a segmentation fault in line 192. Because of the ANSI color code problem (https://github.com/quarto-dev/quarto-cli/pull/10910/files) I had to use the version directly from the git repo (commit 46cdcc35d).

Steps to reproduce

````qmd
---
title: "Mermaid Test"
subtitle: "mermaid"
author: "Lothar R"
date: "2024/10/14"
execute:
  echo: true
  error: true
format:
#   html:
#     code-fold: true 
  beamer: 
    aspectratio: 169
    navigation: horizontal
    # theme: tum
    # echo: true
    # highlight-style: gruvbox-dark
    # code-overflow: wrap
    code-line-numbers: true
---

## MWE

```{mermaid}
%%| fig-width: 5.5
%%| echo: false
flowchart TB
    A[(Data Types)]
    A --> B(Boolean Type)
    A --> C(None Type)

Expected behavior

Render the diagram to pdf

Actual behavior

Rendering to pdf stopped with segmentation fault. Rendering to html works. quarto render mermaid.qmd --verbose /usr/local/bin/quarto: Zeile 192: 52556 Segmentation fault: 11 "${QUARTO_DENO}" ${QUARTO_ACTION} ${QUARTO_DENO_OPTIONS} ${QUARTO_DENO_EXTRA_OPTIONS} "${QUARTO_IMPORT_MAP_ARG}" "${QUARTO_TARGET}" "$@"

Your environment

Quarto check output

quarto check
Quarto 99.9.9
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      commit: 46cdcc35dd3515f8509bd2b8080575b18eb7d350
      Path: /Users/richter/work/tmp/quarto-cli/package/dist/bin

[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /Library/TeX/texbin
      Version: 2024

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

[✓] Checking Python 3 installation....OK
      Version: 3.9.20 (Conda)
      Path: /Users/richter/opt/anaconda3/bin/python
      Jupyter: 5.7.2
      Kernels: python3

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

[✓] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/
mcanouil commented 1 month ago

Because of the ANSI color code problem (https://github.com/quarto-dev/quarto-cli/pull/10910/files) I had to use the version directly from the git repo (commit 46cdcc3).

Sorry, it's confusing. What version of Quarto produces the issue?

lrrichter commented 1 month ago

The current (yesterday evening) version from the repo (I gave the commit ID). Sorry, it is my first time that I file a bug.

mcanouil commented 1 month ago

No reason, to apologise. I only wanted to clarify if the bug was before or after you were using the development version. Note that, there are pre-releases which are a bit "safer" to use and easier to install.

mcanouil commented 1 month ago

Would you mind trying to remove the unnecessary options?

---
title: "Quarto Playground"
format: beamer
---

## Slide 1

```{mermaid}
flowchart TB
    A[(Data Types)]
    A --> B(Boolean Type)
    A --> C(None Type)


I cannot reproduce on almost the same apparent setup (I'm on macOS Sequoia though).
Another difference is that I am using TinyTex as recommended by Quarto (https://quarto.org/docs/output-formats/pdf-engine.html).

What version of Chrome (or similar) are you using?
lrrichter commented 1 month ago

I get the same result with your example given above. I use a fresh install of MacTex 2024 (installed yesterday) incl. updates via the TeX Live Utility Chrome: Version 129.0.6668.101 (Offizieller Build) (x86_64) I will try to install TinyTex as well. BTW: Rendering of Python code with syntax highlighted to pdf works well with this version of Quarto.

mcanouil commented 1 month ago

I will try to install TinyTex as well.

Thanks!

BTW: Rendering of Python code with syntax highlighted to pdf works well with this version of Quarto.

Likely a Pandoc/Skylighting update in that regards.

cderv commented 1 month ago

Because of the ANSI color code problem (https://github.com/quarto-dev/quarto-cli/pull/10910/files) I had to use the version directly from the git repo (commit https://github.com/quarto-dev/quarto-cli/commit/46cdcc35dd3515f8509bd2b8080575b18eb7d350).

@lrrichter #10910 has been merged and available in 1.6.15 pre-release. You could use built pre-release to have it working if you don't want to bother with dev version with install from git.

This would also make sure that there is no side effect of configuration of the dev version.

/usr/local/bin/quarto: Zeile 192: 52556 Segmentation fault: 11 "${QUARTO_DENO}" ${QUARTO_ACTION} ${QUARTO_DENO_OPTIONS} ${QUARTO_DENO_EXTRA_OPTIONS} "${QUARTO_IMPORT_MAP_ARG}" "${QUARTO_TARGET}" "$@"

The error is not thrown by LaTeX rendering. It seems to be at Quarto level. Let's keep investigating !

Using mermaid for PDF output means that snapshoting using chrome will happen to make a version of the mermaid.js content available to LaTeX for PDF rendering.

If you have issue only with files using mermaid cells, then it could be linked to this processing.

Is this Segmentation Fault error happening with other type of rendering ?

Also can you activate debug logging : https://quarto.org/docs/troubleshooting/#verbose-mode Do you have a stack trace showing already ? Otherwise: https://quarto.org/docs/troubleshooting/#get-a-stack-trace

Thank you.

lrrichter commented 1 month ago

I have done the following:

Do you want the (now lengthy) full quarto check output?

cderv commented 1 month ago

Thanks a lot !

It would be really helpful if you could you try 1.6.18 and 1.6.19 ? Quarto 1.6.18 is when we updated to Deno 1.46.3 and it seems the Segmentation Fault is thown from Quarto script when calling Deno. So I suspect the update could be related...

Can you confirm this is only when having mermaid cell in your document that it fails ? Which would confirm that our processing for snapshoting with chrome could be involved.

lrrichter commented 1 month ago

Thanks for the advice. I will give it a try. Only how/where can I get Quarto version 1.6.18 and 1.6.19. I cannot see them on the pre-release builds page. If you could give me the concise git command I would try it. Regular text and Python compiles well to pdf. Some chapters down the road also contain dot, but I have not come so far.

mcanouil commented 1 month ago

All releases are on GitHub: https://github.com/quarto-dev/quarto-cli/releases

cderv commented 1 month ago

qvm (https://github.com/dpastoor/qvm) is also a good tool to test different Quarto version. It will download the required one from github release indeed.

Otherwise, it is through manual download and install, or using gh CLI to download: e.g for v1.6.18

gh release -R quarto-dev/quarto-cli download v1.6.18  --pattern '*-macos.tar.gz'
lrrichter commented 1 month ago

Thank you for your responses, actually before you answered if found git checkout version , followed by the run of ./configure.sh. The following results were created this way. For python/pdf I use a plain example and a complicated one with special syntax highlighting and a customized cls file. I attribute the problem with this to the tinytex config. The TeX code itself is ok and compiles. If this is insufficient I can repeat the experiments. And as last thing: I have not installed Chromium yet, which I also could try as last resort. Rendering Mermaid to pdf always fails.

version Reg. Cont.
pdf/html
Python Syn On
pdf/html
Python Syn off pdf/html Mermaid
pdf/html
Deno
Version
latest +/+ - TeX ok/ + +/+ -/+ 1.46.3
1.6.25 +/+ - TeX ok/+ +/+ -/+ 1.46.3
1.6.19 +/+ - TeX ok/+ +/+ -/+ 1.46.3
1.6.18 +/+ - TeX ok/+ +/+ -/+ 1.41.0
1.6.17 +/+ - TeX ok/+ +/+ -/+ 1.41.0
1.5.57 +/+ - TeX ok/+ +/+ -/+ 1.41.0
cderv commented 1 month ago

Thanks for your detailed test @lrrichter !

Let me try to understand all your examples...

For python/pdf I use a plain example and a complicated one with special syntax highlighting and a customized cls file.

We have no mermaid here right ? You are try to render some document to HTML and PDF with some generic content. I am asking because initial issue is about mermaid as the title is saying.

I attribute the problem with this to the tinytex config. The TeX code itself is ok and compiles.

Are we still talking a segmentation fault error here ? How is TinyTeX involved ? Do you have a .log file from failing xelatex run ? what is the error with TinyTeX ?

And as last thing: I have not installed Chromium yet, which I also could try as last resort. Rendering Mermaid to pdf always fails.

Using mermaid for a PDF output requires to have chromium or a chrome available so that snapshot can be done. https://quarto.org/docs/authoring/diagrams.html#chrome-install So if you don't have a chrome available, it will fail for sure.

Overall, I am really glad you tested extensively but I am now lost about what are the issues ? Is this still related to segmentation fault ?

Do you think there is one or several issues following your test ?

cderv commented 1 month ago

@Steinthal thanks for chiming in.

It looks like a different issue, possibly with same file content but not related to Segmentation fault, which is this original issue. (and format above is beamer)

It would be awesome if we can keep issue scoped and if we can open new issue when something is found not directly related.

Thank you !

Steinthal commented 1 month ago

@cderv, you're right, I jumped to the wrong conclusion. I deleted my post above ~and will open a new issue~. (a clean project works for me.)

lrrichter commented 1 month ago

Thanks for your detailed test @lrrichter !

Let me try to understand all your examples...

For python/pdf I use a plain example and a complicated one with special syntax highlighting and a customized cls file.

We have no mermaid here right ? You are try to render some document to HTML and PDF with some generic content. I am asking because initial issue is about mermaid as the title is saying.

In my MWE I did not mix the things. Everything is either or. One test file plain content. One test file standard python. One file python with my own cls file and advanced syntax highlighting. One file with only Mermaid.

The reason I mention the syntax hightlighting (escaping color codes for TeX) here, is because this was an error which was fixed rather recently. Only after that I ran into the Mermaid issues but the color thing still works. If this is confusing, do not mention it anymore.

I attribute the problem with this to the tinytex config. The TeX code itself is ok and compiles.

Are we still talking a segmentation fault error here ? How is TinyTeX involved ? Do you have a .log file from failing xelatex run ? what is the error with TinyTeX ?

Please ignore this. This is a minor thing. Tinytex currently does not find the cls file, but I think this is on my plate.

And as last thing: I have not installed Chromium yet, which I also could try as last resort. Rendering Mermaid to pdf always fails.

Using mermaid for a PDF output requires to have chromium or a chrome available so that snapshot can be done. https://quarto.org/docs/authoring/diagrams.html#chrome-install So if you don't have a chrome available, it will fail for sure.

I have chrome installed, not chromium. I don't know, if this could make a difference.

Overall, I am really glad you tested extensively but I am now lost about what are the issues ? Is this still related to segmentation fault ?

Do you think there is one or several issues following your test ?

My stickig point is only the Mermaid segfault.

mcanouil commented 1 month ago

To be clear, "chromium" is a basic browser that others use as the core for their browser: Chrome, Microsoft Edge, Brave, etc. By "chromium", it's meant to be read as "chromium-based". So, any "chromium-based" should work but Quarto only detects Chrome and Microsoft Edge for now.

cderv commented 1 month ago

@lrrichter Thanks for the precision !

My stickig point is only the Mermaid segfault.

So it means you have the issues with all versions, it may not be related to Deno update then. It rule that out.

I have chrome installed, not chromium. I don't know, if this could make a difference.

I do think the chromium devtool protocol inside chrome browser is ok. You could still do quarto install chromium to have a minimal chromium install used with Quarto, but I would be surprised this is the problem...

I am still thinking about a segmentation fault problem thrown by Deno for some reason... hard to know more without reproducing. 😞

@gordonwoodhull @cscheid if you have ideas about such error... thanks

gordonwoodhull commented 1 month ago

I have seen segfaults calling Deno but they have always been transient. (Twice since the Deno update; they had disappeared for a while.)

cscheid commented 1 month ago

I haven't been able to reproduce this segfault either, unfortunately.

github-actions[bot] commented 3 weeks ago

Thank you for using Quarto and reporting an issue!

Unfortunately, this issue is now considered stale because it has been opened since 14 days without providing a "working" reproducible example to help us investigate. If you are still facing the issue, please review the "Bug Reports" guide on how to provide a fully reproducible example as a self-contained Quarto document or a link to a Git repository. Without a reproducible example, it is unlikely that the issue will be addressed.

You can share a Quarto document using the following syntax, i.e., using more backticks than you have in your document (usually four ````).

````qmd
---
title: "Reproducible Quarto Document"
format: html
---

This is a reproducible Quarto document using `format: html`.
It is written in Markdown and contains embedded R code.
When you run the code, it will produce a plot.

```{r}
plot(cars)

The end.

cscheid commented 3 weeks ago

I'm going to go ahead and close this one for no activity. If we can find a way to reproduce the crash reliably in a simple test case, we should reopen. Thanks!