From: "YO4 (Yoshinao Muramatsu) via ruby-core" Date: 2025-01-23T16:23:00+00:00 Subject: [ruby-core:120767] [Ruby master Bug#21083] current SystemCallError.new(-1) behavior on windows is not in accordance with the intent of the source code. Issue #21083 has been updated by YO4 (Yoshinao Muramatsu). I made a patch. Includes spec changes. The message of SystemCallError out of the errno range is "Unknown Error", same as ucrt's. [github #12622](https://github.com/ruby/ruby/pull/12622) ---------------------------------------- Bug #21083: current SystemCallError.new(-1) behavior on windows is not in accordance with the intent of the source code. https://bugs.ruby-lang.org/issues/21083#change-111631 * Author: YO4 (Yoshinao Muramatsu) * Status: Open * Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- spec/ruby/core/exception/system_call_error_spec.rb says ``` platform_is :windows do SystemCallError.new(-1).message.should == "The operation completed successfully." end ``` but source code says ```if (e < 0) e = GetLastError();``` at win32/win32.c(2838,9) [1] So it appears that the intent is to retrieve previous errors. This is not what the spec intended. It seems that at some point the behavior was broken because the WIN32API TlsGetValue() sets LastError even if it succeeds. SystemCallError.new(-1).errno returns -1 instead of GetLastError() returns, so the current behavior is not very useful. In my opinion, it is preferable to return "Unknown Error #{e}" as on other platforms. This change needs to revert ruby/spec@328ac37 [2] [1] https://github.com/ruby/ruby/blob/2b1db0faecf03d3fa1b7a1b102cc4c51aa962d5f/win32/win32.c#L2838 [2] https://github.com/ruby/spec/commit/328ac37 BACKGROUND I state the situation because I may be wrong in my guess. I was trying to make changes to allow Language TLS to be used on Windows, but found this spec fails. ``` 1) SystemCallError.new sets an 'unknown error' message when an unknown error number FAILED Expected "The system cannot find message text for message number 0x%1 in the message file for %2." == "The operation completed successfully." to be truthy but was false D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:104:in 'block (3 levels) in ' D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:103:in 'block (2 levels) in ' D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:22:in '' 2) SystemCallError.new adds a custom error message to an 'unknown error' message when an unknown error number and a custom message specified FAILED Expected "The system cannot find the path specified. - custom message" == "The operation completed successfully. - custom message" to be truthy but was false D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:114:in 'block (3 levels) in ' D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:113:in 'block (2 levels) in ' D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:22:in '' ``` message 1) because the previous execution of SystemCallError.new(2**24) failed to retrieve the message. MinGW(UCRT64) and VS2022 got same but VS2015 and VS2019 got different message "The resource loader cache doesn't have loaded MUI entry." message 2) I am not sure where this message was obtained from. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/