Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return exceptions for all filesystem errors #44

Merged
merged 1 commit into from
Nov 14, 2023
Merged

Commits on Nov 7, 2023

  1. Return exceptions for all filesystem errors

    The following changes are aimed at simplifying the Briefly API:
    
    `Briefly.create()` and `Briefly.create(opts)` now return either `{:ok, path}` or
    `{:error, Exception.t()}`. The following exceptions may be returned:
    
      - `%Briefly.NoRootDirectoryError{}` - Returned if Briefly is unable to create a root temporary
        directory.
    
      - `%Briefly.WriteError{}` - Returned when a temporary entry cannot be created. The exception
        contains the POSIX error code the caused the failure.
    
    The `:too_many_attempts` error is not directly actionable so it is no longer surfaced. Since Briefly
    still performs several write attempts when faced with `:eexist` and `:eaccess` error codes, too many
    attempts can be inferred when either of those codes are returned.
    
    The error messages raised by `Briefly.create!()` have been moved to the Exception modules and aside
    from no longer printing the number of attempts they provide the same information.
    
    For example, if you have this:
    
    ```elixir
    case Briefly.create() do
      {:ok, path} -> path
      {:no_space, _} -> raise "no space"
      {:too_many_attempts, _} -> raise "too many attempts"
      {:no_tmp, _} -> raise "no tmp dirs"
    end
    ```
    
    ...then change it to this:
    
    ```elixir
    case Briefly.create() do
      {:ok, path} -> path
      {:error, %Briefly.WriteError{code: :enospc}} -> raise "no space"
      {:error, %Briefly.WriteError{code: c}} when c in [:eexist, :eacces] -> raise "too many attempts"
      {:error, %Briefly.NoRootDirectoryError{}} -> raise "no tmp dirs"
      {:error, exception} -> raise exception
    end
    ```
    mcrumm committed Nov 7, 2023
    Configuration menu
    Copy the full SHA
    6b98fe9 View commit details
    Browse the repository at this point in the history