Skip to content

Commit

Permalink
Add human friendly error message when RPC fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
nasdf committed Jan 28, 2021
1 parent e921416 commit 8a2100c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package rpc

import (
"errors"
"net"
"net/http"
"net/rpc"
Expand All @@ -12,6 +13,11 @@ import (
"github.com/multiverse-vcs/go-multiverse/peer"
)

// ErrConnect is the human friendly error message for failed connections.
var ErrConnect = errors.New(`Could not connect to local RPC server.
Make sure the Multiverse daemon is up.
See 'multi help daemon' for more info.`)

// Service implements an RPC service.
type Service struct {
client *peer.Client
Expand All @@ -35,7 +41,12 @@ func NewClient() (*rpc.Client, error) {
return nil, err
}

return rpc.DialHTTP("unix", sock)
client, err := rpc.DialHTTP("unix", sock)
if err != nil {
return nil, ErrConnect
}

return client, nil
}

// ListenAndServer starts an RPC listener.
Expand Down

0 comments on commit 8a2100c

Please sign in to comment.