Skip to content

Commit

Permalink
improve input validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-hek committed Aug 29, 2024
1 parent 91bff32 commit c0090e1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/boombox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ defmodule Boombox do

@spec run(Enumerable.t(), input: input, output: output) :: :ok | Enumerable.t()
def run(stream \\ nil, opts) do
opts =
Keyword.validate!(opts, [:input, :output])
|> Map.new(fn {k, v} -> {k, parse_opt!(k, v)} end)
opts_keys = [:input, :output]
opts = Keyword.validate!(opts, opts_keys) |> Map.new(fn {k, v} -> {k, parse_opt!(k, v)} end)

if key = Enum.find(opts_keys, fn k -> not is_map_key(opts, k) end) do
raise "#{key} is not provided"
end

case opts do
%{input: {:stream, _in_stream_opts}, output: {:stream, _out_stream_opts}} ->
Expand Down

0 comments on commit c0090e1

Please sign in to comment.