Skip to content

Commit dbd9a3f

Browse files
committed
fix: enhance robustness of file validation and error handling
- Improve error handling when checking template and template variables files - Use explicit existence and error checking for file paths instead of relying solely on file.IsFile return value Signed-off-by: appleboy <[email protected]>
1 parent 190be59 commit dbd9a3f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

cmd/hepler.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,25 @@ func check() error {
5555
}
5656

5757
// Verify template file existence
58-
templateFile := viper.GetString("git.template_file")
59-
if templateFile != "" && !file.IsFile(templateFile) {
60-
return fmt.Errorf("template file not found at: %s", templateFile)
58+
cfgTemplateFile := viper.GetString("git.template_file")
59+
if cfgTemplateFile != "" {
60+
exists, err := file.IsFile(cfgTemplateFile)
61+
if err != nil {
62+
return fmt.Errorf("failed to check template file: %v", err)
63+
}
64+
if !exists {
65+
return fmt.Errorf("template file not found at: %s", cfgTemplateFile)
66+
}
6167
}
6268

63-
if templateVarsFile != "" && !file.IsFile(templateVarsFile) {
64-
return fmt.Errorf("template variables file not found at: %s", templateVarsFile)
69+
if templateVarsFile != "" {
70+
exists, err := file.IsFile(templateVarsFile)
71+
if err != nil {
72+
return fmt.Errorf("failed to check template variables file: %v", err)
73+
}
74+
if !exists {
75+
return fmt.Errorf("template variables file not found at: %s", templateVarsFile)
76+
}
6577
}
6678

6779
// Load custom prompts from configured directory

0 commit comments

Comments
 (0)