Skip to content

Commit

Permalink
source-mysql: Tweak error message wording
Browse files Browse the repository at this point in the history
The error message can get a bit long, so it's useful to have the
extra word "both" in there to indicate "if you skim further along
you will see a second error message".
  • Loading branch information
willdonnelly committed Oct 29, 2024
1 parent 81e1f94 commit 1660259
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions source-mysql-batch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ func connectMySQL(ctx context.Context, cfg *Config) (*client.Conn, error) {
log.WithField("addr", cfg.Address).Info("connected without TLS")
conn = connWithoutTLS
} else if errors.As(errWithoutTLS, &mysqlErr) && mysqlErr.Code == mysql.ER_ACCESS_DENIED_ERROR {
log.WithField("withTLS", errWithTLS).Warn("connecting with TLS failed for an unrelated reason")
log.WithFields(log.Fields{"withTLS": errWithTLS, "nonTLS": errWithoutTLS}).Error("unable to connect to database")
return nil, cerrors.NewUserError(mysqlErr, "incorrect username or password")
} else if errors.As(errWithoutTLS, &mysqlErr) && mysqlErr.Code == mysqlErrorCodeSecureTransportRequired {
return nil, fmt.Errorf("unable to connect to database: %w", errWithTLS)
} else {
return nil, fmt.Errorf("unable to connect to database: failed with TLS (%w) and without TLS (%w)", errWithTLS, errWithoutTLS)
return nil, fmt.Errorf("unable to connect to database: failed both with TLS (%w) and without TLS (%w)", errWithTLS, errWithoutTLS)
}

if _, err := conn.Execute("SELECT true;"); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions source-mysql/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ func (db *mysqlDatabase) connect(_ context.Context) error {
logrus.WithField("addr", address).Info("connected without TLS")
db.conn = connWithoutTLS
} else if errors.As(errWithoutTLS, &mysqlErr) && mysqlErr.Code == mysql.ER_ACCESS_DENIED_ERROR {
logrus.WithField("withTLS", errWithTLS).Warn("connecting with TLS failed for an unrelated reason")
logrus.WithFields(logrus.Fields{"withTLS": errWithTLS, "nonTLS": errWithoutTLS}).Error("unable to connect to database")
return cerrors.NewUserError(mysqlErr, "incorrect username or password")
} else if errors.As(errWithoutTLS, &mysqlErr) && mysqlErr.Code == mysqlErrorCodeSecureTransportRequired {
return fmt.Errorf("unable to connect to database: %w", errWithTLS)
} else {
return fmt.Errorf("unable to connect to database: failed with TLS (%w) and without TLS (%w)", errWithTLS, errWithoutTLS)
return fmt.Errorf("unable to connect to database: failed both with TLS (%w) and without TLS (%w)", errWithTLS, errWithoutTLS)
}

// Debug logging hook so we can get the server config variables when needed
Expand Down

0 comments on commit 1660259

Please sign in to comment.