Skip to content

How to use Witchcraft and Exceptional in the same module ? #81

@lkuty

Description

@lkuty

I use Elixir 1.10.2. My module has:

use Witchcraft, except: [>>>: 2]
use Exceptional

but at compilation time I get:

function >>>/2 imported from both Witchcraft.Chain and Exceptional.Raise, call is ambiguous
    expanding macro: Witchcraft.Monad.monad/2

If I try to do instead:

use Witchcraft, only: [monad: 2]
use Exceptional

Then I get:

:only and :except can only be given together to import when :only is either :functions or :macros

I am trying to add some error processing to my Timex usage which is not safe presently. I have copy pasted the code below to get an idea of my use case. It is used in a Phoenix web application.

    stream = monad Either.new() do
      date1 <- case Map.fetch(params, "date1") do
        {:ok, date1_s} -> case Date.from_iso8601(date1_s) do
          {:ok, date} -> date |> Timex.to_datetime(:local) |> Either.Right.new
          {:error, reason} -> Either.Left.new("error for date1: #{inspect(reason)}")
        end
        :error -> Timex.now(:local) |> Timex.beginning_of_day |> Either.Right.new
      end
      # ...    
      return HydroDB.Database.defaults(site, date1, date2, gens, newdefaults, regex)
    end
    case stream do
      %Either.Right{right: stream_} -> send_stream(conn, stream_, "text/xml")
      %Either.Left{left: error}     -> send_resp(conn, 422, error)
    end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions