elixir-waffle/waffle

Feature request: custom validation errors

Closed this issue · 2 comments

It would be great if we could attach our own validations when files fail validate/1. That way on the file upload forms users would get a better message than "is invalid" (for example: "must be image file").

There's already a way to do this: https://github.com/elixir-waffle/waffle/blob/master/lib/waffle/definition/storage.ex#L94-L97. Note that valid/1 is overrideable, such that you can do as you please. If you want to perform a pipeline of validations, each with their own error messages, you could do so with the override.

@wulymammoth I don't think you can do that. Considering the overidable validate/1 being handled like this:

defp put(definition, {%Waffle.File{} = file, scope}) 
  case definition.validate({file, scope}) 
    true ->
      put_versions(definition, {file, scope})
      |> cleanup!(file)
    _    -> {:error, :invalid_file}
  end
end

Returning anything other than true will only gives you {:error, :invalid_file}