Browse Source

wrap fetch errors in rebar_fetch PRV_ERROR

pull/414/head
Tristan Sloughter 10 years ago
parent
commit
1643f4a1fc
2 changed files with 10 additions and 9 deletions
  1. +5
    -3
      src/rebar_fetch.erl
  2. +5
    -6
      src/rebar_pkg_resource.erl

+ 5
- 3
src/rebar_fetch.erl View File

@ -30,7 +30,7 @@ download_source(AppDir, Source, State) ->
true -> true ->
true; true;
Error -> Error ->
throw(Error)
throw(?PRV_ERROR(Error))
catch catch
C:T -> C:T ->
?DEBUG("rebar_fetch exception ~p ~p ~p", [C, T, erlang:get_stacktrace()]), ?DEBUG("rebar_fetch exception ~p ~p ~p", [C, T, erlang:get_stacktrace()]),
@ -65,10 +65,12 @@ needs_update(AppDir, Source, State) ->
true true
end. end.
format_error({failed_extract, CachePath}) ->
io_lib:format("Failed to extract package: ~s", [CachePath]);
format_error({bad_etag, Source}) -> format_error({bad_etag, Source}) ->
io_lib:format("MD5 Checksum comparison failed for: ~p", [Source]);
io_lib:format("MD5 Checksum comparison failed for: ~s", [Source]);
format_error({fetch_fail, Source}) -> format_error({fetch_fail, Source}) ->
io_lib:format("Failed to fetch and copy dep: ~p", [Source]);
io_lib:format("Failed to fetch and copy dep: ~s", [Source]);
format_error({bad_checksum, File}) -> format_error({bad_checksum, File}) ->
io_lib:format("Checksum mismatch against tarball in ~s", [File]); io_lib:format("Checksum mismatch against tarball in ~s", [File]);
format_error({bad_registry_checksum, File}) -> format_error({bad_registry_checksum, File}) ->

+ 5
- 6
src/rebar_pkg_resource.erl View File

@ -9,7 +9,6 @@
,needs_update/2 ,needs_update/2
,make_vsn/1]). ,make_vsn/1]).
-include_lib("providers/include/providers.hrl").
-include("rebar.hrl"). -include("rebar.hrl").
-define(DEFAULT_CDN, "https://s3.amazonaws.com/s3.hex.pm/tarballs"). -define(DEFAULT_CDN, "https://s3.amazonaws.com/s3.hex.pm/tarballs").
@ -44,7 +43,7 @@ cached_download(TmpDir, CachePath, Pkg, Url, ETag, State) ->
?DEBUG("Download ~s error, using ~s from cache", [Url, CachePath]), ?DEBUG("Download ~s error, using ~s from cache", [Url, CachePath]),
serve_from_cache(TmpDir, CachePath, Pkg, State); serve_from_cache(TmpDir, CachePath, Pkg, State);
error -> error ->
throw(request_failed)
request_failed
end. end.
serve_from_cache(TmpDir, CachePath, Pkg, State) -> serve_from_cache(TmpDir, CachePath, Pkg, State) ->
@ -54,11 +53,11 @@ serve_from_cache(TmpDir, CachePath, Pkg, State) ->
ok = erl_tar:extract({binary, Contents}, [{cwd, TmpDir}, compressed]), ok = erl_tar:extract({binary, Contents}, [{cwd, TmpDir}, compressed]),
{ok, true}; {ok, true};
{_Bin, Chk, Chk} -> {_Bin, Chk, Chk} ->
?PRV_ERROR({failed_extract, CachePath});
{failed_extract, CachePath};
{Chk, _Reg, Chk} -> {Chk, _Reg, Chk} ->
?PRV_ERROR({bad_registry_checksum, CachePath});
{bad_registry_checksum, CachePath};
{_Bin, _Reg, _Tar} -> {_Bin, _Reg, _Tar} ->
?PRV_ERROR({bad_checksum, CachePath})
{bad_checksum, CachePath}
end. end.
serve_from_download(TmpDir, CachePath, Package, ETag, Binary, State) -> serve_from_download(TmpDir, CachePath, Package, ETag, Binary, State) ->
@ -69,7 +68,7 @@ serve_from_download(TmpDir, CachePath, Package, ETag, Binary, State) ->
serve_from_cache(TmpDir, CachePath, Package, State); serve_from_cache(TmpDir, CachePath, Package, State);
FileETag -> FileETag ->
?DEBUG("Download ETag ~s doesn't match cached ETag ~s", [ETag, FileETag]), ?DEBUG("Download ETag ~s doesn't match cached ETag ~s", [ETag, FileETag]),
?PRV_ERROR({bad_download, CachePath})
{bad_download, CachePath}
end. end.

Loading…
Cancel
Save