ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:120748] [Ruby master Bug#21083] current SystemCallError.new(-1) behavior on windows is not in accordance with the intent of the source code.
@ 2025-01-21 15:12 YO4 (Yoshinao Muramatsu) via ruby-core
  2025-01-22  5:27 ` [ruby-core:120759] " nobu (Nobuyoshi Nakada) via ruby-core
  2025-01-23 16:23 ` [ruby-core:120767] " YO4 (Yoshinao Muramatsu) via ruby-core
  0 siblings, 2 replies; 3+ messages in thread
From: YO4 (Yoshinao Muramatsu) via ruby-core @ 2025-01-21 15:12 UTC (permalink / raw)
  To: ruby-core; +Cc: YO4 (Yoshinao Muramatsu)

Issue #21083 has been reported by YO4 (Yoshinao Muramatsu).

----------------------------------------
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

* 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 <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:103:in 'block (2 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:22:in '<top (required)>'
  
  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 <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:113:in 'block (2 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:22:in '<top (required)>'
```
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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:120759] [Ruby master Bug#21083] current SystemCallError.new(-1) behavior on windows is not in accordance with the intent of the source code.
  2025-01-21 15:12 [ruby-core:120748] [Ruby master Bug#21083] current SystemCallError.new(-1) behavior on windows is not in accordance with the intent of the source code YO4 (Yoshinao Muramatsu) via ruby-core
@ 2025-01-22  5:27 ` nobu (Nobuyoshi Nakada) via ruby-core
  2025-01-23 16:23 ` [ruby-core:120767] " YO4 (Yoshinao Muramatsu) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: nobu (Nobuyoshi Nakada) via ruby-core @ 2025-01-22  5:27 UTC (permalink / raw)
  To: ruby-core; +Cc: nobu (Nobuyoshi Nakada)

Issue #21083 has been updated by nobu (Nobuyoshi Nakada).


I think we should drop that code (and the example in ruby/spec).
It is undocumented, non-portable, and unreliable.

----------------------------------------
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-111621

* 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 <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:103:in 'block (2 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:22:in '<top (required)>'
  
  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 <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:113:in 'block (2 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:22:in '<top (required)>'
```
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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [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.
  2025-01-21 15:12 [ruby-core:120748] [Ruby master Bug#21083] current SystemCallError.new(-1) behavior on windows is not in accordance with the intent of the source code YO4 (Yoshinao Muramatsu) via ruby-core
  2025-01-22  5:27 ` [ruby-core:120759] " nobu (Nobuyoshi Nakada) via ruby-core
@ 2025-01-23 16:23 ` YO4 (Yoshinao Muramatsu) via ruby-core
  1 sibling, 0 replies; 3+ messages in thread
From: YO4 (Yoshinao Muramatsu) via ruby-core @ 2025-01-23 16:23 UTC (permalink / raw)
  To: ruby-core; +Cc: YO4 (Yoshinao Muramatsu)

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 <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:103:in 'block (2 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:22:in '<top (required)>'
  
  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 <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:113:in 'block (2 levels) in <top (required)>'
  D:/a/ruby/ruby/src/spec/ruby/core/exception/system_call_error_spec.rb:22:in '<top (required)>'
```
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/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-01-23 16:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-21 15:12 [ruby-core:120748] [Ruby master Bug#21083] current SystemCallError.new(-1) behavior on windows is not in accordance with the intent of the source code YO4 (Yoshinao Muramatsu) via ruby-core
2025-01-22  5:27 ` [ruby-core:120759] " nobu (Nobuyoshi Nakada) via ruby-core
2025-01-23 16:23 ` [ruby-core:120767] " YO4 (Yoshinao Muramatsu) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).