travisf

travisf

Missing templates on staging and production

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.

Most Liked

travisf

travisf

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.

Where Next?

Popular in Discussions Top

blackode
Elixir Upgrading is so Simple in Ubuntu and It worked for me Ubuntu 16.04 git clone https://github.com/elixir-lang/elixir.git cd elixir...
New
jeramyRR
This is an interesting article to read. Elixir’s performance, like usual, is excellent. However, it seems like the high CPU usage is co...
New
arpan
Hello everyone :wave: Today I am very excited to announce a project that I have been working on for almost 3 months now. The project is...
New
ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
rms.mrcs
A couple of days ago I was discussing with a friend about different approaches to write microservices. He said that if he was going to w...
New
jesse
Hi everyone, I hesitated to post this here because I don’t want you to think I’m spamming, but I’ve been working on a Platform-as-a-Serv...
New
paulanthonywilson
I like Umbrella projects and pretty much always use them for personal Elixir stuff, especially Nerves things. But I don’t think this is ...
New
Markusxmr
Since Drab has been developed for a while in the open, introducing the Liveview functionality in a way it happend appears to undermine th...
New
slashdotdash
Phoenix Live View is now publicly available on GitHub. Here’s Chris McCord’s tweet announcing making it public.
New

Other popular topics Top

albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement