-
Notifications
You must be signed in to change notification settings - Fork 518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail loudly on error when executing a cmd in an app.src vsn #2543
Open
aronisstav
wants to merge
2
commits into
erlang:main
Choose a base branch
from
aronisstav:show-app-src-vsn-cmd-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -654,10 +654,18 @@ expand_sh_flag({env, _EnvArg} = Env) -> | |
-type err_handler() :: fun((string(), {integer(), string()}) -> no_return()). | ||
-spec log_msg_and_abort(string()) -> err_handler(). | ||
log_msg_and_abort(Message) -> | ||
fun(_Command, {_Rc, _Output}) -> | ||
?ABORT(Message, []) | ||
fun(Command, Arg) -> | ||
Msg = io_lib:format("~s~n", [Message]), | ||
log_msg_and_abort(Msg, Command, Arg) | ||
end. | ||
|
||
-spec log_msg_and_abort(string(), string(), {integer(), string()}) -> no_return(). | ||
log_msg_and_abort(Message, Command, {Rc, Output}) -> | ||
?ABORT("~s" | ||
"sh(~ts)~n" | ||
"failed with return code ~w and the following output:~n" | ||
"~ts", [Message, Command, Rc, Output]). | ||
|
||
-spec debug_log_msg_and_abort(string()) -> err_handler(). | ||
debug_log_msg_and_abort(Message) -> | ||
fun(Command, {Rc, Output}) -> | ||
|
@@ -668,10 +676,8 @@ debug_log_msg_and_abort(Message) -> | |
end. | ||
|
||
-spec log_and_abort(string(), {integer(), string()}) -> no_return(). | ||
log_and_abort(Command, {Rc, Output}) -> | ||
?ABORT("sh(~ts)~n" | ||
"failed with return code ~w and the following output:~n" | ||
"~ts", [Command, Rc, Output]). | ||
log_and_abort(Command, Arg) -> | ||
log_msg_and_abort("", Command, Arg). | ||
|
||
-spec debug_and_abort(string(), {integer(), string()}) -> no_return(). | ||
debug_and_abort(Command, {Rc, Output}) -> | ||
|
@@ -792,7 +798,8 @@ vcs_vsn_cmd(_, _, _) -> | |
unknown. | ||
|
||
cmd_vsn_invoke(Cmd, Dir) -> | ||
{ok, VsnString} = rebar_utils:sh(Cmd, [{cd, Dir}, {use_stdout, false}]), | ||
ErrorOpt = {abort_on_error, "vsn cmd in .app.src failed"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to add the actual filename or path here as well. Otherwise, if you have many apps its up to the user to find the one with the bad vsn command |
||
{ok, VsnString} = rebar_utils:sh(Cmd, [ErrorOpt, {cd, Dir}, {use_stdout, false}]), | ||
rebar_string:trim(VsnString, trailing, "\n"). | ||
|
||
%% @doc ident to the level specified | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the error message takes place this deep, then it would make sense not to make assumptions on what the caller was doing ("was it really called in a .app.src file?") and simply report the error at its own level (something like "Command x failed") to prevent misguiding error messages when the callsites are expanded.
If we want to provide contextual errors with high-level concerns, then we would need to put in a conditional here and return
{ok, VsnString} | {error, Term}
and move the reporting to the parent.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify a little bit? I am guessing you mean that this code could be reached in different ways, but my understanding, without really checking, is that the only way to reach
cmd_vsn_invoke/2
is when really evaluating acmd
in avsn
property, in an.app.src
file, which is what my error message reports.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is more of future-proofing. I.e. the function
cmd_vsn_invoke
knows it is about a version, but has no idea it actually comes from a .app.src file.