Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: logdog/client/butlerlib/streamclient/tcp.go

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « logdog/client/butlerlib/bootstrap/bootstrap.go ('k') | logdog/client/cli/main.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package streamclient 5 package streamclient
6 6
7 import ( 7 import (
8 "io" 8 "io"
9 "net" 9 "net"
10 10
11 "github.com/luci/luci-go/common/errors" 11 "github.com/luci/luci-go/common/errors"
12 ) 12 )
13 13
14 func tcpProtocolClientFactory(netType string) ClientFactory { 14 func tcpProtocolClientFactory(netType string) ClientFactory {
15 return func(spec string) (Client, error) { 15 return func(spec string) (Client, error) {
16 raddr, err := net.ResolveTCPAddr(netType, spec) 16 raddr, err := net.ResolveTCPAddr(netType, spec)
17 if err != nil { 17 if err != nil {
18 » » » return nil, errors.Annotate(err).Reason("could not resol ve %(net)q address from %(spec)q"). 18 » » » return nil, errors.Annotate(err, "could not resolve %q a ddress from %q", netType, spec).Err()
19 » » » » D("net", netType).
20 » » » » D("spec", spec).
21 » » » » Err()
22 } 19 }
23 20
24 if raddr.IP == nil || raddr.IP.IsUnspecified() { 21 if raddr.IP == nil || raddr.IP.IsUnspecified() {
25 » » » return nil, errors.Reason("a valid %(net)q address must be provided"). 22 » » » return nil, errors.Reason("a valid %q address must be pr ovided", netType).Err()
26 » » » » D("net", netType).
27 » » » » Err()
28 } 23 }
29 24
30 if raddr.Port <= 0 { 25 if raddr.Port <= 0 {
31 return nil, errors.New("a valid port must be provided") 26 return nil, errors.New("a valid port must be provided")
32 } 27 }
33 28
34 return &clientImpl{ 29 return &clientImpl{
35 factory: func() (io.WriteCloser, error) { 30 factory: func() (io.WriteCloser, error) {
36 conn, err := net.DialTCP(netType, nil, raddr) 31 conn, err := net.DialTCP(netType, nil, raddr)
37 if err != nil { 32 if err != nil {
38 » » » » » return nil, errors.Annotate(err).Reason( "failed to dial %(net)q address %(raddr)q"). 33 » » » » » return nil, errors.Annotate(err, "failed to dial %q address %q", netType, raddr).Err()
39 » » » » » » D("net", netType).
40 » » » » » » D("raddr", raddr).
41 » » » » » » Err()
42 } 34 }
43 return conn, nil 35 return conn, nil
44 }, 36 },
45 }, nil 37 }, nil
46 } 38 }
47 } 39 }
OLDNEW
« no previous file with comments | « logdog/client/butlerlib/bootstrap/bootstrap.go ('k') | logdog/client/cli/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698