diff --git a/config.go b/config.go index 5dde4340..cbf09258 100644 --- a/config.go +++ b/config.go @@ -37,7 +37,7 @@ func (c ConfigContext) Configuration() Configuration { // resp, err := paxos.Prepare(cfgCtx, req) func (c Configuration) Context(parent context.Context) *ConfigContext { if len(c) == 0 { - panic("gorums: Context called with empty configuration") + panic("gorums: Context called on an empty configuration") } return &ConfigContext{Context: parent, cfg: c} } @@ -52,7 +52,7 @@ func (c Configuration) Context(parent context.Context) *ConfigContext { // ) func NewConfig(nodes NodeListOption, opts ...DialOption) (Configuration, error) { if nodes == nil { - return nil, fmt.Errorf("config: missing required node list") + return nil, fmt.Errorf("gorums: missing required node list") } mgr := newOutboundManager(opts...) cfg, err := nodes.newConfig(mgr) @@ -66,7 +66,7 @@ func NewConfig(nodes NodeListOption, opts ...DialOption) (Configuration, error) // Extend returns a new Configuration combining c with new nodes from the provided NodeListOption. func (c Configuration) Extend(opt NodeListOption) (Configuration, error) { if len(c) == 0 { - return nil, fmt.Errorf("config: cannot extend empty configuration") + return nil, fmt.Errorf("gorums: cannot extend empty configuration") } if opt == nil { return slices.Clone(c), nil diff --git a/config_opts.go b/config_opts.go index c6e05fc7..a92d73b7 100644 --- a/config_opts.go +++ b/config_opts.go @@ -39,7 +39,7 @@ func (nodeMap[T]) isOption() {} func (nm nodeMap[T]) newConfig(registry nodeRegistry) (Configuration, error) { if len(nm) == 0 { - return nil, fmt.Errorf("config: missing required node map") + return nil, fmt.Errorf("gorums: missing required node map") } builder := newNodeBuilder(registry, len(nm)) // Sort IDs to ensure deterministic processing order @@ -66,7 +66,7 @@ func (nodeList) isOption() {} func (nl nodeList) newConfig(registry nodeRegistry) (Configuration, error) { if len(nl) == 0 { - return nil, fmt.Errorf("config: missing required node addresses") + return nil, fmt.Errorf("gorums: missing required node addresses") } builder := newNodeBuilder(registry, len(nl)) nextID := builder.nextID() @@ -113,17 +113,17 @@ func newNodeBuilder(registry nodeRegistry, capacity int) *nodeBuilder { // add creates or reuses a node with the given ID and address. func (b *nodeBuilder) add(id uint32, addr string) error { if id == 0 { - return fmt.Errorf("config: node 0 is reserved") + return fmt.Errorf("gorums: node 0 is reserved") } normalizedAddr, err := normalizeAddr(addr) if err != nil { - return fmt.Errorf("config: invalid address %q: %w", addr, err) + return fmt.Errorf("gorums: invalid address %q: %w", addr, err) } // If ID already exists, verify address matches if existingNode, found := b.idToNode[id]; found { if existingNode.Address() != normalizedAddr { - return fmt.Errorf("config: node %d already in use by %q", id, existingNode.Address()) + return fmt.Errorf("gorums: node %d already in use by %q", id, existingNode.Address()) } b.nodes = append(b.nodes, existingNode) return nil @@ -131,7 +131,7 @@ func (b *nodeBuilder) add(id uint32, addr string) error { // Check for duplicate address if existingID, exists := b.addrToID[normalizedAddr]; exists { - return fmt.Errorf("config: address %q already in use by node %d", normalizedAddr, existingID) + return fmt.Errorf("gorums: address %q already in use by node %d", normalizedAddr, existingID) } b.addrToID[normalizedAddr] = id diff --git a/config_test.go b/config_test.go index 142c6c44..237fdf3c 100644 --- a/config_test.go +++ b/config_test.go @@ -45,12 +45,12 @@ func TestNewConfig(t *testing.T) { { name: "WithNodeList/Reject/EmptyNodeList", opt: gorums.WithNodeList([]string{}), - wantErr: "config: missing required node addresses", + wantErr: "gorums: missing required node addresses", }, { name: "WithNodes/Reject/EmptyNodeMap", opt: gorums.WithNodes(map[uint32]testNode{}), - wantErr: "config: missing required node map", + wantErr: "gorums: missing required node map", }, { name: "WithNodes/Reject/ZeroID", @@ -58,7 +58,7 @@ func TestNewConfig(t *testing.T) { 0: {addr: "127.0.0.1:9080"}, // ID 0 should be rejected 1: {addr: "127.0.0.1:9081"}, }), - wantErr: "config: node 0 is reserved", + wantErr: "gorums: node 0 is reserved", }, { name: "WithNodes/Reject/DuplicateAddress", @@ -66,7 +66,7 @@ func TestNewConfig(t *testing.T) { 1: {addr: "127.0.0.1:9081"}, 2: {addr: "127.0.0.1:9081"}, // Duplicate address }), - wantErr: `config: address "127.0.0.1:9081" already in use by node 1`, + wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`, }, { name: "WithNodeList/Reject/DuplicateAddress", @@ -74,7 +74,7 @@ func TestNewConfig(t *testing.T) { "127.0.0.1:9081", "127.0.0.1:9081", // Duplicate address }), - wantErr: `config: address "127.0.0.1:9081" already in use by node 1`, + wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`, }, { name: "WithNodes/Reject/NormalizedDuplicateAddress", @@ -82,7 +82,7 @@ func TestNewConfig(t *testing.T) { 1: {addr: "localhost:9081"}, 2: {addr: "127.0.0.1:9081"}, // Same resolved address }), - wantErr: `config: address "127.0.0.1:9081" already in use by node 1`, + wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`, }, { name: "WithNodeList/Reject/NormalizedDuplicateAddress", @@ -90,7 +90,7 @@ func TestNewConfig(t *testing.T) { "localhost:9081", "127.0.0.1:9081", // Same resolved address }), - wantErr: `config: address "127.0.0.1:9081" already in use by node 1`, + wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`, }, } for _, tt := range tests { @@ -155,7 +155,7 @@ func TestConfigurationExtend(t *testing.T) { extendOpt: gorums.WithNodes(map[uint32]testNode{ 0: {addr: "127.0.0.1:9090"}, // ID 0 should be rejected }), - wantErr: "config: node 0 is reserved", + wantErr: "gorums: node 0 is reserved", }, { name: "WithNodes/Reject/IDConflict", @@ -163,7 +163,7 @@ func TestConfigurationExtend(t *testing.T) { extendOpt: gorums.WithNodes(map[uint32]testNode{ 2: {addr: "127.0.0.1:9090"}, // ID 2 already exists, rejected }), - wantErr: `config: node 2 already in use by "127.0.0.1:9082"`, + wantErr: `gorums: node 2 already in use by "127.0.0.1:9082"`, }, { name: "WithNodes/Reject/AddressConflict", @@ -171,7 +171,7 @@ func TestConfigurationExtend(t *testing.T) { extendOpt: gorums.WithNodes(map[uint32]testNode{ 3: {addr: "127.0.0.1:9081"}, // Same address as ID 1 }), - wantErr: `config: address "127.0.0.1:9081" already in use by node 1`, + wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`, }, { name: "WithNodes/Reject/NormalizedAddressConflict", @@ -179,7 +179,7 @@ func TestConfigurationExtend(t *testing.T) { extendOpt: gorums.WithNodes(map[uint32]testNode{ 3: {addr: "localhost:9081"}, // Resolves to same as existing node 1 }), - wantErr: `config: address "127.0.0.1:9081" already in use by node 1`, + wantErr: `gorums: address "127.0.0.1:9081" already in use by node 1`, }, } for _, tt := range tests { diff --git a/correctable.go b/correctable.go index 2724ccb1..d1cb31ad 100644 --- a/correctable.go +++ b/correctable.go @@ -68,7 +68,7 @@ func (c *Correctable[Resp]) update(reply Resp, level int, done bool, err error) c.mu.Lock() defer c.mu.Unlock() if c.done { - panic("update(...) called on a done correctable") + panic("gorums: update(...) called on a completed correctable") } c.reply, c.level, c.err, c.done = reply, level, err, done if done { diff --git a/doc/user-guide.md b/doc/user-guide.md index 91ffc290..1f8fc7a2 100644 --- a/doc/user-guide.md +++ b/doc/user-guide.md @@ -1382,7 +1382,7 @@ Without `Release()`, the server would block all other inbound messages until the func (s *storageServer) ReadNestedQC(ctx gorums.ServerCtx, req *pb.ReadRequest) (*pb.ReadResponse, error) { config := ctx.Config() if len(config) == 0 { - return nil, fmt.Errorf("ReadNestedQC requires a server peer configuration") + return nil, fmt.Errorf("read_nested_qc: requires a server peer configuration") } // Release the handler lock before making nested outbound calls to avoid // blocking inbound message processing on this server. @@ -1520,7 +1520,7 @@ The handler reads `ctx.ClientConfig()` to reach all currently connected client p func (s *storageServer) ReadNestedQC(ctx gorums.ServerCtx, req *pb.ReadRequest) (*pb.ReadResponse, error) { config := ctx.ClientConfig() if len(config) == 0 { - return nil, fmt.Errorf("ReadNestedQC: no client peers connected") + return nil, fmt.Errorf("read_nested_qc: no client peers connected") } ctx.Release() return newestValue(pb.ReadQC(config.Context(ctx), req)) diff --git a/inbound_manager.go b/inbound_manager.go index eefa6435..bb5f9391 100644 --- a/inbound_manager.go +++ b/inbound_manager.go @@ -3,7 +3,7 @@ package gorums import ( "cmp" "context" - "errors" + "fmt" "maps" "slices" "sync" @@ -263,7 +263,7 @@ func (im *inboundManager) acceptClient(streamCtx context.Context, inboundStream im.mu.Lock() defer im.mu.Unlock() if im.nextClientID == ^uint32(0) { - return nil, func() {}, errors.New("gorums: dynamic client ID space exhausted") + return nil, func() {}, fmt.Errorf("gorums: dynamic client ID space exhausted") } id := im.nextClientID im.nextClientID++ diff --git a/internal/stream/channel.go b/internal/stream/channel.go index d77c30bf..b3652de0 100644 --- a/internal/stream/channel.go +++ b/internal/stream/channel.go @@ -287,7 +287,7 @@ func (c *Channel) isConnected() bool { // Combining them would cause double delivery on the response channel. func (c *Channel) Enqueue(req Request) { if req.WaitSendDone && req.Streaming { - panic("stream: WaitSendDone and Streaming are mutually exclusive") + panic("gorums: WaitSendDone and Streaming are mutually exclusive") } if c.isLocal() { c.router.DispatchLocalRequest(c.id, req) diff --git a/mgr.go b/mgr.go index e471cc58..5a9b5a56 100644 --- a/mgr.go +++ b/mgr.go @@ -83,7 +83,7 @@ func (m *outboundManager) addNode(node *Node) { func (m *outboundManager) newNode(id uint32, addr string) (*Node, error) { if _, found := m.Node(id); found { - return nil, fmt.Errorf("node %d already exists", id) + return nil, fmt.Errorf("gorums: node %d already exists", id) } // Use a local (in-process) node when this ID is our own local node // and a handler is configured (symmetric peer configuration). diff --git a/node.go b/node.go index c8a85261..138e698f 100644 --- a/node.go +++ b/node.go @@ -64,7 +64,7 @@ type Node struct { // resp, err := service.GRPCCall(nodeCtx, req) func (n *Node) Context(parent context.Context) *NodeContext { if n == nil { - panic("gorums: Context called with nil node") + panic("gorums: Context called on nil node") } return &NodeContext{Context: parent, node: n} } diff --git a/opts_test.go b/opts_test.go index 9578b615..fcd2dbde 100644 --- a/opts_test.go +++ b/opts_test.go @@ -13,27 +13,27 @@ import ( // a panic when the caller invokes the nil function. func TestSplitOptionsTypedNil(t *testing.T) { tests := []struct { - name string - opts []Option - wantSrvLen int + name string + opts []Option + wantSrvLen int wantDialLen int }{ { - name: "UntypedNil", - opts: []Option{nil}, - wantSrvLen: 0, + name: "UntypedNil", + opts: []Option{nil}, + wantSrvLen: 0, wantDialLen: 0, }, { - name: "NilDialOption", - opts: []Option{DialOption(nil)}, - wantSrvLen: 0, + name: "NilDialOption", + opts: []Option{DialOption(nil)}, + wantSrvLen: 0, wantDialLen: 0, }, { - name: "NilServerOption", - opts: []Option{ServerOption(nil)}, - wantSrvLen: 0, + name: "NilServerOption", + opts: []Option{ServerOption(nil)}, + wantSrvLen: 0, wantDialLen: 0, }, { @@ -44,7 +44,7 @@ func TestSplitOptionsTypedNil(t *testing.T) { ServerOption(nil), WithReceiveBufferSize(0), }, - wantSrvLen: 1, + wantSrvLen: 1, wantDialLen: 1, }, } diff --git a/testopts.go b/testopts.go index 717b1c62..e1012806 100644 --- a/testopts.go +++ b/testopts.go @@ -46,7 +46,7 @@ func (to *testOptions) serverFunc(srvFn func(i int) ServerIface) func(i int) Ser } if len(to.serverOpts) > 0 { // You need to pass nil as the server function to use server options with the default server - panic("gorums: cannot use server options with a custom server function; use nil to use the default test server") + panic("gorums: cannot use server options with a custom server function") } return srvFn } @@ -107,7 +107,7 @@ type stopFuncProvider struct { // This option is intended for testing purposes only. func WithStopFunc(_ testing.TB, fn *func(...int)) TestOption { if fn == nil { - panic("gorums: WithStopFunc called with nil pointer") + panic("gorums: WithStopFunc called with nil function pointer") } return stopFuncProvider{stopFunc: fn} }