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

File.info? on a directory path to file breaks on Windows #15073

Open
HertzDevil opened this issue Oct 10, 2024 · 2 comments
Open

File.info? on a directory path to file breaks on Windows #15073

HertzDevil opened this issue Oct 10, 2024 · 2 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:windows topic:stdlib:files

Comments

@HertzDevil
Copy link
Contributor

If README.md is a file in the current directory, then this raises an exception:

File.info?("README.md/")
Unhandled exception: Unable to get file info: 'README.md/': The directory name is invalid. (File::Error)
  from src\crystal\system\win32\file.cr:126 in 'check_not_found_error'
  from src\crystal\system\win32\file.cr:169 in 'info?'
  from src\file.cr:198 in 'info?'
  from src\file.cr:197 in 'info?'
  from usr\test.cr:132 in '__crystal_main'
  from src\crystal\main.cr:118 in 'main_user_code'
  from src\crystal\main.cr:104 in 'main'
  from src\crystal\main.cr:130 in 'main'
  from src\crystal\system\win32\wmain.cr:37 in 'wmain'
  from D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 in '__scrt_common_main_seh'
  from C:\WINDOWS\System32\KERNEL32.DLL +187367 in 'BaseThreadInitThunk'
  from C:\WINDOWS\SYSTEM32\ntdll.dll +547436 in 'RtlUserThreadStart'

It is raised here:

NOT_FOUND_ERRORS = {
WinError::ERROR_FILE_NOT_FOUND,
WinError::ERROR_PATH_NOT_FOUND,
WinError::ERROR_INVALID_NAME,
}
def self.check_not_found_error(message, path)
error = WinError.value
if NOT_FOUND_ERRORS.includes? error
nil
else
raise ::File::Error.from_os_error(message, error, file: path)
end
end

The error message suggests a WinError.value of ERROR_DIRECTORY, which does not count as an expected failure. I have definitely never seen this before, and I am sure our Windows CI would have caught it, but I also recently upgraded to Windows 24H2 (10.0.26100.1742). Could anyone else confirm this?

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:windows topic:stdlib:files labels Oct 10, 2024
@straight-shoota
Copy link
Member

On 23H2 build 22631.4317 File.info?("README.md/") returns nil. So it seems to be a new error message.

For reference, this is the error message for Get-Content README.md/:

Get-Content : Cannot find path 'C:\crystal\crystal\README.md\' because it does not exist.
At line:4 char:1
+ Get-Content README.md/
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\crystal\crystal\README.md\:String) [Get-Content], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetContentCommand

@HertzDevil
Copy link
Contributor Author

On Wine I found something probably related to this: https://gitlab.winehq.org/wine/wine/-/merge_requests/5737

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. platform:windows topic:stdlib:files
Projects
Status: Todo
Development

No branches or pull requests

2 participants