Skip to content

Commit 2cbf58d

Browse files
committed
error return value is unnecessary
1 parent 419b88e commit 2cbf58d

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

netrc/netrc.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package netrc
33
import (
44
"bufio"
55
"bytes"
6-
"errors"
76
"fmt"
87
"io"
98
"io/ioutil"
@@ -46,23 +45,23 @@ type Netrc struct {
4645

4746
// FindMachine returns the Machine in n named by name. If a machine named by
4847
// name exists, it is returned. If no Machine with name name is found and there
49-
// is a ``default'' machine, the ``default'' machine is returned . Otherwise, an
50-
// error is returned.
51-
func (n *Netrc) FindMachine(name string) (m *Machine, err error) {
48+
// is a ``default'' machine, the ``default'' machine is returned. Otherwise, nil
49+
// is returned.
50+
func (n *Netrc) FindMachine(name string) (m *Machine) {
5251
// TODO(bgentry): not safe for concurrency
5352
var def *Machine
5453
for _, m = range n.machines {
5554
if m.Name == name {
56-
return m, nil
55+
return m
5756
}
5857
if m.IsDefault() {
5958
def = m
6059
}
6160
}
6261
if def == nil {
63-
return nil, errors.New("no machine found")
62+
return nil
6463
}
65-
return def, nil
64+
return def
6665
}
6766

6867
// MarshalText implements the encoding.TextMarshaler interface to encode a
@@ -462,13 +461,14 @@ func Parse(r io.Reader) (*Netrc, error) {
462461
}
463462

464463
// FindMachine parses the netrc file identified by filename and returns the
465-
// Machine named by name. If a machine named by name exists, it is returned. If
466-
// no Machine with name name is found and there is a ``default'' machine, the
467-
// ``default'' machine is returned. Otherwise, an error is returned.
464+
// Machine named by name. If a problem occurs parsing the file at filename, an
465+
// error is returned. If a machine named by name exists, it is returned. If no
466+
// Machine with name name is found and there is a ``default'' machine, the
467+
// ``default'' machine is returned. Otherwise, nil is returned.
468468
func FindMachine(filename, name string) (m *Machine, err error) {
469469
n, err := ParseFile(filename)
470470
if err != nil {
471471
return nil, err
472472
}
473-
return n.FindMachine(name)
473+
return n.FindMachine(name), nil
474474
}

netrc/netrc_test.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,19 @@ func TestNetrcFindMachine(t *testing.T) {
151151
t.Fatal(err)
152152
}
153153

154-
m, err := n.FindMachine("ray")
155-
if err != nil {
156-
t.Fatal(err)
157-
}
154+
m := n.FindMachine("ray")
158155
if !eqMachine(m, expectedMachines[1]) {
159156
t.Errorf("bad machine; expected %v, got %v\n", expectedMachines[1], m)
160157
}
161158
if m.IsDefault() {
162159
t.Errorf("expected def to be false")
163160
}
161+
162+
n = &Netrc{}
163+
m = n.FindMachine("nonexistent")
164+
if m != nil {
165+
t.Errorf("expected nil, got %v", m)
166+
}
164167
}
165168

166169
func TestMarshalText(t *testing.T) {
@@ -347,10 +350,7 @@ func TestUpdateLogin(t *testing.T) {
347350
}
348351

349352
for _, test := range tests {
350-
m, err := n.FindMachine(test.name)
351-
if err != nil {
352-
t.Fatal(err)
353-
}
353+
m := n.FindMachine(test.name)
354354
if m.IsDefault() == test.exists {
355355
t.Errorf("expected machine %s to not exist, but it did", test.name)
356356
} else {
@@ -362,10 +362,7 @@ func TestUpdateLogin(t *testing.T) {
362362
continue
363363
}
364364
m.UpdateLogin(test.newlogin)
365-
m, err := n.FindMachine(test.name)
366-
if err != nil {
367-
t.Fatal(err)
368-
}
365+
m := n.FindMachine(test.name)
369366
if m.Login != test.newlogin {
370367
t.Errorf("expected new login %q, got %q", test.newlogin, m.Login)
371368
}
@@ -415,10 +412,7 @@ func TestUpdatePassword(t *testing.T) {
415412
}
416413

417414
for _, test := range tests {
418-
m, err := n.FindMachine(test.name)
419-
if err != nil {
420-
t.Fatal(err)
421-
}
415+
m := n.FindMachine(test.name)
422416
if m.IsDefault() == test.exists {
423417
t.Errorf("expected machine %s to not exist, but it did", test.name)
424418
} else {
@@ -430,10 +424,7 @@ func TestUpdatePassword(t *testing.T) {
430424
continue
431425
}
432426
m.UpdatePassword(test.newpassword)
433-
m, err := n.FindMachine(test.name)
434-
if err != nil {
435-
t.Fatal(err)
436-
}
427+
m = n.FindMachine(test.name)
437428
if m.Password != test.newpassword {
438429
t.Errorf("expected new password %q, got %q", test.newpassword, m.Password)
439430
}

0 commit comments

Comments
 (0)