Update Elixir from 1.7.4 to 1.8.0

elixir18

#1

I want to update elixir from 1.7.4 to 1.8.0. I did elixir update many times and never be difficult for me to update but this time it gives an error after update elixir version.

Here are error details:

== Compilation error in file lib/evercam_media_web/views/email_view.ex ==
** (BadMapError) expected a map, got: {:safe, [{:|, [], [{:__block__, [], [{:=, [], [{:tmp1, [], Phoenix.HTML.Engine}, [{:|, [], [{:__block__, [], [{:=, [], [{:tmp1, [], Phoenix.HTML.Engine}, [{:|, [], [{:__block__, [], [{:=, [], [{:tmp1, [], Phoenix.HTML.Engine}, [{:|, [], ["", "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" style=\"font-family: Arial, Helvetica, sans-serif; margin: 0; padding: 0;\">\n<head>\n  <meta name=\"viewport\" content=\"width=device-width\">\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n  <title>Evercam.io</title>\n</head>\n<body bgcolor=\"#FFFFFF\" style=\"font-family: Arial, Helvetica, sans-serif; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; margin: 0; padding: 0;\">\n<style type=\"text/css\">\n  @media only screen and (max-width: 600px) {\n    a[class=\"btn\"] {\n      display: block !important; margin-bottom: 10px !important; background-image: none !important; margin-right: 0 !important;\n    }\n    div[class=\"column\"] {\n      width: auto !important; float: none !important;\n    }\n    table.social div[class=\"column\"] {\n      width: auto !important;\n    }\n  }\n  @media only screen and (max-width: 480px){\n    .logo{\n      max-width:28% !important;\n      max-width:175px !important;\n    }\n  }\n</style>\n<!-- HEADER -->\n<table class=\"head-wrap\" bgcolor=\"#f5f5f5\" style=\"width: 100%; margin: 0; padding: 0;\">\n  <tr style=\"margin: 0; padding: 0;\">\n    <td style=\"margin: 0; padding: 0;\"></td>\n    <td class=\"header container\" style=\"display: block !important; clear: both !important; margin: 0 auto; padding: 0;\">\n      <div class=\"content\" style=\"display: block; margin: 0 auto; padding: 15px;\">\n        <table bgcolor=\"#f5f5f5\" style=\"width: 100%; margin: 0; padding: 0;\">\n          <tr style=\"margin: 0; padding: 0;text-align:center;\">\n            <td style=\"margin: 0; padding: 0;\">\n              <img src=\"https://www.evercam.io/img/logo.png\" class=\"logo\" style=\"max-width:28%;max-width:175px; padding-top:10px;margin:0;\">\n            </td>\n          </tr>\n        </table>\n      </div>\n    </td>\n    <td style=\"margin: 0; padding: 0;\"></td>\n  </tr>\n</table>\n<!-- /HEADER -->\n<!-- BODY -->\n<table class=\"body-wrap\" style=\"font-family: Arial, Helvetica, sans-serif; width: 100%; margin: 0; background-color:#f5f5f5; padding: 0;\">\n  <tr style=\"font-family: Arial, Helvetica, sans-serif; margin: 0; padding: 0;\"><td style=\"font-family: Arial, Helvetica, sans-serif; margin: 0; padding: 0;\"></td>\n    <td class=\"container\" bgcolor=\"#FFFFFF\" style=\"font-family: Arial, Helvetica, sans-serif; display: block !important; border-radius:3px; clear: both !important; margin: 0 auto; padding: 0;\">\n\n      <div class=\"content\" style=\"font-family: Arial, Helvetica, sans-serif; display: block; margin: 0 auto; padding: 15px;\">\n        <table style=\"font-family: Arial, Helvetica, sans-serif; width: 100%; margin: 0; padding: 0;\"><tr style=\"font-family: Arial, Helvetica, sans-serif; margin: 0; padding: 0;\">\n          <td style=\"font-family: Arial, Helvetica, sans-serif; font-weight: normal; font-size: 14px; margin: 0; padding: 0;\">\n\n            <p class=\"lead\" style=\"line-height: 1.6; margin: 0 0 10px; padding: 0;\">Hi "]}]]}, [{:|, [], [{:tmp1, [], Phoenix.HTML.Engine}, {:case, [generated: true], [{...}, ...]}]}]]}, ",</p>\n            <p style=\"line-height: 1.6; margin: 0 0 10px; padding: 0;\">This is just to let you know that "]}]]}, [{:|, [], [{:tmp1, [], Phoenix.HTML.Engine}, {:case, [generated: true], [{{:., [line: 57], [{:__aliases__, [line: 57, alias: false], [:Phoenix, :HTML, :Engine]}, :fetch_assign]}, [line: 57], [{:var!, [line: 57, context: Phoenix.HTML.Engine, import: Kernel], [{:assigns, [line: 57], Phoenix.HTML.Engine}]}, :sharee]}, [do: [{:->, [generated: true], [[safe: {:data, [generated: true], Phoenix.HTML.Engine}], {:data, [generated: true], Phoenix.HTML.Engine}]}, {:->, [generated: true], [[{:when, [generated: true], [{:bin, ...}, {...}]}], {{:., [generated: true], [{...}, ...]}, [generated: true], [{:bin, ...}]}]}, {:->, [generated: true], [[{:other, [generated: true], Phoenix.HTML.Engine}], {{:., [line: 57], [...]}, [line: 57], [{...}]}]}]]]}]}]]}, " has accepted your request to share the camera <strong>"]}]]}, [{:|, [], [{:tmp1, [], Phoenix.HTML.Engine}, {:case, [generated: true], [{{:., [line: 57], [{{:., [line: 57], [{:__aliases__, [line: 57, alias: false], [:Phoenix, :HTML, :Engine]}, :fetch_assign]}, [line: 57], [{:var!, [line: 57, context: Phoenix.HTML.Engine, import: Kernel], [{:assigns, [line: 57], Phoenix.HTML.Engine}]}, :camera]}, :name]}, [line: 57], []}, [do: [{:->, [generated: true], [[safe: {:data, [generated: true], Phoenix.HTML.Engine}], {:data, [generated: true], Phoenix.HTML.Engine}]}, {:->, [generated: true], [[{:when, [generated: true], [{:bin, [generated: true], Phoenix.HTML.Engine}, {:is_binary, [generated: true, context: Phoenix.HTML.Engine, import: Kernel], [{:bin, [generated: true], Phoenix.HTML.Engine}]}]}], {{:., [generated: true], [{:__aliases__, [generated: true, alias: false], [:Plug, :HTML]}, :html_escape]}, [generated: true], [{:bin, [generated: true], Phoenix.HTML.Engine}]}]}, {:->, [generated: true], [[{:other, [generated: true], Phoenix.HTML.Engine}], {{:., [line: 57], [{:__aliases__, [line: 57, alias: false], [:Phoenix, :HTML, :Safe]}, :to_iodata]}, [line: 57], [{:other, [line: 57], Phoenix.HTML.Engine}]}]}]]]}]}]]}, "</strong> with them. Nice one !</p>\n\n"]}]}
    (eex) lib/eex/engine.ex:161: EEx.Engine.handle_begin/1
    (eex) lib/eex/compiler.ex:54: EEx.Compiler.generate_buffer/4
    (phoenix) lib/phoenix/template.ex:349: Phoenix.Template.compile/3
    (phoenix) lib/phoenix/template.ex:160: anonymous fn/4 in Phoenix.Template."MACRO-__before_compile__"/2
    (elixir) lib/enum.ex:1940: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix) expanding macro: Phoenix.Template.__before_compile__/1
    lib/evercam_media_web/views/email_view.ex:1: EvercamMediaWeb.EmailView (module)
    (elixir) lib/kernel/parallel_compiler.ex:208: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

