Merge remote branch 'cloudant:log_filepath_on_errors'
This closes #210
Signed-off-by: ILYA Khlopotov <iilyak@apache.org>
diff --git a/src/couch_file.erl b/src/couch_file.erl
index e7d9413..19e5998 100644
--- a/src/couch_file.erl
+++ b/src/couch_file.erl
@@ -428,10 +428,10 @@
% up to 8Kbs of read ahead
read_raw_iolist_int(File, Pos, ?READ_AHEAD - (Pos rem ?SIZE_BLOCK))
catch
- throw:read_beyond_eof ->
- throw(read_beyond_eof);
- throw:{exceed_pread_limit, Limit} ->
- throw({exceed_pread_limit, Limit});
+ throw:{read_beyond_eof, _} = Reason ->
+ throw(Reason);
+ throw:{exceed_pread_limit, _, _} = Reason ->
+ throw(Reason);
_:_ ->
read_raw_iolist_int(File, Pos, 4)
end,
@@ -625,10 +625,12 @@
case Pos + TotalBytes of
Size when Size > F#file.eof + ?READ_AHEAD ->
couch_stats:increment_counter([pread, exceed_eof]),
- throw(read_beyond_eof);
+ {_Fd, Filepath} = get(couch_file_fd),
+ throw({read_beyond_eof, Filepath});
Size when Size > Limit ->
couch_stats:increment_counter([pread, exceed_limit]),
- throw({exceed_pread_limit, Limit});
+ {_Fd, Filepath} = get(couch_file_fd),
+ throw({exceed_pread_limit, Filepath, Limit});
Size ->
{ok, <<RawBin:TotalBytes/binary>>} = file:pread(Fd, Pos, TotalBytes),
{remove_block_prefixes(BlockOffset, RawBin), Size}
diff --git a/test/couch_file_tests.erl b/test/couch_file_tests.erl
index 497999e..c16be16 100644
--- a/test/couch_file_tests.erl
+++ b/test/couch_file_tests.erl
@@ -139,7 +139,8 @@
ok = file:pwrite(Io, Pos, <<0:1/integer, DoubleBin:31/integer>>),
file:close(Io),
unlink(Fd),
- ExpectedError = {badmatch, {'EXIT', {bad_return_value, read_beyond_eof}}},
+ ExpectedError = {badmatch, {'EXIT', {bad_return_value,
+ {read_beyond_eof, Filepath}}}},
?_assertError(ExpectedError, couch_file:pread_binary(Fd, Pos)).
should_truncate(Fd) ->
@@ -175,11 +176,12 @@
}.
should_not_read_more_than_pread_limit(Fd) ->
+ {_, Filepath} = couch_file:process_info(Fd),
BigBin = list_to_binary(lists:duplicate(100000, 0)),
{ok, Pos, _Size} = couch_file:append_binary(Fd, BigBin),
unlink(Fd),
ExpectedError = {badmatch, {'EXIT', {bad_return_value,
- {exceed_pread_limit, 50000}}}},
+ {exceed_pread_limit, Filepath, 50000}}}},
?_assertError(ExpectedError, couch_file:pread_binary(Fd, Pos)).