summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <tristan.sloughter@gmail.com>2015-08-23 09:21:35 -0500
committerTristan Sloughter <tristan.sloughter@gmail.com>2015-08-23 09:21:35 -0500
commit657a1bf52e4de27d3d302de707fdd53fa3d0632e (patch)
tree5724696bc29083a23f05174e3daf669b065426de
parent725e2e9d255c7c2f8c680f60eb1b82284d55a333 (diff)
parentdae1b4cc827edbe805c74ae4abcff7ad5571f569 (diff)
Merge pull request #742 from tsloughter/pkg_check
improve error messages for packages by checking its existance before fetch
-rw-r--r--src/rebar_app_utils.erl18
-rw-r--r--src/rebar_fetch.erl2
-rw-r--r--src/rebar_packages.erl8
-rw-r--r--src/rebar_prv_app_discovery.erl4
-rw-r--r--src/rebar_prv_install_deps.erl2
-rw-r--r--src/rebar_prv_update.erl1
6 files changed, 29 insertions, 6 deletions
diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl
index b14c50a..7239fe7 100644
--- a/src/rebar_app_utils.erl
+++ b/src/rebar_app_utils.erl
@@ -126,6 +126,8 @@ parse_dep(Parent, {Name, Vsn}, DepsDir, IsLock, State) when is_list(Vsn); is_bin
not_found ->
{PkgName, PkgVsn} = parse_goal(ec_cnv:to_binary(Name)
,ec_cnv:to_binary(Vsn)),
+ %% Verify package actually exists. This will throw a missing_package exception
+ rebar_packages:deps(PkgName, PkgVsn, State),
Source = {pkg, PkgName, PkgVsn},
rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, PkgName, PkgVsn, Source, IsLock, State), pkg)
end;
@@ -137,6 +139,8 @@ parse_dep(Parent, Name, DepsDir, IsLock, State) when is_atom(Name); is_binary(Na
{ok, _App} ->
dep_to_app(root, DepsDir, Name, [], [], IsLock, State);
not_found ->
+ %% Verify package actually exists. This will throw a missing_package exception
+ rebar_packages:deps(PkgName, PkgVsn, State),
Source = {pkg, PkgName, PkgVsn},
rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, PkgName, PkgVsn, Source, IsLock, State), pkg)
end;
@@ -153,6 +157,8 @@ parse_dep(Parent, {_Name, {pkg, Name, Vsn}, Level}, DepsDir, IsLock, State) when
{ok, _App} ->
dep_to_app(root, DepsDir, Name, [], [], IsLock, State);
not_found ->
+ %% Verify package actually exists. This will throw a missing_package exception
+ rebar_packages:deps(Name, Vsn, State),
Source = {pkg, Name, Vsn},
rebar_app_info:resource_type(dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State), pkg)
end;
@@ -193,6 +199,10 @@ dep_to_app(Parent, DepsDir, Name, Vsn, Source, IsLock, State) ->
end,
rebar_app_info:resource_type(rebar_app_info:parent(AppInfo, Parent), ResourceType).
+format_error({missing_package, Package}) ->
+ io_lib:format("Package not found in registry: ~s", [Package]);
+format_error({parse_dep, Dep}) ->
+ io_lib:format("Failed parsing dep ~p", [Dep]);
format_error(Error) ->
io_lib:format("~p", [Error]).
@@ -212,8 +222,12 @@ parse_goal(Name, Constraint) ->
end.
get_package(Dep, State) ->
- {ok, HighestDepVsn} = rebar_packages:find_highest_matching(Dep, "0", ?PACKAGE_TABLE, State),
- {Dep, HighestDepVsn}.
+ case rebar_packages:find_highest_matching(Dep, "0", ?PACKAGE_TABLE, State) of
+ {ok, HighestDepVsn} ->
+ {Dep, HighestDepVsn};
+ none ->
+ throw(?PRV_ERROR({missing_package, ec_cnv:to_binary(Dep)}))
+ end.
-spec has_all_beams(file:filename_all(), [module()]) ->
true | ?PRV_ERROR({missing_module, module()}).
diff --git a/src/rebar_fetch.erl b/src/rebar_fetch.erl
index 64c5380..b80c125 100644
--- a/src/rebar_fetch.erl
+++ b/src/rebar_fetch.erl
@@ -71,6 +71,8 @@ format_error({failed_extract, CachePath}) ->
io_lib:format("Failed to extract package: ~s", [CachePath]);
format_error({bad_etag, Source}) ->
io_lib:format("MD5 Checksum comparison failed for: ~s", [Source]);
+format_error({fetch_fail, Name, Vsn}) ->
+ io_lib:format("Failed to fetch and copy dep: ~s-~s", [Name, Vsn]);
format_error({fetch_fail, Source}) ->
io_lib:format("Failed to fetch and copy dep: ~p", [Source]);
format_error({bad_checksum, File}) ->
diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl
index 3352323..e3346ae 100644
--- a/src/rebar_packages.erl
+++ b/src/rebar_packages.erl
@@ -106,7 +106,7 @@ registry_checksum({pkg, Name, Vsn}, State) ->
%% `~> 2.1` | `>= 2.1.0 and < 3.0.0`
find_highest_matching(Dep, Constraint, Table, State) ->
verify_table(State),
- case ets:lookup_element(Table, Dep, 2) of
+ try ets:lookup_element(Table, Dep, 2) of
[[HeadVsn | VsnTail]] ->
{ok, handle_vsns(Constraint, HeadVsn, VsnTail)};
[[Vsn]] ->
@@ -114,9 +114,9 @@ find_highest_matching(Dep, Constraint, Table, State) ->
[Vsn] ->
handle_single_vsn(Dep, Vsn, Constraint);
[HeadVsn | VsnTail] ->
- {ok, handle_vsns(Constraint, HeadVsn, VsnTail)};
- [] ->
- ?WARN("Missing registry entry for package ~s. Try to fix with `rebar3 update`", [Dep]),
+ {ok, handle_vsns(Constraint, HeadVsn, VsnTail)}
+ catch
+ error:badarg ->
none
end.
diff --git a/src/rebar_prv_app_discovery.erl b/src/rebar_prv_app_discovery.erl
index ea55e11..5449f82 100644
--- a/src/rebar_prv_app_discovery.erl
+++ b/src/rebar_prv_app_discovery.erl
@@ -38,6 +38,10 @@ do(State) ->
State1 = rebar_app_discover:do(State, LibDirs),
{ok, State1}
catch
+ throw:{error, {rebar_packages, Error}} ->
+ {error, {rebar_packages, Error}};
+ throw:{error, {rebar_app_utils, Error}} ->
+ {error, {rebar_app_utils, Error}};
throw:{error, Error} ->
?PRV_ERROR(Error)
end.
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index 0b0f607..49116fc 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -108,6 +108,8 @@ format_error({not_rebar_package, Package, Version}) ->
io_lib:format("Package not buildable with rebar3: ~s-~s", [Package, Version]);
format_error({missing_package, Package, Version}) ->
io_lib:format("Package not found in registry: ~s-~s", [Package, Version]);
+format_error({missing_package, Package}) ->
+ io_lib:format("Package not found in registry: ~s", [Package]);
format_error({cycles, Cycles}) ->
Prints = [["applications: ",
[io_lib:format("~s ", [Dep]) || Dep <- Cycle],
diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl
index a4628b2..10faf4d 100644
--- a/src/rebar_prv_update.erl
+++ b/src/rebar_prv_update.erl
@@ -117,6 +117,7 @@ update_deps_list(Deps, HexRegistry, State) ->
{ok, HighestDepVsn} ->
[{Dep, HighestDepVsn} | DepsListAcc];
none ->
+ ?WARN("Missing registry entry for package ~s. Try to fix with `rebar3 update`", [Dep]),
DepsListAcc
end;
Vsn ->