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

Enhanced error messages for invalid library/executables names #3646

Merged
merged 7 commits into from
Aug 5, 2020

Conversation

voodoos
Copy link
Collaborator

@voodoos voodoos commented Jul 23, 2020

Actual behavior

When an executable has an invalid name, dune wrongly states that this module doesn't exist, while it not a valid module name:

File "dune", line 2, characters 7-16:
2 |  (name main-test)
           ^^^^^^^^^
Error: Module "Main-test" doesn't exist.

Moreover libraries have a better message when only the public_name is specified and it is not a valid module name:

Public library names don't have this restriction. You
  can either change this public name to be a valid library
  name or add a \"name\" field with a valid library name."

This is not the case for executables.

In this PR

  • The first two commits implement the same error granularity for executables than for libraries, as described hereinabove.
  • The last one adds an hint to suggest a valid name to the user.

New behavior (see tests for more)

  File "dune", line 2, characters 7-10:
  2 |  (name a.b))
             ^^^
  Error: "a.b" is an invalid module name.
  Module names must be non-empty and composed only of the following characters:
  'A'..'Z', 'a'..'z', '_', ''' or '0'..'9'.
  Hint: a_b would be a correct module name
  File "dune", line 2, characters 14-17:
  2 |  (public_name a.b))
                    ^^^
  Error: Invalid module name.
  Public executable names don't have this restriction. You can either change
  this public name to be a valid module name or add a "name" field with a valid
  module name.
  Hint: Module names must be non-empty and composed only of the following
  characters: 'A'..'Z', 'a'..'z', '_', ''' or '0'..'9'.
  Hint: a_b would be a correct module name

Note

These messages and validation do not take into account the fact that the ocamlc compiler does accept, with a warning, an invalid name for the main module:

$ ocamlc a-b.ml -o a-b
File "a-b.ml", line 1:
Warning 24: bad source file name: "A-b" is not a valid module name.

$ ./a-b 
hello world

@voodoos voodoos requested a review from emillon July 23, 2020 14:10
src/dune/lib_name.ml Outdated Show resolved Hide resolved
Option.iter names
~f:
(List.iter ~f:(fun name ->
ignore (Module_name.parse_string_exn name)));
Copy link
Member

Choose a reason for hiding this comment

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

Can we specify the type of the value we're ignoring? That's a convention we follow in dune because it's error prone to keep ignoring values if the type returned changes.

@voodoos voodoos force-pushed the invalid-public-name branch from 80866fe to d9aa0ad Compare August 5, 2020 12:37
voodoos and others added 7 commits August 5, 2020 14:39
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
Signed-off-by: Ulysse Gérard <thevoodoos@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants