[erlang-bugs] {packet, http} with gen_tcp:connect/2 problem

Kostis Sagonas kostis@REDACTED
Thu Oct 29 16:47:25 CET 2009


Sverker Eriksson wrote:
> Hi,
> 
> gen_tcp:recv has been returning {error,{http_error,_}} instead of 
> {ok,{...}} since the beginning (when it was an undocumented feature used 
> by some privileged applications), so I don't think we can change that 
> without breaking backwards compatibility. I guess we have to introduce 
> this "exception to the rule" in both the documentation and dialyzer.

I do not really see any problem as far as backwards compatibility for 
the masses is concerned.  Even today, the documented behaviour of 
gen_tcp (http://www.erlang.org/doc/man/gen_tcp.html) reads:

   recv(Socket, Length) -> {ok, Packet} | {error, Reason}
   recv(Socket, Length, Timeout) -> {ok, Packet} | {error, Reason}

   Types:
    Socket = socket()
    Length = int()
    Packet = [char()] | binary()
    Timeout = int() | infinity
    Reason = closed | posix()

where posix() is an atom.

Programs that explicitly match on {error, {http_error, _}} rely on 
something undocumented and they should know better that this could 
change at any time.

Moreover, dialyzer exists and automatically identifies all these places 
in the code and is there to help users in changing them.

What's the problem in making the right decision here?

Erlang has too many inconsistent return values in its key functions. 
Does it need another one?

Kostis


More information about the erlang-bugs mailing list