rich-iannone / quarto-email

MIT License
4 stars 0 forks source link

error with missing attachment #2

Closed aronatkins closed 1 year ago

aronatkins commented 1 year ago

When a named attachment does not exist (by user error or because that file is conditionally generated), this filter produces an error.

An example document:

---
title: bogus attachment
published-title: produced
format: html
filters:
  - rich-iannone/quarto-email
attachments:
  - data.csv
---

::: {.email}
:::

When rendered, the following error is produced:

Error running filter /Applications/RStudio.app/Contents/Resources/app/quarto/share/filters/main.lua:
...t/_extensions/rich-iannone/quarto-email/quarto-email.lua:272: attempt to index a nil value
stack traceback:
    ...t/_extensions/rich-iannone/quarto-email/quarto-email.lua:283: in function <...t/_extensions/rich-iannone/quarto-email/quarto-email.lua:281>
    [C]: in ?
    [C]: in method 'walk'
    ...app/Contents/Resources/app/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
    ...app/Contents/Resources/app/quarto/share/filters/main.lua:449: in local 'callback'
    [string "..."]:1789: in field 'withScriptFile'
    ...app/Contents/Resources/app/quarto/share/filters/main.lua:452: in upvalue 'run_emulated_filter_chain'
    ...app/Contents/Resources/app/quarto/share/filters/main.lua:495: in function <...app/Contents/Resources/app/quarto/share/filters/main.lua:476>
stack traceback:
    ...app/Contents/Resources/app/quarto/share/filters/main.lua:171: in function 'run_emulated_filter'
    ...app/Contents/Resources/app/quarto/share/filters/main.lua:449: in local 'callback'
    [string "..."]:1789: in field 'withScriptFile'
    ...app/Contents/Resources/app/quarto/share/filters/main.lua:452: in upvalue 'run_emulated_filter_chain'
    ...app/Contents/Resources/app/quarto/share/filters/main.lua:495: in function <...app/Contents/Resources/app/quarto/share/filters/main.lua:476>

Using Quarto 1.3.433 (distributed with recent RStudio daily builds, but shows errors both inside and outside RStudio).

rich-iannone commented 1 year ago

This is fixed in https://github.com/rich-iannone/quarto-email/commit/41da8d5bc858e66d4e19248e15d53c4f8c4a3b9b, where all declared attachment paths are filtered (checking for existence before writing an internal Lua table). There is additional safeguarding when copying files to the project dir (again, checking for file existence).

After the change, the Quarto error is no longer present and the example document renders correctly on Connect (main document and email sent to myself). Other documents (with correctly declared attachments) rendered fine as well.

rich-iannone commented 1 year ago

Given that this is solved, I'll close the issue. But definitely re-open if some edge case is caught.