From 0502de18524c160d295f2721b1b0f5211260737e Mon Sep 17 00:00:00 2001 From: Andrei Zavada Date: Thu, 4 Aug 2016 13:49:01 +0300 Subject: [PATCH 1/3] have characters_to_unicode_binary (which throws) return Val, not {ok, Val} --- src/riakc_ts.erl | 12 ++++++------ src/riakc_ts_get_operator.erl | 4 ++-- src/riakc_ts_put_operator.erl | 4 ++-- src/riakc_ts_query_operator.erl | 2 +- src/riakc_utils.erl | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/riakc_ts.erl b/src/riakc_ts.erl index 259c8e47..c9fe32c9 100644 --- a/src/riakc_ts.erl +++ b/src/riakc_ts.erl @@ -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, @@ -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, @@ -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), @@ -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(), diff --git a/src/riakc_ts_get_operator.erl b/src/riakc_ts_get_operator.erl index 9957334e..de39bd37 100644 --- a/src/riakc_ts_get_operator.erl +++ b/src/riakc_ts_get_operator.erl @@ -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}. diff --git a/src/riakc_ts_put_operator.erl b/src/riakc_ts_put_operator.erl index fdbcebfd..e87e0271 100644 --- a/src/riakc_ts_put_operator.erl +++ b/src/riakc_ts_put_operator.erl @@ -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 = [], diff --git a/src/riakc_ts_query_operator.erl b/src/riakc_ts_query_operator.erl index 80ff8692..e28cd247 100644 --- a/src/riakc_ts_query_operator.erl +++ b/src/riakc_ts_query_operator.erl @@ -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)}, diff --git a/src/riakc_utils.erl b/src/riakc_utils.erl index 1d4cc529..f85f9a05 100644 --- a/src/riakc_utils.erl +++ b/src/riakc_utils.erl @@ -45,5 +45,5 @@ characters_to_unicode_binary(String) -> ErrMsg = io_lib:format("Unicode encoding error. Encoded: ~p Rest: ~p", [Encoded, Rest]), throw({unicode_error, ErrMsg}); Binary -> - {ok, Binary} + Binary end. From 22df47c6f42f7b111f1b5108234fef6a0c852ef9 Mon Sep 17 00:00:00 2001 From: Andrei Zavada Date: Thu, 4 Aug 2016 14:01:27 +0300 Subject: [PATCH 2/3] flatten ErrMsg made with io_lib:format in characters_to_unicode_binary --- src/riakc_utils.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/riakc_utils.erl b/src/riakc_utils.erl index f85f9a05..36111ba2 100644 --- a/src/riakc_utils.erl +++ b/src/riakc_utils.erl @@ -39,10 +39,10 @@ wait_for_list(ReqId, Acc) -> 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 -> Binary From da505c8a53be2e305f099b3def31b65015abbdda Mon Sep 17 00:00:00 2001 From: Andrei Zavada Date: Thu, 4 Aug 2016 13:50:38 +0300 Subject: [PATCH 3/3] add a couple of specs in riakc_utils --- src/riakc_utils.erl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/riakc_utils.erl b/src/riakc_utils.erl index 36111ba2..fba298c2 100644 --- a/src/riakc_utils.erl +++ b/src/riakc_utils.erl @@ -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, []). @@ -34,6 +35,7 @@ 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) ->