Skip to content

Commit

Permalink
Log errors from Type conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
stavro committed May 10, 2018
1 parent 8972a7d commit 02e0eb0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 12 additions & 5 deletions lib/arc_ecto/type.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
defmodule Arc.Ecto.Type do
@moduledoc false
require Logger

def type, do: :string

@filename_with_timestamp ~r{^(.*)\?(\d+)$}
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 02e0eb0

Please sign in to comment.