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

Windows error tag (-1) is outside of enumeration's range (0,4) #113

Open
supermario opened this issue Aug 6, 2024 · 2 comments
Open

Windows error tag (-1) is outside of enumeration's range (0,4) #113

supermario opened this issue Aug 6, 2024 · 2 comments

Comments

@supermario
Copy link

supermario commented Aug 6, 2024

I've had users report the following crashes happen occasionally in a scenario where we're using fsnotify to watch the disk for file changes:

lamdera.exe: toEnum{Action}: tag (-1) is outside of enumeration's range (0,4)
CallStack (from HasCallStack):
  error, called at win-src\System\Win32\FileNotify.hsc:46:34 in fsnotify-0.4.1.0-7SQlBibA4qu3CuGnOcBOvF:System.Win32.FileNotify

I'm guessing this is related to:

readDirectoryChangesW h buffer (toEnum maxBuf) wst mask bret
readChanges buffer
data Action = FileAdded | FileRemoved | FileModified | FileRenamedOld | FileRenamedNew
deriving (Show, Read, Eq, Ord, Enum)

As it's the only place toEnum is used in this package. But I'm unsure what the -1 value would indicate in Windows or how to debug further.

Would be happy to add debugging/instrumentation code if someone could provide some guidance, but otherwise we don't currently have a sure-fire way of replicating the issue reliably.

@thomasjm
Copy link
Contributor

thomasjm commented Aug 6, 2024

I see another toEnum usage a few lines down:

faToAction fa = toEnum $ fromEnum fa - 1

It looks like Windows gives us action enums with a value between 1 and 5 inclusive, see here.

It appears that this line is converting from the 1-based Windows indexing to the 0-based Haskell Enum indexing. But somehow Windows is sending 0 for the action, resulting in a call to (toEnum (-1))?

@thomasjm
Copy link
Contributor

thomasjm commented Aug 6, 2024

If you have a Windows dev machine handy, maybe you can load FileNotify.hsc in GHCi and check that the enums (FileAction and Action) have the expected values?

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

No branches or pull requests

2 participants