blob: eebca94c98cd6725f21c583e771696126bf44611 [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// Copyright (C) MongoDB, Inc. 2017-present.
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may
4// not use this file except in compliance with the License. You may obtain
5// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6
7package connection
8
9import "fmt"
10
11// Error represents a connection error.
12type Error struct {
13 ConnectionID string
14 Wrapped error
15
16 message string
17}
18
19// Error implements the error interface.
20func (e Error) Error() string {
21 if e.Wrapped != nil {
22 return fmt.Sprintf("connection(%s) %s: %s", e.ConnectionID, e.message, e.Wrapped.Error())
23 }
24 return fmt.Sprintf("connection(%s) %s", e.ConnectionID, e.message)
25}
26
27// NetworkError represents an error that occurred while reading from or writing
28// to a network socket.
29type NetworkError struct {
30 ConnectionID string
31 Wrapped error
32}
33
34func (ne NetworkError) Error() string {
35 return fmt.Sprintf("connection(%s): %s", ne.ConnectionID, ne.Wrapped.Error())
36}
37
38// PoolError is an error returned from a Pool method.
39type PoolError string
40
41func (pe PoolError) Error() string { return string(pe) }