我在透析器中收到一个错误,当它分析以下功能。
-spec do_request(Method, Type, Url, Expect, Headers, Body, Client) -> Response::client_response()
when
Method :: method(),
Type :: content_type(),
Url :: url(),
Expect :: status_codes(),
Headers :: headers(),
Body :: body(),
Client :: #client{}.
do_request(Method, Type, Url, Expect, Headers, Body, Client) ->
Client2 = check_expired(Client),
Headers2 = add_auth_header(Headers, Client2),
%% error occurs on this line
Response = restc:request(Method, Type, binary_to_list(Url), Expect, Headers2, Body),
%%
{Response, Client2}.
错误是:
The call restc:request(Method::any(),Type::any(),
[byte()],Expect::any(),Headers2::[{binary(),binary()},...],
Body::any()) breaks the contract (Method::method(), Type::content_type(),
Url::url(), Expect::status_codes(), Headers::headers(),
Body::body()) -> Response::response()
restc:request
具有以下类型:
-spec request(Method::method(), Type::content_type(), Url::url(),
Expect::status_codes(), Headers::headers(), Body::body()) -> Response::response().
调用使用的类型有:
-type method() :: head | get | put | post | trace | options | delete.
-type url() :: binary().
-type headers() :: [header()].
-type header() :: {binary(), binary()}.
-type status_codes() :: [status_code()].
-type status_code() :: integer().
-type reason() :: term().
-type content_type() :: json | xml | percent.
-type property() :: atom() | tuple().
-type proplist() :: [property()].
-type body() :: proplist().
-type response() :: {ok, Status::status_code(), Headers::headers(), Body::body()} |
{error, Status::status_code(), Headers::headers(), Body::body()} |
{error, Reason::reason()}.
-type client_response() :: {response(), #client{}}.
-type token_type() :: bearer | unsupported.
为什么透透器说我的调用是传递变量与any()
类型,当我已经指定了传递变量的类型?我已经检查了调用链,以验证类型规范是一致的(并且与其他模块一致)。
问题是url()
被指定为binary()
,但您在那里传递[byte()]
(字符串)。您需要将url()
的类型规范更改为类似iodata()
的类型,或者通过先将其转换为二进制来限制您的输入。