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 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New

Other Trending Topics Top

marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews