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 Responses

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

Jayshua
I recently came across the javascript library htmx. It reminded me a lot of liveview so I thought the community here might be interested....
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
thojanssens1
It would be nice to be able to define a redirect from one route to another from the router.ex file. E.g.: redirect "/", UserController, ...
New
WildYorkies
It seems that the more I read, the more I find Elixir users speaking about all the ways that Elixir is not good for x, y, and z use cases...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
Crowdhailer
I’ve been hearing much about the new formatter and it’s something I have been keen to try. I find examples buy far the most illuminating...
248 19204 150
New
rower687
Hi all, I’ve been reading a lot about the “let it crash” term and how supervising processes and the whole messaging passing make an elixi...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
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
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

We're in Beta

About us Mission Statement