Try to solve but failed. Help to solve this issue?


#2

I understand from the error message that you are passing a keywords list instead of a Map. Could you share the code?


#3

First try doing rm -rf _build and then recompiling.


#4

Correct. mix still has some bugs that don’t replace _build when it should, this is always a good starting point.


#5

Yes, I thought too but mentioned file does not contain keywords list.

defmodule EvercamMediaWeb.EmailView do
  use EvercamMediaWeb, :view

  def full_name(user) do
    "#{user.firstname} #{user.lastname}"
  end

  def get_user_name(email) do
    email
    |> User.by_username_or_email
    |> User.get_fullname
  end
end

This is the file mentioned in error description.


#6

Same error.


#7

The cause of the issue is not in the module, but in one of the templates, which is compiled into the module (or at least should be).


#8

Yep, it’s some template that contains the text </strong> with them. Nice one !</p> for note.


#9

To be more precise, I believe the bug is actually in the template enginie. They may have been relying on some assumptions about how EEx works that may no longer be true in v1.8.


#10

OK, I found the issue. This error happens due to if-condition in my template. When I removed that condition it start working.

<p class="lead" style="line-height: 1.6; margin: 0 0 10px; padding: 0;">Hi <%= @user.firstname %>,</p>
<p style="line-height: 1.6; margin: 0 0 10px; padding: 0;">This is just to let you know that <%= @sharee %> has accepted your request to share the camera <strong><%= @camera.name %></strong> with them. Nice one !</p>

