Skip to content

Commit

Permalink
chore: use Read() for reading error buffer (#4366) (#4377)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-bytebase committed Jan 21, 2023
1 parent 2123b2a commit aed8820
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions plugin/db/pg/dump.go
Expand Up @@ -146,34 +146,17 @@ func (driver *Driver) dumpOneDatabaseWithPgDump(ctx context.Context, database st
}
}

var errBuilder strings.Builder
for {
line, readErr := errReader.ReadString('\n')
if readErr != nil && readErr != io.EOF {
return readErr
}

if err := func() error {
// Log the error, but return the first 1024 characters in the error to users.
log.Warn(line)
if errBuilder.Len() < 1024 {
if _, err := errBuilder.WriteString(line); err != nil {
return err
}
}
return nil
}(); err != nil {
return err
}

if readErr == io.EOF {
break
}
errorMsg := make([]byte, 1024)
readSize, readErr := errReader.Read(errorMsg)
if readErr != nil && readErr != io.EOF {
return err
}
if readSize > 0 {
log.Warn(string(errorMsg))
}

err = cmd.Wait()
if err != nil {
return errors.Wrapf(err, "error message: %s", errBuilder.String())
return errors.Wrapf(err, "error message: %s", errorMsg)
}
return nil
}
Expand Down

0 comments on commit aed8820

Please sign in to comment.