Skip to content

Transform: Silent Failures which don't output file result in crash later on attempted File copy. #87

@holsee

Description

@holsee

Environment

  • Elixir version (elixir -v): OTP 24 Elixir 1.12.2
  • Waffle version (mix deps): 1.1.5
  • Waffle dependencies when applicable (mix deps): n/a
  • Operating system: OS X

Expected behaviour

An error should be returned when a file failed to be transformed (or at least when the output file does not exist).
The silent failure due to the 0 return code, means the actual issue is no obvious.
A change along the lines of the following would check that the expected output file exists before continuing.

Waffle.Transform.Convert @ apply/4

    result = System.cmd(program, args_list(args), stderr_to_stdout: true)

    case result do
      {_, 0} ->
        # Check that the transform output a new file to `new_path`
        if File.exists?(new_path) do
          {:ok, %Waffle.File{file | path: new_path, is_tempfile?: true}}
        else
          failed_cmd = Enum.join([program | arg_list(args)], " ")
          {:error, {"Transform failed silently as no file was output.", failed_cmd}}
        end

      {error_message, _exit_code} ->
        {:error, error_message}
    end

Actual behaviour

Throwing error as the output file does not exist due to silent conversion failure by transform function.

This issue was discovered when trying to convert an animated gif with image magick without the correct arguments to select the first frame during the conversion process. This I would suggest is not an uncommon occurrence as gif files are whitelisted in the generate default template and the transform will fail silently for animated versions.

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