<%= if @thumbnail_available do %>
  <br>
  <img src="cid:snapshot.jpg" alt='Camera Preview' style="width: 100%; display:block; margin:0 auto;" >
<% end %>

Error occurred on <%= if @thumbnail_available do %>. what change it requires in 1.8?


#11

I found a solution for this issue. I just moved if-condition from template to view and then used that function in the template.

email_view.ex

def image_tag(has_thumbnail) do
        case has_thumbnail do
          true -> "<br><img src='cid:snapshot.jpg' alt='Camera Preview' style='width: 100%; display:block; margin:0 auto;' >"
          _ -> ""
        end
      end

template.html.eex

<p style="line-height: 1.6; margin: 0 0 10px; padding: 0;">This is just to let you know that <%= @sharee %> has accepted your request to share the camera with them. Nice one !</p>
<%= raw image_tag(@thumbnail_available) %>
<br>
<p style="line-height: 1.6; margin: 0 0 0px; padding: 0;">The Evercam Team</p>

Is it a correct way and according to the elixir standards?


#12

The bug is not in your template. Your template is fine. The bug is in whatever is compiling your templates. Probably in your e-mail handling library. Maybe updating the version will fix it. Your solution is fine, as it circumvents the issue, but at first there is nothing wrong with your template.


#13

I got a similar error in


#14

Does anyone know the root cause of the problem. I’m getting it with (I think) ecto_enum.


#15

Does anyone know the root cause of the problem. I’m getting it with (I think) ecto_enum.


#16

@shortlyportly please don’t bump a thread asking the same question only 16 hours apart. Also please understand that a BadMapError is a very generic error and if you’re not getting it in a view and specifically from EEx then it is almost surely a different issue than what is found in this thread. But please start a new post for the issue that are encountering with ecto_enum (and when you do please include a full stacktrace/error message and list applicable versions of depedencies).


#17

Apologies @Axelson - the second request was not due to impatience but the fact I thought I’d not actually asked the question. In terms of my problem I did think it was related hence why I asked the question.

Once again if this is not the right thing to do then apologies.

Dave


#18

No worries, the forum software does act funky at times. Please open a new topic if you’re still running into your issue!

Also for @azharmalik3’s and @norpan’s issues I’ve raised an Elixir bug to assist in getting a better/more informative error message: