Skip to content

Commit aaa321f

Browse files
committed
fix: check file existence during wizard instead of only after
Move the os.Stat existence check into validateYAMLExtension so users get immediate feedback at stepSaveFile time, avoiding lost work if the target file already exists.
1 parent 2dd5d56 commit aaa321f

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

internal/policywizard/forms.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package policywizard
22

33
import (
44
"fmt"
5+
"os"
56
"path/filepath"
67
"regexp"
78
"slices"
@@ -264,6 +265,9 @@ func validateYAMLExtension(s string) error {
264265
if ext != ".yaml" && ext != ".yml" {
265266
return fmt.Errorf("file must have a .yaml or .yml extension")
266267
}
268+
if _, err := os.Stat(s); err == nil {
269+
return fmt.Errorf("file %q already exists; choose a different name", s)
270+
}
267271
return nil
268272
}
269273

0 commit comments

Comments
 (0)