Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a new ConnectionError type for network errors #418

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,16 @@ func badStreamPanic(err error) {
func badStreamPanicf(format string, v ...interface{}) {
panic(streamErrorf(format, v...))
}

type ConnectionError struct {
Message string
Err error
}

func (c ConnectionError) Error() string {
return fmt.Sprintf("%s: %v", c.Message, c.Err)
}

func connectionError(message string, err error) ConnectionError {
return ConnectionError{Message: message, Err: err}
}
10 changes: 5 additions & 5 deletions mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (c *Conn) sendCommitRequest() error {
c.sess.log.Printf("Failed to send CommitXact with %v", err)
}
c.connectionGood = false
return fmt.Errorf("Faild to send CommitXact: %v", err)
return connectionError("Failed to send CommitXact", err)
}
return nil
}
Expand All @@ -254,7 +254,7 @@ func (c *Conn) sendRollbackRequest() error {
c.sess.log.Printf("Failed to send RollbackXact with %v", err)
}
c.connectionGood = false
return fmt.Errorf("Failed to send RollbackXact: %v", err)
return connectionError("Failed to send RollbackXact", err)
}
return nil
}
Expand Down Expand Up @@ -291,7 +291,7 @@ func (c *Conn) sendBeginRequest(ctx context.Context, tdsIsolation isoLevel) erro
c.sess.log.Printf("Failed to send BeginXact with %v", err)
}
c.connectionGood = false
return fmt.Errorf("Failed to send BeginXact: %v", err)
return connectionError("Failed to send BeginXant", err)
}
return nil
}
Expand Down Expand Up @@ -438,7 +438,7 @@ func (s *Stmt) sendQuery(args []namedValue) (err error) {
conn.sess.log.Printf("Failed to send SqlBatch with %v", err)
}
conn.connectionGood = false
return fmt.Errorf("failed to send SQL Batch: %v", err)
return connectionError("Failed to send SQL Batch", err)
}
} else {
proc := sp_ExecuteSql
Expand All @@ -463,7 +463,7 @@ func (s *Stmt) sendQuery(args []namedValue) (err error) {
conn.sess.log.Printf("Failed to send Rpc with %v", err)
}
conn.connectionGood = false
return fmt.Errorf("Failed to send RPC: %v", err)
return connectionError("Failed to send RPC", err)
}
}
return
Expand Down