Return errors everywhere instead of exit. Remove zx logger.

This commit is contained in:
Craig Everett 2025-05-19 20:20:11 +09:00
parent bef57f261d
commit f31e4edd4a

View File

@ -22,7 +22,6 @@
bin_to_int/1]).
-include("http.hrl").
-include("$zx_include/zx_logger.hrl").
-spec parse(Socket, Received) -> Result
@ -193,16 +192,13 @@ read_method(Socket, Received) when byte_size(Received) < 7 ->
{tcp, Socket, Bin} ->
read_method(Socket, <<Received/binary, Bin/binary>>);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end;
{error, Reason} ->
Message = "inet:setopts/2 failed in read_method/2 with ~tp",
ok = tell(info, Message, [Reason]),
{error, {inet, Reason}}
end;
read_method(_, _) ->
@ -228,10 +224,9 @@ read_path(Socket, <<>>, Acc) ->
{tcp, Socket, Bin} ->
read_path(Socket, Bin, Acc);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end;
@ -267,10 +262,9 @@ read_qkey(Socket, <<>>, Acc, Qargs) ->
{tcp, Socket, Bin} ->
read_qkey(Socket, Bin, Acc, Qargs);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end.
@ -297,10 +291,9 @@ read_qval(Socket, <<>>, Acc, Key, Qargs) ->
{tcp, Socket, Bin} ->
read_qval(Socket, Bin, Acc, Key, Qargs);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end.
@ -327,10 +320,9 @@ read_fragment(Socket, <<>>, Acc) ->
{tcp, Socket, Bin} ->
read_fragment(Socket, Bin, Acc);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end.
@ -348,10 +340,9 @@ read_version(Socket, Acc) when byte_size(Acc) =< 10 ->
{tcp, Socket, Bin} ->
read_version(Socket, <<Acc/binary, Bin/binary>>);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end;
@ -365,10 +356,9 @@ read_headers(Socket, <<"\r">>) ->
{tcp, Socket, Bin} ->
read_headers(Socket, <<"\r", Bin/binary>>);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end;
@ -394,15 +384,13 @@ read_hkey(Socket, <<>>, Acc, Headers) ->
{tcp, Socket, Bin} ->
read_hkey(Socket, Bin, Acc, Headers);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end;
read_hkey(_, Received, _, _) ->
log(info, "~p Headers died at: ~p", [?LINE, Received]),
read_hkey(_, _, _, _) ->
{error, headers}.
skip_hblanks(Socket, <<" ", Rest/binary>>, Key, Headers) ->
@ -413,10 +401,9 @@ skip_hblanks(Socket, <<>>, Key, Headers) ->
{tcp, Socket, Bin} ->
skip_hblanks(Socket, Bin, Key, Headers);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end;
@ -433,15 +420,13 @@ read_hval(Socket, <<>>, Val, Key, Headers) ->
{tcp, Socket, Bin} ->
read_hval(Socket, Bin, Val, Key, Headers);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end;
read_hval(_, Received, _, _, _) ->
log(info, "~p Headers died at: ~p", [?LINE, Received]),
read_hval(_, _, _, _, _) ->
{error, headers}.
read_enctype(#request{method = get}) ->
@ -588,10 +573,9 @@ simple_multipart(Socket, Received, Seps, Parts) ->
{tcp, Socket, Bin} ->
simple_multipart(Socket, <<Received/binary, Bin/binary>>, Seps, Parts);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end.
@ -715,10 +699,9 @@ unfuck_form_data(Socket, Received, Acc, Seps, Size) when Size < 52428800 ->
NewBin = <<Received/binary, Bin/binary>>,
unfuck_form_data(Socket, NewBin, Acc, Seps);
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end;
@ -845,10 +828,9 @@ accumulate(Socket, Remaining, Received) when Remaining > 0 ->
{ok, NewReceived, Next}
end;
{tcp_closed, Socket} ->
exit(normal);
{error, tcp_closed};
{tcp_error, Socket, Reason} ->
ok = tell(info, "Socket error: ~p", [Reason]),
exit(normal)
{error, {tcp_error, Reason}}
after 3000 ->
{error, timeout}
end;