www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4563] New: [module system] Error messages for missing package or missing name

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563

           Summary: [module system] Error messages for missing package or
                    missing name
           Product: D
           Version: D1 & D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



This is a wrong D2 program ("bitmanips" name doesn't exist):


import std.bitmanips: bitfields;
void main() {}


This is the error message given by dmd 2.047:

test.d(1): Error: module bitmanips is in file 'std\bitmanips.d' which cannot be
read


But a better error message can be:

test.d(1): Error: module 'bitmanips' not found in package 'std'.

---------------------

This is another wrong D2 program (the 'bitfield' name is missing inside
std.bimanip):


import std.bitmanip: bitfield;
void main() {}


This is the error message given by dmd 2.047:

test.d(1): Error: import bitfield not found
test.d(1): Error: alias test.bitfield recursive alias declaration


But the second error message can be omitted, it's useless and quite confusing.
So DMD can print just:

test.d(1): Error: import name 'bitfield' not found inside 'std.bitmanip'
module.


See also bug 3845

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



15:43:08 PDT ---
Agreed. There's an example in the docs (which I've filed a bug report for) that
imports std.hiddenfunc which doesn't exist anymore. "File cannot be read" is
pretty ambiguous in it's meaning.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 01 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563




Giving code to a D newbie such person didn't know what this error message
means:


foo.d(3): Error: module ascii is in file 'std/ascii.d' which cannot
be read
import path[0] = /usr/include/d
import path[1] = /usr/include/d/druntime/import


The problem was simple, he has used dmd 2.053 instead of the successive one, so
std.ascii was not present yet. This error message is not clear enough.

In a similar situation Python2 gives:
ImportError: No module named foo

I suggest an error message like:

foo.d(3): Error: module "std.ascii" not found (file 'std/ascii.d').

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 10 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563




Now the situation is worse (DMD 2.057head):


import std.math: foo;
void main() {}


Gives:

test.d(1): Error: import __anonymous foo not found
test.d(1): Error: alias test.foo recursive alias declaration

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 25 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563




The situation is not improved.

Wrong D2 code:


import core.stdc.stdlib: puts;
import std.stdio: reverse;
void main() {
    puts("hello");
    int[] a = [1, 2, 3];
    reverse(a);
}



After the recent changes in import semantics DMD 2.058head gives:

test.d(4): Error: undefined identifier puts
test.d(6): Error: undefined identifier reverse

But instead of such errors at the usage point I suggest to give import errors,
something like:

test.d(1): Error: name 'puts' not present in 'core.stdc.stdlib' module.
test.d(2): Error: name 'reverse' not present in 'std.stdio' module.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 04 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563


Leandro Lucarella <leandro.lucarella sociomantic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |leandro.lucarella sociomant
                   |                            |ic.com



2012-01-10 04:40:42 PST ---
*** Issue 7253 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 10 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563




18:53:44 PDT ---

 import std.bitmanips;
 void main() {}
 
 test.d(1): Error: module bitmanips is in file 'std\bitmanips.d' which cannot  
  be read
This is the only test-case left to fix in this Issue (the others seem to be fixed). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563






 This is the only test-case left to fix in this Issue (the others seem to be
 fixed).
This is the current situation: ---------------- import std.bitmanips: bitfields; void main() {} test.d(1): Error: module bitmanips is in file 'std\bitmanips.d' which cannot be read import path[0] = C:\dmd2\src\phobos\ import path[1] = C:\dmd2\src\druntime\import\ import path[2] = C:\leonardo\d_bugs\ import path[3] = C:\dmd2\windows\bin\..\..\src\phobos import path[4] = C:\dmd2\windows\bin\..\..\src\druntime\import ---------------- import std.bitmanip: bitfield; void main() {} test.d(1): Error: module std.bitmanip import 'bitfield' not found, did you mean 'template bitfields(T...)'? ---------------- import std.math: foo; void main() {} test.d(1): Error: module std.math import 'foo' not found, did you mean 'function fma'? ---------------- test.d(1): Error: name 'foo' not found in module std.math, did you mean function 'fma'? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563




06:48:43 PDT ---

 test.d(1): Error: module bitmanips is in file 'std\bitmanips.d' which cannot be
 read

Yes, it can be: test.d(1): Error: module bitmanips not found in package 'std' However what if the module is not in any package? Example: import bitmanips; void main() { } => test.d(1): Error: module bitmanips is in file 'bitmanips.d' which cannot be read What should we do here?
 test.d(1): Error: name 'foo' not found in module std.math, did you mean
 function 'fma'?
I would replace 'name' with 'symbol' here. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563






 However what if the module is not in any package? Example:
 
 import bitmanips; void main() { }
 
 => test.d(1): Error: module bitmanips is in file 'bitmanips.d' which cannot be
 read
 
 What should we do here?
Instead of writing: test.d(1): Error: module bitmanips cannot be found in package 'std'. It omits the last part of the message: test.d(1): Error: module bitmanips cannot be found. (Unrelated: do you know why D error messages don't have an ending full stop "." as in correct English?) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563




10:21:54 PDT ---

 test.d(1): Error: module bitmanips cannot be found.
Ok, I'll implement a pull and see what others think about it.
 (Unrelated: do you know why D error messages don't have an ending full stop "."
 as in correct English?)
GCC and DMC don't add a period either. I think it's purely accidental, some tools do, others don't (and sometimes it's mixed). I don't mind such issues though. Personally I worry much more about things like this: void main() { void function(int x, int y, float z) funcC; void function(int x, float y, int z) funcD; funcC = funcD; } Error: cannot implicitly convert expression (funcD) of type void function(int x, float y, int z) to void function(int x, int y, float z) It would make it much easier to debug such cases if the error spanned multiple lines and aligned the types, for example: Error: cannot implicitly convert expression (funcD) of type void function(int x, float y, int z) to void function(int x, int y, float z) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563






 Ok, I'll implement a pull and see what others think about it.
Thank you.
 It would make it much easier to debug such cases if the error spanned multiple
 lines and aligned the types, for example:
 
 Error: cannot implicitly convert expression (funcD) of type 
 void function(int x, float y, int z) to 
 void function(int x, int y, float z)
Better: Error: cannot implicitly convert expression (funcD) of type: void function(int x, float y, int z) to type: void function(int x, int y, float z) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 24 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563






 test.d(1): Error: module bitmanips cannot be found.
Ok, I'll implement a pull and see what others think about it.
Or: test.d(1): Error: module 'bitmanips' cannot be found. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 24 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4563




11:19:11 PDT ---


 
 Ok, I'll implement a pull and see what others think about it.
Thank you.
I think we can do even better: import foo.bar.doo; Now it's test.d(3): Error: module doo is in file 'foo\bar\doo.d' which cannot be read If 'foo' doesn't exist the error should probably be: test.d(3): Error: package 'foo' not found If 'bar' doesn't exist it should be: test.d(3): Error: package 'bar' not found in package 'foo' If 'doo' doesn't exist: test.d(3): Error: module 'doo' not found in package 'foo.bar' Also, we might consider doing informative spellchecker errors, e.g.: import std.stddio; test.d(3): Error: module 'stddio' not found in package 'std', did you mean 'stdio'? The above should probably try finding D modules that are similar to 'stddio', read their module declaration (because it might be different from the filename), and if the module declaration is similar to 'stddio' it should print that module name as a recommendation. import stdd.stdio; test.d(3): Error: package 'stdd' not found, did you mean 'std'? Here we might try finding non-empty folders with .d or .di files named similarly to 'stdd' and recommend such a folder. I don't know how hard this will be but I think it's worth pursuing. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 24 2012