Skip to content

Commit

Permalink
chore: replaced configurationError with direct fmt.Errorf
Browse files Browse the repository at this point in the history
Since configurationError only added a prefix.
  • Loading branch information
meling committed Mar 23, 2024
1 parent d0746c9 commit b197cbd
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions cmd/protoc-gen-gorums/dev/mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewManager(opts ...gorums.ManagerOption) (mgr *Manager) {
// using the And, WithNewNodes, Except, and WithoutNodes methods.
func (m *Manager) NewConfiguration(opts ...gorums.ConfigOption) (c *Configuration, err error) {
if len(opts) < 1 || len(opts) > 2 {
return nil, fmt.Errorf("wrong number of options: %d", len(opts))
return nil, fmt.Errorf("config: wrong number of options: %d", len(opts))
}
c = &Configuration{}
for _, opt := range opts {
Expand All @@ -51,13 +51,13 @@ func (m *Manager) NewConfiguration(opts ...gorums.ConfigOption) (c *Configuratio
// Must be last since v may match QuorumSpec if it is interface{}
c.qspec = v
default:
return nil, fmt.Errorf("unknown option type: %v", v)
return nil, fmt.Errorf("config: unknown option type: %v", v)
}
}
// return an error if the QuorumSpec interface is not empty and no implementation was provided.
var test interface{} = struct{}{}
if _, empty := test.(QuorumSpec); !empty && c.qspec == nil {
return nil, fmt.Errorf("missing required QuorumSpec")
return nil, fmt.Errorf("config: missing required QuorumSpec")
}
return c, nil
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/protoc-gen-gorums/gengorums/template_static.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gorums

import "fmt"

// RawConfiguration represents a static set of nodes on which quorum calls may be invoked.
//
// NOTE: mutating the configuration is not supported.
Expand All @@ -14,7 +16,7 @@ type RawConfiguration []*RawNode
// using the And, WithNewNodes, Except, and WithoutNodes methods.
func NewRawConfiguration(mgr *RawManager, opt NodeListOption) (nodes RawConfiguration, err error) {
if opt == nil {
return nil, configurationError("missing required node list")
return nil, fmt.Errorf("config: missing required node list")
}
return opt.newConfig(mgr)
}
Expand Down
12 changes: 7 additions & 5 deletions config_opts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gorums

import "fmt"
import (
"fmt"
)

// ConfigOption is a marker interface for options to NewConfiguration.
type ConfigOption interface{}
Expand All @@ -17,7 +19,7 @@ type nodeIDMap struct {

func (o nodeIDMap) newConfig(mgr *RawManager) (nodes RawConfiguration, err error) {
if len(o.idMap) == 0 {
return nil, configurationError("missing required node map")
return nil, fmt.Errorf("config: missing required node map")
}
nodes = make(RawConfiguration, 0, len(o.idMap))
for naddr, id := range o.idMap {
Expand Down Expand Up @@ -51,7 +53,7 @@ type nodeList struct {

func (o nodeList) newConfig(mgr *RawManager) (nodes RawConfiguration, err error) {
if len(o.addrsList) == 0 {
return nil, configurationError("missing required node addresses")
return nil, fmt.Errorf("config: missing required node addresses")
}
nodes = make(RawConfiguration, 0, len(o.addrsList))
for _, naddr := range o.addrsList {
Expand Down Expand Up @@ -86,14 +88,14 @@ type nodeIDs struct {

func (o nodeIDs) newConfig(mgr *RawManager) (nodes RawConfiguration, err error) {
if len(o.nodeIDs) == 0 {
return nil, configurationError("missing required node IDs")
return nil, fmt.Errorf("config: missing required node IDs")
}
nodes = make(RawConfiguration, 0, len(o.nodeIDs))
for _, id := range o.nodeIDs {
node, found := mgr.Node(id)
if !found {
// Node IDs must have been registered previously
return nil, configurationError(fmt.Sprintf("node %d not found", id))
return nil, fmt.Errorf("config: node %d not found", id)
}
nodes = append(nodes, node)
}
Expand Down
5 changes: 0 additions & 5 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import (
"fmt"
)

// configurationError reports that a Configuration could not be created.
func configurationError(desc string) error {
return fmt.Errorf("configuration: %s", desc)
}

// A QuorumCallError is used to report that a quorum call failed.
type QuorumCallError struct {
Reason string
Expand Down
2 changes: 1 addition & 1 deletion mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (m *RawManager) Size() (nodes int) {
func (m *RawManager) AddNode(node *RawNode) error {
if _, found := m.Node(node.ID()); found {
// Node IDs must be unique
return configurationError(fmt.Sprintf("node %d (%s) already exists", node.ID(), node.Address()))
return fmt.Errorf("config: node %d (%s) already exists", node.ID(), node.Address())
}
if m.logger != nil {
m.logger.Printf("Connecting to %s with id %d\n", node, node.id)
Expand Down
6 changes: 3 additions & 3 deletions mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func TestManagerAddNode(t *testing.T) {
id uint32
err string
}{
{"127.0.1.1:1234", 1, "configuration: node 1 (127.0.1.1:1234) already exists"},
{"127.0.1.1:1234", 1, "config: node 1 (127.0.1.1:1234) already exists"},
{"127.0.1.1:1234", 5, ""},
{"127.0.1.1:1234", 6, ""}, // TODO(meling) does it make sense to allow same addr:port for different IDs?
{"127.0.1.1:1234", 2, "configuration: node 2 (127.0.1.1:1234) already exists"},
{"127.0.1.1:1234", 6, ""}, // The same addr:port can have different IDs
{"127.0.1.1:1234", 2, "config: node 2 (127.0.1.1:1234) already exists"},
}
for _, test := range tests {
node, err := gorums.NewRawNodeWithID(test.addr, test.id)
Expand Down

0 comments on commit b197cbd

Please sign in to comment.