travisf

travisf

I have a feature that allows users to generate PDFs. This is done by creating an HTML version of the page and using Puppeteer to render it to a PDF. This feature worked fine but recently we made some changes to our Cloudformation templates, and had to spin up new EC2 instances. This broke puppeteer. I’ve reinstalled it and updated the Node version. Now, however I’m not even getting to the PDF generate, the application is throwing this error message:

(Phoenix.Template.UndefinedError) Could not render "quote_pdf.html" for StorefrontWeb.PDFView, please define a matching clause for render/2 or define a template at "lib/storefront_web/templates/pdf/**/*". No templates were compiled for this module.

But quote_pdf.html does exist, it hasn’t moved or changed, and I’ve redeployed a few times just to be sure. I’ve even changed up the file suffix from, trying .html.eex .html.leex, .html.heex. I’ve also created other dummy HTML files in that directory to be sure.

#uses view to call `render/2`
 use StorefrontWeb, :view

  @spec to_pdf(Map.t()) :: {:ok, String.t()} | {:error, atom()}
  def to_pdf( assigns) do

    filename = create_filename(assigns)
    render_pdf("quote_pdf.html", filename, assigns)
  end

  # sobelow_skip ["Traversal.FileModule"]
  defp render_pdf(template, filename, %{quote_id: quote_id} = assigns) do
    root_path = Application.get_env(:storefront_web, :tmp_dir)

    with html <- render_html(template, assigns),
        # the next clauses are never called 
         html_path <- Path.join([root_path, "#{filename}.html"]),
         pdf_path <- Path.join([root_path, "#{filename}.pdf"]),
         :ok <- File.write(html_path, html),
         {_, 0} <-
           System.cmd("puppeteer-pdf", [
             html_path,
             "--path",
             pdf_path
           ]) do
     ... 
  end

  def render_html(template, assigns) do
    template
    |> __MODULE__.render(assigns)
    |> html_escape()
    |> safe_to_string()
  end

Any idea why my template is no longer being found? I mentioned the server and node updates because they happened at the same time this stopped working however all the related errors went away when I got Puppeteer installed so I don’t think they are related.

Showing Posts 1 to 4

senconscious

senconscious

Can you provide where is your view, template modules placed, theirs name. And how you call render/3 from your controller ? And also what is controller name. If you haven’t touched modules (like renaming or moving) thats strange. Also what are your phoenix, view versions ?

travisf

travisf OP

the view: app/apps/storefront_web/lib/storefront_web/views/pdf_view.ex
the template: app/apps/storefront_web/lib/storefront_web/templates/pdf/quote_pdf.html.eex

The view method, to_pdf/1 is not called by a controller, but a worker.

I didn’t make this clear above but this all works locally (all my tests have also worked locally as well).

I’d be curious if there was a way to view all the templates compiled for a module, I looked into how Phoenix does this a bit on Friday but was unable to find an easy way of doing it.

axelson

axelson

Scenic Core Team

Is the _build directory carried over between deploys on the server? If so maybe try clearing it out to force a full recompile.

travisf

travisf OP

Thanks for the advice, I’m beginning to think the whole missing template thing was a red herring. After rolling back the above mentioned changes I’m still getting errors from Puppeteer that it can’t find Chromium. I think that is the root of the issue rather than missing templates.

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 92995 915
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
caslu
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews