Skip to content

Commit 3882d26

Browse files
added dir cleanup and error checking for lookupTargetDir
1 parent 332f412 commit 3882d26

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

gatlingparser/gatlingparser.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ var (
8888
func lookupTargetDir(ctx context.Context, dir string) error {
8989
const loopTimeout = 5 * time.Second
9090

91-
l.Infoln("Looking for target directory...")
91+
cleanDir := filepath.Clean(filepath.FromSlash(dir))
92+
93+
l.Infoln("Looking for target directory... %s", cleanDir)
9294
for {
9395
// This block checks if stop signal is received from user
9496
// and stops further lookup
@@ -98,20 +100,25 @@ func lookupTargetDir(ctx context.Context, dir string) error {
98100
default:
99101
}
100102

101-
fInfo, err := os.Stat(dir)
102-
if err != nil && !os.IsNotExist(err) {
103-
return fmt.Errorf("Target path %s exists but there is an error: %w", dir, err)
104-
}
105-
if os.IsNotExist(err) {
106-
time.Sleep(loopTimeout)
107-
continue
103+
fInfo, err := os.Stat(cleanDir)
104+
if err != nil {
105+
if os.IsNotExist(err) {
106+
time.Sleep(loopTimeout)
107+
continue
108+
}
109+
// Log the specific error type to help diagnose issues
110+
return fmt.Errorf("error accessing path %s (error type: %T): %w", dir, err, err)
108111
}
109112

110113
if !fInfo.IsDir() {
111-
return fmt.Errorf("Was expecting directory at %s, but found a file", dir)
114+
return fmt.Errorf("was expecting directory at %s, but found a file", dir)
115+
}
116+
117+
abs, err := filepath.Abs(cleanDir)
118+
if err != nil {
119+
return fmt.Errorf("failed to get absolute path for %s: %w", dir, err)
112120
}
113121

114-
abs, _ := filepath.Abs(dir)
115122
l.Infof("Target directory found at %s", abs)
116123
break
117124
}

0 commit comments

Comments
 (0)