From c38515e5c6db52bbcd88804636826d6eb8906a89 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Fri, 31 Aug 2018 12:19:09 +0900 Subject: [PATCH] It's safe to ignore the error from bytes.Buffer.Write methods. They can't actually error, they have an error return so that they fit the io.Writer interface. (https://golang.org/src/bytes/buffer.go#L170) With the error removed the FIXME/panic in the caller should be safe to remove as well. --- api/api.go | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/api/api.go b/api/api.go index 1b9289f24..aa2037509 100644 --- a/api/api.go +++ b/api/api.go @@ -88,41 +88,27 @@ type Orb struct { Executors map[string]struct{} } -func addOrbElementsToBuffer(buf *bytes.Buffer, name string, elems map[string]struct{}) error { +func addOrbElementsToBuffer(buf *bytes.Buffer, name string, elems map[string]struct{}) { var err error - if len(elems) > 0 { _, err = buf.WriteString(fmt.Sprintf(" %s:\n", name)) - if err != nil { - return err - } for key := range elems { _, err = buf.WriteString(fmt.Sprintf(" - %s\n", key)) - if err != nil { - return err - } } } - - return err + // This should never occur, but the linter made me do it :shrug: + if err != nil { + panic(err) + } } func (orb Orb) String() string { var buffer bytes.Buffer - err := addOrbElementsToBuffer(&buffer, "Commands", orb.Commands) - // FIXME: refactor this to handle the error - if err != nil { - panic(err) - } - err = addOrbElementsToBuffer(&buffer, "Jobs", orb.Jobs) - if err != nil { - panic(err) - } - err = addOrbElementsToBuffer(&buffer, "Executors", orb.Executors) - if err != nil { - panic(err) - } + addOrbElementsToBuffer(&buffer, "Commands", orb.Commands) + addOrbElementsToBuffer(&buffer, "Jobs", orb.Jobs) + addOrbElementsToBuffer(&buffer, "Executors", orb.Executors) + return buffer.String() }