-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Handle empty string returned from Environment.GetFolderPath
#51854
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
base: release/10.0.2xx
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds defensive error handling for a rare edge case where Environment.GetFolderPath or Path.GetTempPath() returns an empty string, preventing potential issues downstream when attempting to construct temporary file paths for file-based app artifacts.
Key Changes
- Added a null/empty string check after obtaining the temporary directory path
- Throws an
InvalidOperationExceptionwith a descriptive message if the path is empty - Protects against potential
ArgumentExceptionor unexpected behavior when passing empty paths toPath.Join
| </data> | ||
| </root> | ||
| <data name="EmptyTempPath" xml:space="preserve"> | ||
| <value>Unable to determine a temporary directory path. Consider configuring the TEMP environment variable on Windows or local app data folder on Unix.</value> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path.GetTempPath on Windows never returns an empty string. If GetTempPathW or GetTempPath2W returns a zero length, it throws instead. So this advice on "configuring the TEMP environment variable on Windows" will not be seen on Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth having a unit test with different OSs so that we check this situation.
@RikkiGibson has noticed in the documentation of Environment.GetFolderPath that it might return an empty string. So this PR handles that case.