MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / validateFileWithTimeout

Function validateFileWithTimeout

cmd/gosqlx/internal/actioncmd/action.go:374–395  ·  view source on GitHub ↗
(filePath string, timeout time.Duration)

Source from the content-addressed store, hash-verified

372}
373
374func validateFileWithTimeout(filePath string, timeout time.Duration) error {
375 type result struct {
376 err error
377 }
378 ch := make(chan result, 1)
379
380 go func() {
381 data, err := os.ReadFile(filepath.Clean(filePath))
382 if err != nil {
383 ch <- result{err: fmt.Errorf("cannot read file: %w", err)}
384 return
385 }
386 ch <- result{err: parser.ValidateBytes(data)}
387 }()
388
389 select {
390 case r := <-ch:
391 return r.err
392 case <-time.After(timeout):
393 return fmt.Errorf("timeout after %v", timeout)
394 }
395}
396
397func writeStepSummary(path string, total, valid, valErrors, lintErrors, lintWarnings int) {
398 f, err := os.OpenFile(filepath.Clean(path), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600)

Callers 1

runActionFunction · 0.85

Calls 2

ValidateBytesFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected