Skip to content

Commit

Permalink
Raise better exception on file errors (#66)
Browse files Browse the repository at this point in the history
* Raise better exception on file errors

* Fix tests on CI (and add newer Elixir/OTP to test matrix)

Ubuntu versions newer than 20.04 do not have OTP 22

* Replace is_exception/1 with explicit guards

Because is_exception/1 is only available since Elixir 1.11.0
  • Loading branch information
lucaong committed Dec 31, 2022
1 parent 0f384ad commit 94abc60
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ jobs:
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: '1.13.4'
otp-version: '24.3'
elixir-version: '1.14.2'
otp-version: '25.2'

- name: Restore dependencies cache
uses: actions/cache@v2
Expand All @@ -77,12 +77,14 @@ jobs:

test:
name: Test OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}}
runs-on: ubuntu-latest
runs-on: ubuntu-20.04 # Later Ubuntu versions do not have OTP 22
strategy:
matrix:
otp: ['22.2', '23.3', '24.3']
elixir: ['1.7.4', '1.8.2', '1.9.4', '1.10.4', '1.11.4', '1.12.3', '1.13.4']
otp: ['22.3', '23.3', '24.3', '25.2']
elixir: ['1.7.4', '1.8.2', '1.9.4', '1.10.4', '1.11.4', '1.12.3', '1.13.4', '1.14.2']
exclude:
- otp: '22.3'
elixir: '1.14.2'
- otp: '23.3'
elixir: '1.7.4'
- otp: '23.3'
Expand All @@ -99,6 +101,18 @@ jobs:
elixir: '1.9.4'
- otp: '24.3'
elixir: '1.10.4'
- otp: '25.2'
elixir: '1.7.4'
- otp: '25.2'
elixir: '1.8.2'
- otp: '25.2'
elixir: '1.9.4'
- otp: '25.2'
elixir: '1.10.4'
- otp: '25.2'
elixir: '1.11.4'
- otp: '25.2'
elixir: '1.12.3'
steps:
- uses: actions/checkout@v2
- name: Set up Elixir
Expand Down
7 changes: 6 additions & 1 deletion lib/cubdb/store/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,12 @@ defimpl CubDB.Store, for: CubDB.Store.File do

defp raise_if_error({:error, :enospc}), do: raise("No space left on device")

defp raise_if_error({:error, error}), do: raise(error)
defp raise_if_error({:error, error})
# is_exception is only available from Elixir 1.11
when is_map(error) and :erlang.is_map_key(:__exception__, error),
do: raise(error)

defp raise_if_error({:error, error}), do: raise("File error: #{inspect(error)}")

defp read_term(file, location) do
with {:ok, <<length::32>>, len} <- read_blocks(file, location, 4),
Expand Down

0 comments on commit 94abc60

Please sign in to comment.