Skip to content

Return a structured Image.Error from every open and write path - #218

Merged
kipcole9 merged 1 commit into
elixir-image:mainfrom
hlindset:fix/open-write-error-contract
Jul 28, 2026
Merged

Return a structured Image.Error from every open and write path#218
kipcole9 merged 1 commit into
elixir-image:mainfrom
hlindset:fix/open-write-error-contract

Conversation

@hlindset

@hlindset hlindset commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator
  • Every error path in Image.open/2 and Image.write/3 now returns {:error, %Image.Error{}}.
  • :operation is now set for all open and write errors
  • Fixes a bug where on error, Image.open!/2 would put the entire image into :path, and then interpolate it into :message
  • Simplify Image.Error.wrap/2, delegating the work to Image.Error.exception/1 instead. This removes potential error message drift (which had already happened for :enoent)
  • Remove Image.Error tuple constructors
  • Rename internal vix_open/2 to open_path/2 for consistency with the new open_binary/2 and open_enum/2 functions

Breaking changes:

  • Image.from_binary/2 returns {:error, %Image.Error{}} instead of {:error, binary}
  • Image.write/3 to a Plug.Conn returns %Image.Error{reason: :closed} rather than {:error, :closed}
  • Image.Error.exception(reason: :enoent, path: p) now has wrap/2's message, "The image file ... was not found or could not be opened", instead of "File not found: ..."
  • A {atom, value} reason built through Image.Error.wrap/2 gains the "Image error: " prefix
  • Internal:raise Image.Error, {:enoent, path} and raise Image.Error, {message, path} no longer have clauses and fall through to the catch-all (was documented behaviour)

@kipcole9
kipcole9 merged commit f7b7d8a into elixir-image:main Jul 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants