Fix bug when endpoint is invalid or not configured proeprly and fails lookup (#171)
Fixes #169 This now behaves like this: ``` /Users/prologic/Projects/saltyim/saltyim # ./salty-chat write prologic@mills.io test WARN[0000] error looking up user endpoint error="error looking up user testing123@shortcircuit.net.au: non-2xx response received: 404 Not Found" error initializing client: unable to find your endpoint for testing123@shortcircuit.net.au /Users/prologic/Projects/saltyim/saltyim # ``` Co-authored-by: James Mills <prologic@shortcircuit.net.au> Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/171 Reviewed-by: m u t e f a l l <mutefall@noreply@mills.io>
This commit is contained in:
parent
dc432abdc3
commit
9c5fec5caf
18
client.go
18
client.go
|
@ -126,18 +126,22 @@ func NewClient(me *Addr, options ...ClientOption) (*Client, error) {
|
|||
return nil, ErrMissingIdentity
|
||||
}
|
||||
|
||||
if me == nil || me.IsZero() {
|
||||
me = cli.id.addr
|
||||
if cli.me == nil || cli.me.IsZero() {
|
||||
cli.me = cli.id.addr
|
||||
}
|
||||
|
||||
if me == nil || me.IsZero() {
|
||||
return nil, fmt.Errorf("unable to find your user addressn in %s", cli.id.Source())
|
||||
}
|
||||
|
||||
if err := me.Refresh(); err != nil {
|
||||
if err := cli.me.Refresh(); err != nil {
|
||||
log.WithError(err).Warn("error looking up user endpoint")
|
||||
}
|
||||
|
||||
if cli.me == nil || cli.me.IsZero() {
|
||||
return nil, fmt.Errorf("unable to find your user address in %s", cli.id.Source())
|
||||
}
|
||||
|
||||
if cli.me.Endpoint() == nil {
|
||||
return nil, fmt.Errorf("unable to find your endpoint for %s", cli.me.String())
|
||||
}
|
||||
|
||||
log.Debugf("Using identity %s with public key %s", cli.id.Source(), cli.id.key)
|
||||
log.Debugf("Salty Addr is %s", cli.me)
|
||||
log.Debugf("Endpoint is %s", cli.me.Endpoint())
|
||||
|
|
|
@ -7,9 +7,22 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/keys-pub/keys"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestClient_InvalidEndpoint(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
me, err := ParseAddr("foo@example.com")
|
||||
require.NoError(err)
|
||||
assert.NotNil(me)
|
||||
|
||||
_, err = NewClient(me)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
func TestClient_Outbox(t *testing.T) {
|
||||
test := require.New(t)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.mills.io/saltyim"
|
||||
|
@ -31,7 +32,7 @@ NOTE: This is only spported on a Salty Broker.`,
|
|||
|
||||
me, err := saltyim.ParseAddr(user)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
|
||||
log.Debugf("error parsing addr: %s\n", err)
|
||||
}
|
||||
// XXX: What if me.IsZero()
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ messages to the user via their discovered endpoint.`,
|
|||
|
||||
me, err := saltyim.ParseAddr(user)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
|
||||
log.Debugf("error parsing addr: %s\n", err)
|
||||
}
|
||||
// XXX: What if me.IsZero()
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ NOTE: The <endpoint> argument will override and -u/--endpoint flag set.`,
|
|||
|
||||
me, err := saltyim.ParseAddr(args[0])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
|
||||
log.Debugf("error parsing addr: %s\n", err)
|
||||
}
|
||||
// XXX: What if me.IsZero()
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ not specified defaults to the local user ($USER)`,
|
|||
|
||||
me, err := saltyim.ParseAddr(user)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
|
||||
log.Debugf("error parsing addr: %s\n", err)
|
||||
}
|
||||
// XXX: What if me.IsZero()
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.mills.io/saltyim"
|
||||
|
@ -27,7 +28,7 @@ NOTE: This is only spported o a Salty Broker.`,
|
|||
|
||||
me, err := saltyim.ParseAddr(args[0])
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
|
||||
log.Debugf("error parsing addr: %s\n", err)
|
||||
}
|
||||
// XXX: What if me.IsZero()
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
|
@ -48,7 +49,7 @@ https://mills.io/.well-known/salty/prologic.json`,
|
|||
|
||||
me, err := saltyim.ParseAddr(user)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
|
||||
log.Debugf("error parsing addr: %s\n", err)
|
||||
}
|
||||
// XXX: What if me.IsZero()
|
||||
|
||||
|
|
Loading…
Reference in New Issue