Skip to content

Commit

Permalink
Support read timeout for SQL loop and better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-coavoux committed Jun 20, 2023
1 parent 3f19729 commit a89b550
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions mssql/resource_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func resourceLogin() *schema.Resource {
},
Timeouts: &schema.ResourceTimeout{
Default: defaultTimeout,
Read: defaultTimeout,
},
}
}
Expand Down
1 change: 1 addition & 0 deletions mssql/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func resourceUser() *schema.Resource {
},
Timeouts: &schema.ResourceTimeout{
Default: defaultTimeout,
Read: defaultTimeout,
},
}
}
Expand Down
13 changes: 11 additions & 2 deletions sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,24 @@ func connectLoop(connector driver.Connector, timeout time.Duration) (*sql.DB, er
if err == nil {
return db, nil
}
if strings.Contains(err.Error(), "Login failed") {
if strings.Contains(strings.ToLower(err.Error()), "login failed") {
return nil, err
}
if strings.Contains(err.Error(), "Login error") {
if strings.Contains(strings.ToLower(err.Error()), "login error") {
return nil, err
}
if strings.Contains(err.Error(), "error retrieving access token") {
return nil, err
}
if strings.Contains(err.Error(), "AuthenticationFailedError") {
return nil, err
}
if strings.Contains(err.Error(), "credential") {
return nil, err
}
if strings.Contains(err.Error(), "request failed") {
return nil, err
}
log.Println(errors.Wrap(err, "failed to connect to database"))
}
}
Expand Down

0 comments on commit a89b550

Please sign in to comment.