Incomplete message for compiler errors on Windows #12874
Labels
kind:bug
A bug in the code. Does not apply to documentation, specs, etc.
platform:windows
Windows support based on the MSVC toolchain / Win32 API
status:discussion
topic:compiler
On windows, some compiler errors are not properly reported to the user.
When such an error happens in a required file, the outermost error is a
Crystal::CodeError
with message "while requiring ...". And that's the only thing that's printed.Demonstration:
On Windows, the error message is
Error: while requiring "./bar"
. Nothing else. That's not a lot to go on.On Linux it's more elaborate about the actual error cause:
Error: error executing command: false, got exit status 1
.I might have seen a similar behaviour on Linux as well at some point. But not sure about that and what exactly caused this.
I think I have isolated the root cause for this in slightly different behaviour of
Process.run
. This is method is called for the expansion of the system command`filedoesnotexist`
, through the backtick method (.`
). It ends up callingProcess.run("filedoesnotexist", shell: true)
which on Linux (and probably all POSIX systems) returnsProcess::Status
with exit code127
, while on Windows it raisesFileNotFoundError
.This
FileNotFoundError
then bubbles up in the compiler but this error type is not expected in the compiler's error handling code (because it's not aCrystal::CodeError
). The non-success exit status on the macro system call instead results in aCodeError
on Linux, which is then treated differently in the compiler's error handling.The most obvious action to fix this behaviour is of course to adjust the behaviour of the backtick method (and probably
Process.run
) to behave the same on Windows as it does on POSIX systems. This is a separate issue discussed in #12873.However, there are two aspects related to the compiler's error handling:
Crystal::CodeError
to attach the origin location. This should happen even for unexpected exceptions which could appear as good as anywhere.The text was updated successfully, but these errors were encountered: