SCons: Fix potential Windows ANSI exception #92087
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #92065
Rectified the issue by looking up the explicit values these functions expect1, which should prevent futher type errors from occuring. As far as making sure that a build progresses regardless, this adds an exception wrapper to that bit of code that caused the issue. If an exception does occur, it assumes that the Windows ANSI setup failed & explicitly disables color output. Also moved the check down slightly in the main
SConstruct
file so that it can output an error message viamethods.print_error
instead of a generic print.A future solution could be to overhaul the color system to something closer to what colorama achieves, which has a dedicated catch/conversion for Windows specifically. I'm not wholly knowledgeable on that approach, so I didn't attempt to implement it here.
Footnotes
https://learn.microsoft.com/en-us/windows/console/getstdhandle
https://learn.microsoft.com/en-us/windows/console/getconsolemode
https://learn.microsoft.com/en-us/windows/console/setconsolemode ↩