fix unreachable code & missing stringer-generated code

This commit is contained in:
Christian Schwarz 2017-09-30 16:31:55 +02:00
parent 6199595602
commit 0cbee78b40
12 changed files with 53 additions and 24 deletions

View File

@ -111,7 +111,6 @@ func (m DatasetMapFilter) Map(source *zfs.DatasetPath) (target *zfs.DatasetPath,
mi, hasMapping := m.mostSpecificPrefixMapping(source) mi, hasMapping := m.mostSpecificPrefixMapping(source)
if !hasMapping { if !hasMapping {
return nil, nil return nil, nil
return
} }
me := m.entries[mi] me := m.entries[mi]

View File

@ -4,9 +4,9 @@ import (
"io/ioutil" "io/ioutil"
"fmt" "fmt"
yaml "github.com/go-yaml/yaml"
"github.com/mitchellh/mapstructure" "github.com/mitchellh/mapstructure"
"github.com/pkg/errors" "github.com/pkg/errors"
yaml "github.com/go-yaml/yaml"
"os" "os"
) )
@ -99,7 +99,7 @@ func parseConfig(i interface{}) (c *Config, err error) {
// Try to find its name // Try to find its name
namei, ok := asMap.Jobs[i]["name"] namei, ok := asMap.Jobs[i]["name"]
if !ok { if !ok {
namei = fmt.Sprintf("<no name, %i in list>", i) namei = fmt.Sprintf("<no name, entry #%d in list>", i)
} }
err = errors.Wrapf(err, "cannot parse job '%v'", namei) err = errors.Wrapf(err, "cannot parse job '%v'", namei)
return nil, err return nil, err
@ -175,9 +175,6 @@ func parseJob(c JobParsingContext, i map[string]interface{}) (j Job, err error)
return nil, errors.Errorf("unknown job type '%s'", jobtype) return nil, errors.Errorf("unknown job type '%s'", jobtype)
} }
panic("implementation error")
return nil, nil
} }
func parseConnect(i map[string]interface{}) (c RWCConnecter, err error) { func parseConnect(i map[string]interface{}) (c RWCConnecter, err error) {
@ -194,8 +191,6 @@ func parseConnect(i map[string]interface{}) (c RWCConnecter, err error) {
return nil, errors.Errorf("unknown connection type '%s'", t) return nil, errors.Errorf("unknown connection type '%s'", t)
} }
panic("implementation error")
return
} }
func parseInitialReplPolicy(v interface{}, defaultPolicy InitialReplPolicy) (p InitialReplPolicy, err error) { func parseInitialReplPolicy(v interface{}, defaultPolicy InitialReplPolicy) (p InitialReplPolicy, err error) {
@ -239,9 +234,6 @@ func parsePrunePolicy(v map[string]interface{}) (p PrunePolicy, err error) {
return return
} }
panic("implementation error")
return
} }
func parseAuthenticatedChannelListenerFactory(c JobParsingContext, v map[string]interface{}) (p AuthenticatedChannelListenerFactory, err error) { func parseAuthenticatedChannelListenerFactory(c JobParsingContext, v map[string]interface{}) (p AuthenticatedChannelListenerFactory, err error) {
@ -259,7 +251,4 @@ func parseAuthenticatedChannelListenerFactory(c JobParsingContext, v map[string]
return return
} }
panic("implementation error")
return
} }

View File

@ -15,11 +15,11 @@ func ListenUnixPrivate(sockaddr *net.UnixAddr) (*net.UnixListener, error) {
return nil, errors.Wrapf(err, "cannot stat(2) '%s'", sockdir) return nil, errors.Wrapf(err, "cannot stat(2) '%s'", sockdir)
} }
if !sdstat.IsDir() { if !sdstat.IsDir() {
return nil, errors.Errorf("%s is not a directory: %s", sockdir) return nil, errors.Errorf("not a directory: %s", sockdir)
} }
p := sdstat.Mode().Perm() p := sdstat.Mode().Perm()
if p&0007 != 0 { if p&0007 != 0 {
return nil, errors.Errorf("%s must not be world-accessible (permissions are %#o)", p) return nil, errors.Errorf("socket directory not be world-accessible: %s (permissions are %#o)", sockdir, p)
} }
// Maybe things have not been cleaned up before // Maybe things have not been cleaned up before

View File

