From 02e0eb041469cd3580c18f83219931f73a9e9ecc Mon Sep 17 00:00:00 2001 From: Sean Stavropoulos Date: Thu, 10 May 2018 11:20:14 -0700 Subject: [PATCH] Log errors from Type conversions --- CHANGELOG.md | 2 +- README.md | 2 +- lib/arc_ecto/type.ex | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0715e53..f67e70f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## v0.8.0 (2017-07-15) +## v0.8.0 (2018-05-10) * (Enhancement) Use `NaiveDateTime` instead of `Ecto.DateTime`. * (Dependency Update) Require `ecto ~> 2.1` diff --git a/README.md b/README.md index 57598af..d003dea 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Add the latest stable release to your `mix.exs` file: ```elixir defp deps do [ - {:arc_ecto, "~> 0.7.0"} + {:arc_ecto, "~> 0.8.0"} ] end diff --git a/lib/arc_ecto/type.ex b/lib/arc_ecto/type.ex index 147b002..0801041 100644 --- a/lib/arc_ecto/type.ex +++ b/lib/arc_ecto/type.ex @@ -1,4 +1,7 @@ defmodule Arc.Ecto.Type do + @moduledoc false + require Logger + def type, do: :string @filename_with_timestamp ~r{^(.*)\?(\d+)$} @@ -7,10 +10,13 @@ defmodule Arc.Ecto.Type do def cast(_definition, %{"file_name" => file, "updated_at" => updated_at}) do {:ok, %{file_name: file, updated_at: updated_at}} end + def cast(definition, args) do case definition.store(args) do - {:ok, file} -> {:ok, %{file_name: file, updated_at: DateTime.utc_now() |> DateTime.to_naive()}} - _ -> :error + {:ok, file} -> {:ok, %{file_name: file, updated_at: NaiveDateTime.utc_now}} + error -> + Logger.error(inspect(error)) + :error end end @@ -26,9 +32,10 @@ defmodule Arc.Ecto.Type do updated_at = case gsec do gsec when is_binary(gsec) -> gsec - |> String.to_integer() - |> :calendar.gregorian_seconds_to_datetime() - |> NaiveDateTime.from_erl!() + |> String.to_integer + |> :calendar.gregorian_seconds_to_datetime + |> NaiveDateTime.from_erl! + _ -> nil end