Skip to content

Commit

Permalink
Handle all doc and package creation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
starbelly committed Dec 24, 2021
1 parent 9f1ac0f commit a3632b9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/rebar3_hex_build.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,24 @@ create_package(State, #{name := RepoName} = _Repo, App) ->
| OptionalFiltered
]),

Tarball = create_package_tarball(Metadata, PackageFiles),

Package = #{
name => PkgName,
repo_name => RepoName,
deps => Deps1,
version => Version,
metadata => Metadata,
files => PackageFiles,
tarball => Tarball,
has_checkouts => has_checkouts(State)
},
{ok, Package};
{error, _} = Err ->
Err
case create_package_tarball(Metadata, PackageFiles) of
{error, _} = Err ->
Err;
Tarball ->
Package = #{
name => PkgName,
repo_name => RepoName,
deps => Deps1,
version => Version,
metadata => Metadata,
files => PackageFiles,
tarball => Tarball,
has_checkouts => has_checkouts(State)
},
{ok, Package}
end;
Error ->
Error
end.

update_versions(ConfigDeps, LockDeps) ->
Expand Down Expand Up @@ -178,8 +181,8 @@ create_docs(State, Repo, App, Args) ->
{ok, #{
tarball => Tarball, name => binarify(PkgName), vsn => binarify(Vsn)
}};
{error, _} = Err ->
Err;
{error, Reason} ->
{error, hex_tarball:format_error(Reason)};
Err ->
Err
end;
Expand Down Expand Up @@ -268,8 +271,8 @@ create_package_tarball(Metadata, Files) ->
case hex_tarball:create(Metadata, Files) of
{ok, #{tarball := Tarball, inner_checksum := _Checksum}} ->
Tarball;
{error, _} = Err ->
Err;
{error, Reason} ->
{error, hex_tarball:format_error(Reason)};
Error ->
Error
end.
Expand Down
11 changes: 11 additions & 0 deletions src/rebar3_hex_publish.erl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ format_error({app_not_found, AppName}) ->
io_lib:format("App ~s specified with --app switch not found in project", [AppName]);
format_error(bad_command) ->
"bad command";
format_error({create_package, {error, Err}}) when is_list(Err) ->
io_lib:format("Error creating package : ~ts", [Err]);
format_error({publish_package, app_switch_required}) ->
"--app required when publishing with the package argument in a umbrella";
format_error({publish_docs, app_switch_required}) ->
Expand All @@ -119,6 +121,13 @@ format_error({publish, {error, #{<<"message">> := Message}}}) ->
io_lib:format("Failed to publish package: ~ts", [Message]);
format_error({create_docs, {error, {doc_provider_not_found, PrvName}}}) ->
io_lib:format("The ~ts documentation provider could not be found", [PrvName]);
format_error({create_docs, {error, {doc_provider_failed, PrvName}}}) ->
io_lib:format("The ~ts documentation provider failed", [PrvName]);
format_error({create_docs, {error, missing_doc_index}}) ->
"No index.html file was found in expected docs directory.\n"
"If you provided --doc-dir option ensure that your docs were generated before running this task.\n"
"Otherwise, check that your preferred doc provider is properly generating docs outside the scope of this task.\n"
"Once resolved, run rebar3 hex publish docs <options> to publish only the docs for this version of your package.\n";
format_error({non_hex_deps, Excluded}) ->
Err = "Can not publish package because the following deps are not available"
++ " in hex: ~s",
Expand Down Expand Up @@ -369,6 +378,8 @@ create_docs(State, Repo, App, Args) ->
case rebar3_hex_build:create_docs(State, Repo, App, Args) of
{ok, Docs} ->
Docs;
{error, no_doc_config} ->
rebar_api:warn("No documentation provider was configured, docs will not be generated.", []);
Err ->
?RAISE({create_docs, Err})
end.
Expand Down

0 comments on commit a3632b9

Please sign in to comment.