sys/win: display a useful error message when SetConsoleMode fails#639
sys/win: display a useful error message when SetConsoleMode fails#639
Conversation
src/sys/windows.rs
Outdated
| | Console::ENABLE_VIRTUAL_TERMINAL_INPUT, | ||
| ))?; | ||
| )) { | ||
| Err(apperr::Error::Sys(e)) if e == 0x80070000 | ERROR_INVALID_PARAMETER => { |
There was a problem hiding this comment.
You could call gle_to_apperr(ERROR_INVALID_PARAMETER) instead here. It's a const function so it should get optimized away.
There was a problem hiding this comment.
at first I tried to match Sys(0x80070057) directly and it didn't work. i resorted to this somewhat tortured syntax because it was the only thing that did work. i can test it again.
src/sys/windows.rs
Outdated
| ..mem::zeroed() | ||
| }; | ||
| let condition = | ||
| VerSetConditionMask(0, VER_BUILDNUMBER, 3 /* VER_GREATER_EQUAL */); |
There was a problem hiding this comment.
You can import VER_GREATER_EQUAL from windows_sys::Win32::System::SystemInformation.
There was a problem hiding this comment.
(I didn't go out of my way to do it the more difficult, harder to document and more annoying to review way on purpose 😁)
There was a problem hiding this comment.
Sorry, it's in windows_sys::Win32::System::SystemServices for some reason. 🥴
https://docs.rs/windows-sys/0.61.0/windows_sys/Win32/System/SystemServices/constant.VER_GREATER_EQUAL.html
src/sys/windows.rs
Outdated
| Err(apperr::Error::Sys( | ||
| match VerifyVersionInfoW(&mut osv, VER_BUILDNUMBER, condition) { | ||
| Foundation::TRUE => ERROR_UNSUPPORTED_LEGACY_CONSOLE, | ||
| Foundation::FALSE => ERROR_UNSUPPORTED_WINDOWS_VERSION, |
There was a problem hiding this comment.
I'm still not 100% sure if the distinction between the two errors is meaningful nowadays, given how rarely older versions of Windows are still used.
There was a problem hiding this comment.
yeah, that's fair. It is technically true that "On windows 8.1, the legacy console is in use"
…crosoft#639) edit will now display specific error messages when the console fails to support `ENABLE_VIRTUAL_TERMINAL_INPUT`. The user will be gently reprimanded for not using the modern console host. It is technically possible to run edit on OpenConsole (or another third- party console host!)--even on Windows 8.1--where it will work properly.
…crosoft#639) edit will now display specific error messages when the console fails to support `ENABLE_VIRTUAL_TERMINAL_INPUT`. The user will be gently reprimanded for not using the modern console host. It is technically possible to run edit on OpenConsole (or another third- party console host!)--even on Windows 8.1--where it will work properly.


edit will now display specific error messages when the console fails to support
ENABLE_VIRTUAL_TERMINAL_INPUT. On Windows 8.1, the user will be gently reprimanded to update to Windows 10. On Windows 10, they will be coerced into using the modern console host.We only check the version after this fails because it is technically possible to run edit on OpenConsole (or another third-party console host!)--even on Windows 8.1--where it will work properly.