@ -310,8 +310,7 @@ func doPull(pull PullContext) (err error) {
} }
panic("implementation error: this should not be reached") panic("should not be reached")
return false
}) })

View File

@ -47,7 +47,7 @@ func (l Level) String() string {
case Error: case Error:
return "error" return "error"
default: default:
return fmt.Sprintf("%s", l) return fmt.Sprintf("%s", string(l))
} }
} }

View File

@ -72,7 +72,7 @@ func (l *Logger) WithField(field string, val interface{}) *Logger {
defer l.mtx.Unlock() defer l.mtx.Unlock()
if _, ok := l.fields[field]; ok { if _, ok := l.fields[field]; ok {
fmt.Fprintf(os.Stderr, "%s caller overwrites field '%s'. Stack:\n%s\n", InternalErrorPrefix, string(debug.Stack())) fmt.Fprintf(os.Stderr, "%s caller overwrites field '%s'. Stack:\n%s\n", InternalErrorPrefix, field, string(debug.Stack()))
} }
child := &Logger{ child := &Logger{

View File

@ -26,6 +26,7 @@ const (
FrameTypeRST FrameType = 0xff FrameTypeRST FrameType = 0xff
) )
//go:generate stringer -type=Status
type Status uint64 type Status uint64
const ( const (
@ -154,7 +155,7 @@ func (w *frameBridgingWriter) writeUntilFrameFull(b []byte) (n int, err error) {
return return
} }
if w.bytesLeftToLimit == 0 { if w.bytesLeftToLimit == 0 {
err = errors.Errorf("exceeded limit of total %v bytes for this message") err = errors.Errorf("message exceeds max number of allowed bytes")
return return
} }
maxwrite := len(b) maxwrite := len(b)

27
rpc/frametype_string.go Normal file
View File

@ -0,0 +1,27 @@
// Code generated by "stringer -type=FrameType"; DO NOT EDIT.
package rpc
import "fmt"
const (
_FrameType_name_0 = "FrameTypeHeaderFrameTypeDataFrameTypeTrailer"
_FrameType_name_1 = "FrameTypeRST"
)
var (
_FrameType_index_0 = [...]uint8{0, 15, 28, 44}
_FrameType_index_1 = [...]uint8{0, 12}
)
func (i FrameType) String() string {
switch {
case 1 <= i && i <= 3:
i -= 1
return _FrameType_name_0[_FrameType_index_0[i]:_FrameType_index_0[i+1]]
case i == 255:
return _FrameType_name_1
default:
return fmt.Sprintf("FrameType(%d)", i)
}
}

View File

@ -28,7 +28,6 @@ func (s *LocalRPC) RegisterEndpoint(name string, handler interface{}) (err error
func (s *LocalRPC) Serve() (err error) { func (s *LocalRPC) Serve() (err error) {
panic("local cannot serve") panic("local cannot serve")
return nil
} }
func (c *LocalRPC) Call(endpoint string, in, out interface{}) (err error) { func (c *LocalRPC) Call(endpoint string, in, out interface{}) (err error) {

View File

@ -160,7 +160,6 @@ func (s *Server) ServeRequest() (err error) {
r := NewErrorHeader(StatusRequestError, "unregistered control endpoint %s", h.Endpoint) r := NewErrorHeader(StatusRequestError, "unregistered control endpoint %s", h.Endpoint)
return s.writeResponse(r) return s.writeResponse(r)
} }
panic("implementation error")
} }
ep, ok := s.endpoints[h.Endpoint] ep, ok := s.endpoints[h.Endpoint]

17
rpc/status_string.go Normal file
View File

@ -0,0 +1,17 @@
// Code generated by "stringer -type=Status"; DO NOT EDIT.
package rpc
import "fmt"
const _Status_name = "StatusOKStatusRequestErrorStatusServerErrorStatusError"
var _Status_index = [...]uint8{0, 8, 26, 43, 54}
func (i Status) String() string {
i -= 1
if i >= Status(len(_Status_index)-1) {
return fmt.Sprintf("Status(%d)", i+1)
}
return _Status_name[_Status_index[i]:_Status_index[i+1]]
}

View File

@ -25,7 +25,6 @@ func (t VersionType) DelimiterChar() string {
default: default:
panic(fmt.Sprintf("unexpected VersionType %#v", t)) panic(fmt.Sprintf("unexpected VersionType %#v", t))
} }
return ""
} }
type FilesystemVersion struct { type FilesystemVersion struct {