Skip to content
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

Resolve string vs list crashing rebar3 #1807

Merged

Conversation

starbelly
Copy link
Contributor

@starbelly starbelly commented Jun 7, 2018

This PR resolves #1645.

To be clear we can not abort if "" is given, because it may be [] which is valid. Neither result in a fatal though, so it's a non-issue.

TODO:

  • Abort on binary only such as "abc"
  • Tests

@@ -796,3 +797,10 @@ dir_recursive(Opts, Dir, CompileOpts) when is_list(CompileOpts) ->
undefined -> rebar_dir:recursive(Opts, Dir);
Recursive -> Recursive
end.

valid_erl_first_conf(FileList) when not is_list(hd(FileList)) ->
throw("An invalid file list was provided as part of your erl_files_first directive");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check out the ?ABORT("...", [...]) macro for such usages

@starbelly
Copy link
Contributor Author

@ferd I wonder if there are more cases where this applies? If there are, then perhaps this can be made a little more generic name wise... it might also make better since to validate in rebar_opts if that is the case.

@ferd
Copy link
Collaborator

ferd commented Jun 7, 2018

There are possibly more cases. I guess the most generic we could make it for now is a call like -spec rebar_utils:is_list_of_strings(term()) -> boolean() and leave messaging and error handling to the call-site.

@starbelly starbelly force-pushed the 1645-erl_files_first_string_crashes_rebar3 branch from d1ff177 to 1b0d28a Compare June 8, 2018 16:25

valid_erl_first_conf(FileList) ->
case FileList of
[] -> ?WARN("An empty file list (~p) was provided as part of your erl_files_first directive", [FileList]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know that an empty file is warning-worthy since it should be equivalent to not submitting anything. Does it break stuff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this does not break stuff, will remove that. I locked on to the problem of trying to handle "" :)

@starbelly starbelly force-pushed the 1645-erl_files_first_string_crashes_rebar3 branch 2 times, most recently from 6a7fdff to fa71427 Compare June 8, 2018 18:40
@starbelly starbelly changed the title WIP: Resolve string vs list crashing rebar3 Resolve string vs list crashing rebar3 Jun 8, 2018
@starbelly
Copy link
Contributor Author

@ferd This should be good to go.

@starbelly starbelly force-pushed the 1645-erl_files_first_string_crashes_rebar3 branch from fa71427 to d1fc937 Compare June 8, 2018 23:09
@ferd ferd merged commit ca36f30 into erlang:master Jun 8, 2018
@RumataEstor
Copy link

@starbelly
Copy link
Contributor Author

starbelly commented Jun 27, 2018

@RumataEstor What version of OTP version etc? It's compiling over here on OTP 20.3 and OTP 21.0.

Never mind I reproduced.

@starbelly
Copy link
Contributor Author

starbelly commented Jun 27, 2018

If supplying atoms in this list is valid, I have a quick fix, but I will wait to hear from @ferd or @tsloughter

@RumataEstor
Copy link

@starbelly I'm not sure if it's supposed to work, just noticed in case the breakage wasn't intentional. I'm fine already ;-)

@ferd
Copy link
Collaborator

ferd commented Jun 27, 2018

I don't think it should be valid, as even rebar 2.x appears to have no code in use to support it. However, most of the file handling functions seem to accept atoms, and so it worked kind of accidentally since we never did much to validate these entries.

We can possibly support atoms but with a warning. Something like "erl_first_files only expects lists of filenames as strings. The module name x is an atom and may not work perfectly" or something. I think it clarifies intent a bit better and it's not like users were stupid to think a module would be fine if they tried it an it worked.

@starbelly
Copy link
Contributor Author

Noting for history that a check for the existence of atoms in erl_first_files was added. We filter out atoms from the list and perform string validation on only strings, but we do give a warning about the use of module names (atoms) in this config directive.

See #1828 for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants