8

I have two files main.raku and TestMod.rakumod in a directory C:\Users\suman.

TestMod.rakumod

unit module TestMod;
sub add($a, $b) is export {
    $a + $b
}

main.raku

use lib $*PROGRAM.dirname;
use TestMod;

say add(8,9)

I want to call some functions in the TestMod module from main script file. When I run the script, I get this error

===SORRY!=== Error while compiling c:\Users\suman\main.raku
read from dirhandle failed: 123
at c:\Users\suman\main.raku:2

This is my OS specific information:

Host Name:                 SUMANKHANAL
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.19043 N/A Build 19043
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          N/A
Registered Organization:   N/A
Product ID:                00331-20350-00000-AA867
Original Install Date:     10/19/2020, 3:36:49 PM
System Boot Time:          12/7/2021, 1:00:40 PM
System Manufacturer:       Dell Inc.
System Model:              Inspiron 5379
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 142 Stepping 10 GenuineIntel ~1792 Mhz
BIOS Version:              Dell Inc. 1.17.0, 8/18/2021
Windows Directory:         C:\WINDOWS
System Directory:          C:\WINDOWS\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (UTC+05:45) Kathmandu

Rakudo specific information (installed from rakudo.org):

Welcome to Rakudo™ v2021.10.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2021.10.

This scenario however works in Linux. See MWE here.

Is it Windows specific issue/bug or am I missing something?

Suman Khanal
  • 3,079
  • 1
  • 17
  • 29
  • 1
    Looks like a bug; apparently the handle returned does not follow a platform-independent convention. Have you tried to simply do `use lib <.>`? – jjmerelo Dec 07 '21 at 16:21
  • 1
    Perhaps `use lib $*PROGRAM.parent.absolute` ? – Elizabeth Mattijsen Dec 07 '21 at 16:26
  • I am afraid `use lib <.>` and `use lib $*PROGRAM.parent.absolute` both are not working in Windows. – Suman Khanal Dec 07 '21 at 16:56
  • 2
    Pointing a `use lib ...` at a big directory (such as your home directory as shown above) that may contain files your current user doesn't have access to isn't a good idea. – ugexe Dec 07 '21 at 18:33
  • 1
    Note we know rakudo generally loads modules fine with `use lib ...` since the tests of rakudo itself exercises such a code path. – ugexe Dec 07 '21 at 18:35
  • Hmmm, I get your two files to work, but when using the line `use lib $*PROGRAM.dirname;` I have to move them into something other than my main `Users` directory (on a Mac). Presumably I'm hanging because it's a big folder. I have better luck when I toss the files into their own `Suman_Folder`. Maybe the following (older, closed) Github issue is still relevant? "Error when loading module via -Ilib when lib/ contains symlinks (linux) #2960" https://github.com/rakudo/rakudo/issues/2960 – jubilatious1 Dec 14 '21 at 20:10

6 Answers6

6

TL;DR A nanswer that might help you towards an answer.

What do I know?

Not a lot. I haven't used Windows for dev in years. I've not seen this error before.

I just decided to see what I could find. I found a couple things, read between the lines, and... ended up with this nanswer.

read from dirhandle failed: 123

A google for "read from dirhandle failed: 123" listed two matches for me.

One was this SO. I'm not sure that's especially helpful, though we are trying!


The other match was:

githubmemoryhttps://githubmemory.com › ... · Translate this page
ohmycloud Profile - githubmemory

When I clicked it it did not include the error message I'd searched for.

But clicking the showed an About this result popup, and a cache button at the bottom of that popup linked to an earlier version of the page that the search had matched. (This is a general trick to know about when a search result appears not to contain something you'd just searched for.)

And that page (which I can see with this URL; YMMV) contained this match:

when execute above script as Administrator, failed with read from dirhandle failed: 123

But it wasn't conclusive. Hmmm.


githubmemory.com is just a copy of GH. So I figured out it's a copy of this issue. And that is more conclusive. That is to say, the issue opener, ohmycloud, closes it with the conclusion:

It's actually a access deny error

Hmmm. Really?

Please consider investigating that angle, and perhaps editing your question to summarize your conclusions. But please read on first, because there are reasons to doubt it's an access error, as follows.

Windows System Error 123

My next research angle was determining exactly what the error code means.

I figured out the read from dirhandle failed: was from MoarVM, and that showed the error code was from GetLastError(), and I figured out that is from the Windows API, and I arrived at this reference entry:

The filename, directory name, or volume label syntax is incorrect.

Hmm. Why did ohmycloud talk about an access error?

We should probably try to investigate whether it is "just" invalid syntax rather than something else like an access error.

Please try the following, and consider whether it's worth pasting some of your results, at least one of them, into your question:

say $*PROGRAM.dirname.raku;
chdir $*PROGRAM.dirname;
say $*PROGRAM.dirname.IO.raku;

A last chance long odds dark horse?

While googling a tad more widely (dropping the 123) I found another match that might be of interest.

(It actually does have the same error, so I don't understand why it wasn't listed by the first google I tried, but whatever.)

It's this 2016 comment by nick cygx on the #moarvm channel

eventually dies with a SORRY: read from dirhandle failed: 123

This is also on Windows. One can tell that due to the error message but it's also confirmed later that same day on the IRC channel:

that "read from dirhandle failed" thing happens inside a windows ifdefed block

Afaict, cygx is saying they got the error message for the test case in the bug Class fails to smartmatch against role defined in module.

jnthn's response to this failure was:

That...makes no sense o.O

(Which is a pretty good summary of your SO.)


jnthn's said one other thing about cygx's error:

I've put off fixing up hyper/race for months already. :)


So, perhaps, or more lyrically as a last chance long shot dark horse, maybe there's some hyper/race related problem within MoarVM's guts that manifests on Windows in relation to module loading?


It would be helpful if you could try the "Minimal testcase​" in the bug report. Do you get the 123 error?

If you do, then perhaps (even longer shot) it's worth someone trying to get in touch with cygx? Unfortunately the nick cygx last appeared on #moarvm in 2019. So I did a google for cygx raku. I found an 8 month old comment about Raku under that nick from 8 months ago. (Which I see I replied to ineptly. Sorry, cygx.)

@ugexe's comments

Their first comment is:

Pointing a use lib ... at [a directory containing] files your current user doesn't have access to isn't a good idea.

That suggests you would best make sure the directory you're pointing lib at is not a directory such as C:\Users\suman because, in the general case, that may include files your Rakudo compiler can't access. (Whether this is the case depends on your system setup and what files you have, but the simple solution is to make sure you only point lib at a directory dedicated to Raku code.)


Their last comment (below this answer) is a link to a gist with lines like this:

C:\Users\ugexe>raku --ll-exception -e "use lib '.'; use Test;"
read from dirhandle failed: 123
   at SETTING::src/core.c/Rakudo/Internals.pm6:1345  (C:\Users\ugexe\.rakudobrew\moar-2021.10\install\share\perl6\runtime/CORE.c.setting.moarvm:next)
 from SETTING::src/core.c/Rakudo/Internals.pm6:1374
.
.
.

I don't know how to interpret this gist, but I can see that their gist:

  • Shows them producing the same Windows System Error (123) with nothing but a use Test;;

  • Shows paths that, if passed to Windows, would presumably be syntactically invalid (C:\Users\ugexe\.rakudobrew\moar-2021.10\install\share\perl6\runtime/CORE.c.setting.moarvm:next). My guess is that they're not passed to Windows, but instead just constructed that way as part of displaying the error. But that is just a guess.

raiph
  • 31,607
  • 3
  • 62
  • 111
  • 2
    https://gist.github.com/ugexe/b1b72ed0fd57069ff5533dfc03a95532 – ugexe Dec 08 '21 at 02:12
  • 2
    https://gist.github.com/ugexe/90b63ea9e33f406f977c970d138bbc9d -- looks like maybe something related to the e.g. "My Videos" type document folders/links – ugexe Dec 14 '21 at 02:38
  • 1
    @raiph Your efforts to help is commendable. Moving `.rakumod` files to a `separate folder` within `C:\Users\suman` and importing with `use lib ""` from `main` script works. Also moving both files to `Desktop` also works. But I find it weird! Because `python` files similar to my question works fine without any issues in the folder `C:\Users\suman`. So I was expecting the same with `raku`. Unfortunately its not the same. – Suman Khanal Dec 16 '21 at 12:33
6
  • Moving .rakumod files to a separate folder within C:\Users\suman and importing with use lib "<separate folder>" from main script works.

In my case, when I move TestMod.rakumod to C:\Users\suman\rakulib and modify main script as follows:

use lib "rakulib";
use TestMod;

say add(8,9)

it works.

  • Also moving both files to Desktop also works.

But I find it weird! Because two python files similar to my question works fine without any issues even when both of them are in the folder C:\Users\suman.

file1.py

def add(a,b):
    return a + b

file2.py

from file1 import add

print(add(8,9))

So I was expecting the same with raku. Unfortunately it's not the case.

read from dirhandle failed seems like access deny error as pointed by many rakoons. I am interested to know how can we fix this from within raku.

Acknowledgement: The ideas suggested by @jubilatious1 and @chenyf works. So I combine them here.

Suman Khanal
  • 3,079
  • 1
  • 17
  • 29
  • Hi @SumanKhanal. :) (Is referring to you as Suman friendly, or would Khanal be friendlier, or would you prefer I stick with @SumanKhanal?) I literally just had the thought you "ought" accept your answer rather than mine. And as I was pondering whether to say something, or whether the system wasn't allowing you to accept your answer for a couple days, and as I was thinking to myself I could link to yours from the start of mine, and acknowledge the other helpful answers, but maybe I "ought" just be patient, the screen flashed. I scrolled up and... we are as one. BIG smile on my face. – raiph Dec 16 '21 at 13:02
  • @raiph SumanKhanal would be fine. :) – Suman Khanal Dec 16 '21 at 13:07
  • 1
    "I am interested to know how can we fix this ..." ❶ I agree we ought address this problem in Rakunia. I think a fix that makes the problem go away would be by far the best thing. But, failing that, a better error message. Or, at absolute minimum, better doc would improve things. ❷ `123` is classified by Windows API doc as invalid "syntax" for a path. I've been researching that over the last 24 hours. As I write this I've good reason to think MS's use of the word "syntax" is profoundly misleading. I will contribute my findings in a gist (or an issue if you open one) when I've got them in order. – raiph Dec 16 '21 at 13:26
4

It's ok on my desktop:

raku .\main.raku
17

enter image description here

OS Version: Windows 11 professional(21H2)

Raku Version: 2021.10

chenyf
  • 5,048
  • 1
  • 12
  • 35
3

Despite what I've said in my comment, it's entirely likely that dirname is behaving according to spec; only it's not in that spec to return a platform-specific name. So it would be interesting to investigate what $*PROGRAM.dirname returns. If it's a Linux-formatted path, that might be part of the problem. This is raiph's answer points at: wrong syntax. If that's the case, we need to get to the "right" syntax. That is why in the first version of this answer I pointed at using IO::Path::Win32 to create that syntax. Other option might be to simply put the directory name by hand. Finally, a bug can't be excluded.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86
  • Both approaches are not working. Even setting `export RAKUDOLIB=.` in `Git Bash` in Windows is not working. Also tried executing the script from command line `rakudo -I . main.raku` or `rakudo -M TestMod -I . main.raku`. Not working though. – Suman Khanal Dec 07 '21 at 17:08
  • Same error? Have you tried putting the . adjacent to the I instead of separated? Also, -I *before* the module you want loaded? What is the error in the cases you mention above? – jjmerelo Dec 07 '21 at 19:00
  • Tried your suggestions. Errors are exactly same. – Suman Khanal Dec 08 '21 at 06:11
  • 2
    @SumanKhanal have you tried moving the module code into its own folder such as (for example) `rakulib`, one level down from your `main` (calling) script? Then calling the module from the `main` script with: `use lib "rakulib";`? ...I've gotten your code to work that way (on my Mac). – jubilatious1 Dec 14 '21 at 20:26
  • 2
    @jubilatious1 That indeed works. But I find it weird. Because `python` files similar to my question works fine without any issues in the folder `C:\Users\suman`. So I was expecting same with `raku`. Unfortunately its not the same. – Suman Khanal Dec 16 '21 at 12:30
  • @SumanKhanal I believe the traditional reply--if you consider my comment/contribution to have significantly solved your problem--is to ask me to write up my comment as an Answer for you to "accept"? Or accept chenyf 's "Desktop" answer, whichever you consider to be your long-term solution? Kindest Regards. – jubilatious1 Dec 17 '21 at 13:03
  • 1
    @jubilatious1 To make aware the future readers, I thought it would be useful to combine both suggestions that worked for me in a single answer. I have added acknowledgement in the edited answer. Best regards. – Suman Khanal Dec 17 '21 at 14:33
2

It may be a problem with read permission: read from dirhandle failed

chenyf
  • 5,048
  • 1
  • 12
  • 35
  • 1
    The `read from dirhandle failed: 123` section of my answer includes a link to the same issue you've linked. The next section links the Microsoft doc for error `123`. It says it's a *syntax* problem. That doesn't seem to square with it being a read permission (or access deny) problem. But I think you *filed* that issue, right? If so, then it seems you concluded the *root* cause of *your* `123` error *was* a read permission / access deny probIem. Maybe you could add another comment, here or in your linked issue, that discusses *why* you've drawn the conclusion it was or might be read permission? – raiph Dec 12 '21 at 12:51
  • 1
    my program exit when reach file `C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache\Content.IE5`, but this file doesn't exist, when use `dir C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\INetCache\Content.IE5` to list it, just not found. – chenyf Dec 13 '21 at 05:01
2

Move the module code into its own folder such as (for example) rakulib, one level down from your main (calling) script. Then call the module from the main script with:

Main Script: "Suman_main.p6":

use lib "rakulib";
use SumanTestMod;


say add(8,9);

Module Code: "SumanTestMod.pm6":

unit module SumanTestMod;
sub add ( $a, $b) is export {
    $a + $b
}

[ Answer adapted from code found in Arne Sommer's "Beginning Raku" book, see: https://arnesom.github.io/ ]

jubilatious1
  • 1,999
  • 10
  • 18