File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -486,6 +486,9 @@ func UserConfigDir() (string, error) {
486
486
// On Unix, including macOS, it returns the $HOME environment variable.
487
487
// On Windows, it returns %USERPROFILE%.
488
488
// On Plan 9, it returns the $home environment variable.
489
+ //
490
+ // If the expected variable is not set in the environment, UserHomeDir
491
+ // returns either a platform-specific default value or a non-nil error.
489
492
func UserHomeDir () (string , error ) {
490
493
env , enverr := "HOME" , "$HOME"
491
494
switch runtime .GOOS {
Original file line number Diff line number Diff line change @@ -2639,10 +2639,20 @@ func TestUserHomeDir(t *testing.T) {
2639
2639
t .Fatal ("UserHomeDir returned an empty string but no error" )
2640
2640
}
2641
2641
if err != nil {
2642
- t .Skipf ("UserHomeDir failed: %v" , err )
2642
+ // UserHomeDir may return a non-nil error if the environment variable
2643
+ // for the home directory is empty or unset in the environment.
2644
+ t .Skipf ("skipping: %v" , err )
2643
2645
}
2646
+
2644
2647
fi , err := Stat (dir )
2645
2648
if err != nil {
2649
+ if os .IsNotExist (err ) {
2650
+ // The user's home directory has a well-defined location, but does not
2651
+ // exist. (Maybe nothing has written to it yet? That could happen, for
2652
+ // example, on minimal VM images used for CI testing.)
2653
+ t .Log (err )
2654
+ return
2655
+ }
2646
2656
t .Fatal (err )
2647
2657
}
2648
2658
if ! fi .IsDir () {
You can’t perform that action at this time.
0 commit comments