go.ligato.io/vpp-agent/v3@v3.5.0/cmd/agentctl/client/errors.go (about) 1 package client 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 // errConnectionFailed implements an error returned when connection failed. 9 type errConnectionFailed struct { 10 host string 11 } 12 13 // Error returns a string representation of an errConnectionFailed 14 func (err errConnectionFailed) Error() string { 15 if err.host == "" { 16 return "Cannot connect to the agent. Is the agent running on this host?" 17 } 18 return fmt.Sprintf("Cannot connect to the agent at %s. Is the agent running?", err.host) 19 } 20 21 // IsErrConnectionFailed returns true if the error is caused by connection failed. 22 func IsErrConnectionFailed(err error) bool { 23 var connErr *errConnectionFailed 24 return errors.As(err, &connErr) 25 } 26 27 // ErrorConnectionFailed returns an error with host in the error message when connection to agent failed. 28 func ErrorConnectionFailed(host string) error { 29 return errConnectionFailed{host: host} 30 }