Skip to content

Commit

Permalink
Merge pull request #308 from basho/fix-az-let_throwing_funs_return_ju…
Browse files Browse the repository at this point in the history
…st_value

small enhancements to #307 (manual merge because bors is out to lunch)
  • Loading branch information
hmmr authored Aug 4, 2016
2 parents 04ad523 + da505c8 commit 621d09b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/riakc_ts.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ query_common(Pid, Query, Interpolations, Cover, Options)
-spec get_coverage(pid(), table_name(), QueryText::iolist()) ->
{ok, Entries::[term()]} | {error, term()}.
get_coverage(Pid, Table, Query) ->
{ok, T} = riakc_utils:characters_to_unicode_binary(Table),
{ok, Q} = riakc_utils:characters_to_unicode_binary(Query),
T = riakc_utils:characters_to_unicode_binary(Table),
Q = riakc_utils:characters_to_unicode_binary(Query),
Message =
#tscoveragereq{'query' = #tsinterpolation{base = Q},
replace_cover = undefined,
Expand All @@ -117,8 +117,8 @@ replace_coverage(Pid, Table, Query, Cover) ->
OtherCover::list(binary())) ->
{ok, Entries::[term()]} | {error, term()}.
replace_coverage(Pid, Table, Query, Cover, Other) ->
{ok, T} = riakc_utils:characters_to_unicode_binary(Table),
{ok, Q} = riakc_utils:characters_to_unicode_binary(Query),
T = riakc_utils:characters_to_unicode_binary(Table),
Q = riakc_utils:characters_to_unicode_binary(Query),
Message =
#tscoveragereq{'query' = #tsinterpolation{base = Q},
replace_cover = Cover,
Expand Down Expand Up @@ -174,7 +174,7 @@ put(Pid, Table, Measurements, Options)
delete(Pid, Table, Key, Options)
when is_pid(Pid), (is_binary(Table) orelse is_list(Table)),
is_list(Key), is_list(Options) ->
{ok, T} = riakc_utils:characters_to_unicode_binary(Table),
T = riakc_utils:characters_to_unicode_binary(Table),
Message = #tsdelreq{table = T,
key = riak_pb_ts_codec:encode_cells_non_strict(Key),
vclock = proplists:get_value(vclock, Options),
Expand Down Expand Up @@ -224,7 +224,7 @@ stream_list_keys(Pid, Table, Timeout) when is_integer(Timeout) ->
stream_list_keys(Pid, Table, [{timeout, Timeout}]);
stream_list_keys(Pid, Table, Options)
when is_pid(Pid), (is_binary(Table) orelse is_list(Table)), is_list(Options) ->
{ok, T} = riakc_utils:characters_to_unicode_binary(Table),
T = riakc_utils:characters_to_unicode_binary(Table),
ReqTimeout = proplists:get_value(timeout, Options),
Req = #tslistkeysreq{table = T, timeout = ReqTimeout},
ReqId = riakc_pb_socket:mk_reqid(),
Expand Down
4 changes: 2 additions & 2 deletions src/riakc_ts_get_operator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@


serialize(Table, Key, true) ->
{ok, T} = riakc_utils:characters_to_unicode_binary(Table),
T = riakc_utils:characters_to_unicode_binary(Table),
#tsgetreq{table = T, key = Key};
serialize(Table, Key, false) ->
{ok, T} = riakc_utils:characters_to_unicode_binary(Table),
T = riakc_utils:characters_to_unicode_binary(Table),
SerializedKey = riak_pb_ts_codec:encode_cells_non_strict(Key),
#tsgetreq{table = T, key = SerializedKey}.

Expand Down
4 changes: 2 additions & 2 deletions src/riakc_ts_put_operator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
%% As of 2015-11-05, columns parameter is ignored, Riak TS
%% expects the full set of fields in each element of Data.
serialize(TableName, Measurements, true) ->
{ok, T} = riakc_utils:characters_to_unicode_binary(TableName),
T = riakc_utils:characters_to_unicode_binary(TableName),
#tsputreq{table = T,
columns = [],
rows = Measurements};
serialize(TableName, Measurements, false) ->
{ok, T} = riakc_utils:characters_to_unicode_binary(TableName),
T = riakc_utils:characters_to_unicode_binary(TableName),
SerializedRows = riak_pb_ts_codec:encode_rows_non_strict(Measurements),
#tsputreq{table = T,
columns = [],
Expand Down
2 changes: 1 addition & 1 deletion src/riakc_ts_query_operator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

serialize(QueryText, Interpolations)
when is_binary(QueryText) orelse is_list(QueryText) ->
{ok, Q} = riakc_utils:characters_to_unicode_binary(QueryText),
Q = riakc_utils:characters_to_unicode_binary(QueryText),
Content = #tsinterpolation{
base = Q,
interpolations = serialize_interpolations(Interpolations)},
Expand Down
8 changes: 5 additions & 3 deletions src/riakc_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

-export([wait_for_list/1, characters_to_unicode_binary/1]).

-spec wait_for_list(non_neg_integer()) -> {ok, list()} | {error, any()}.
%% @doc Wait for the results of a listing operation
wait_for_list(ReqId) ->
wait_for_list(ReqId, []).
Expand All @@ -34,16 +35,17 @@ wait_for_list(ReqId, Acc) ->
{ReqId, {_, Res}} -> wait_for_list(ReqId, [Res|Acc])
end.

-spec characters_to_unicode_binary(string()|binary()) -> binary().
%% @doc Convert to unicode binary with informative errors
%% @throws {unicode_error, ErrMsg}
characters_to_unicode_binary(String) ->
case unicode:characters_to_binary(String) of
{incomplete, Encoded, Rest} ->
ErrMsg = io_lib:format("Incomplete unicode data provided. Encoded: ~p Rest: ~p", [Encoded, Rest]),
ErrMsg = lists:flatten(io_lib:format("Incomplete unicode data provided. Encoded: ~p Rest: ~p", [Encoded, Rest])),
throw({unicode_error, ErrMsg});
{error, Encoded, Rest} ->
ErrMsg = io_lib:format("Unicode encoding error. Encoded: ~p Rest: ~p", [Encoded, Rest]),
ErrMsg = lists:flatten(io_lib:format("Unicode encoding error. Encoded: ~p Rest: ~p", [Encoded, Rest])),
throw({unicode_error, ErrMsg});
Binary ->
{ok, Binary}
Binary
end.

0 comments on commit 621d09b

Please sign in to comment.