Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix incorrect NIF error tuples #39

Merged
merged 1 commit into from

2 participants

@jtuple

Certain Bitcask NIFs would return {error, {error, Reason}} on failure rather than the expected {error, Reason} tuple. This would cause certain pattern matches to fail, such as the following:
https://github.com/basho/bitcask/blob/31b782aa4096d6084e57108f1ee0035be583dc50/src/bitcask.erl#L808

This pull-request fixes this error tuples.

@jonmeredith
Owner

Review of code looks good - can't find any other places where errors tuples are being wrapped and can trigger the new code easily enough.

7> [bitcask:put(Ref, <<I:32/integer>>, Bin) || I <- lists:seq(1,30000)].
** exception error: no match of right hand side value {error,enospc}
     in function  bitcask_fileops:write/4
     in call from bitcask:do_put/5
     in call from bitcask:put/3

Will review the erlang code calling the NIFs, then should be +1 for merge.

@jonmeredith
Owner

Passes bctt test and pulses tests.

+1 merge.

@jtuple jtuple merged commit 60e232b into from
@engelsanchez engelsanchez deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 4, 2012
  1. @jtuple

    Fix incorrect NIF error tuples

    jtuple authored
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 21 deletions.
  1. +7 −21 c_src/bitcask_nifs.c
View
28 c_src/bitcask_nifs.c
@@ -1304,9 +1304,7 @@ ERL_NIF_TERM bitcask_nifs_file_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM
}
else
{
- ERL_NIF_TERM error = enif_make_tuple2(env, ATOM_ERROR,
- enif_make_atom(env, erl_errno_id(errno)));
- return enif_make_tuple2(env, ATOM_ERROR, error);
+ return enif_make_tuple2(env, ATOM_ERROR, errno_atom(env, errno));
}
}
else
@@ -1346,9 +1344,7 @@ ERL_NIF_TERM bitcask_nifs_file_sync(ErlNifEnv* env, int argc, const ERL_NIF_TERM
}
else
{
- ERL_NIF_TERM error = enif_make_tuple2(env, ATOM_ERROR,
- enif_make_atom(env, erl_errno_id(errno)));
- return enif_make_tuple2(env, ATOM_ERROR, error);
+ return enif_make_tuple2(env, ATOM_ERROR, errno_atom(env, errno));
}
}
else
@@ -1404,9 +1400,7 @@ ERL_NIF_TERM bitcask_nifs_file_pread(ErlNifEnv* env, int argc, const ERL_NIF_TER
{
/* Read failed altogether */
enif_release_binary(&bin);
- ERL_NIF_TERM error = enif_make_tuple2(env, ATOM_ERROR,
- enif_make_atom(env, erl_errno_id(errno)));
- return enif_make_tuple2(env, ATOM_ERROR, error);
+ return enif_make_tuple2(env, ATOM_ERROR, errno_atom(env, errno));
}
}
else
@@ -1442,9 +1436,7 @@ ERL_NIF_TERM bitcask_nifs_file_pwrite(ErlNifEnv* env, int argc, const ERL_NIF_TE
else
{
/* Write failed altogether */
- ERL_NIF_TERM error = enif_make_tuple2(env, ATOM_ERROR,
- enif_make_atom(env, erl_errno_id(errno)));
- return enif_make_tuple2(env, ATOM_ERROR, error);
+ return enif_make_tuple2(env, ATOM_ERROR, errno_atom(env, errno));
}
}
@@ -1501,9 +1493,7 @@ ERL_NIF_TERM bitcask_nifs_file_read(ErlNifEnv* env, int argc, const ERL_NIF_TERM
{
/* Read failed altogether */
enif_release_binary(&bin);
- ERL_NIF_TERM error = enif_make_tuple2(env, ATOM_ERROR,
- enif_make_atom(env, erl_errno_id(errno)));
- return enif_make_tuple2(env, ATOM_ERROR, error);
+ return enif_make_tuple2(env, ATOM_ERROR, errno_atom(env, errno));
}
}
else
@@ -1534,9 +1524,7 @@ ERL_NIF_TERM bitcask_nifs_file_write(ErlNifEnv* env, int argc, const ERL_NIF_TER
else
{
/* Write failed altogether */
- ERL_NIF_TERM error = enif_make_tuple2(env, ATOM_ERROR,
- enif_make_atom(env, erl_errno_id(errno)));
- return enif_make_tuple2(env, ATOM_ERROR, error);
+ return enif_make_tuple2(env, ATOM_ERROR, errno_atom(env, errno));
}
}
@@ -1562,9 +1550,7 @@ ERL_NIF_TERM bitcask_nifs_file_seekbof(ErlNifEnv* env, int argc, const ERL_NIF_T
else
{
/* Write failed altogether */
- ERL_NIF_TERM error = enif_make_tuple2(env, ATOM_ERROR,
- enif_make_atom(env, erl_errno_id(errno)));
- return enif_make_tuple2(env, ATOM_ERROR, error);
+ return enif_make_tuple2(env, ATOM_ERROR, errno_atom(env, errno));
}
}
else
Something went wrong with that request. Please try again.