mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-06-16 11:58:24 +00:00
Fix a panic when there is no valid Endpoint (#90)
Fixes #83 But I'm not sure how to properly surface teh aerrors out of the `Subscribe` and `Rain` channels at this time 😆 (and do something sensible with them at eh UI/UX level). Co-authored-by: James Mills <prologic@shortcircuit.net.au> Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/90 Reviewed-by: xuu <xuu@noreply@mills.io> Co-authored-by: James Mills <james@mills.io> Co-committed-by: James Mills <james@mills.io>
This commit is contained in:
parent
2bd7ee7b4e
commit
7fc5e7184b
2
Makefile
2
Makefile
@ -65,7 +65,7 @@ generate: ## Genereate any code required by the build
|
||||
echo 'Running in debug mode...'; \
|
||||
fi
|
||||
|
||||
PWA_SRCS = $(shell find ./internal/pwa -type f)
|
||||
PWA_SRCS = $(shell ls *.go) $(shell find ./internal/pwa -type f)
|
||||
|
||||
internal/web/app.wasm: $(PWA_SRCS)
|
||||
@GOARCH=wasm GOOS=js $(GOCMD) build -o ./internal/web/app.wasm ./internal/pwa/
|
||||
|
20
client.go
20
client.go
@ -26,7 +26,8 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoMessages = errors.New("error: no messages found")
|
||||
ErrNoMessages = errors.New("error: no messages found")
|
||||
ErrClientNotConnected = errors.New("error: client not connected")
|
||||
)
|
||||
|
||||
type addrCache map[string]*Addr
|
||||
@ -228,11 +229,16 @@ func (cli *Client) Drain(ctx context.Context, extraenvs, prehook, posthook strin
|
||||
msg, err := cli.Read(extraenvs, prehook, posthook)
|
||||
if err != nil {
|
||||
log.Debugf("err: #%v", err)
|
||||
if err == ErrNoMessages {
|
||||
switch err {
|
||||
case ErrNoMessages:
|
||||
log.Debug("no more messages, existing readloop...")
|
||||
return
|
||||
case ErrClientNotConnected:
|
||||
log.Debug("client not connected, existing readloop...")
|
||||
return
|
||||
default:
|
||||
log.WithError(err).Warn("error reading inbox")
|
||||
}
|
||||
log.WithError(err).Warn("error reading inbox")
|
||||
} else {
|
||||
msgs <- msg
|
||||
}
|
||||
@ -258,6 +264,10 @@ func (cli *Client) Drain(ctx context.Context, extraenvs, prehook, posthook strin
|
||||
|
||||
// Read reads a single message from this user's inbox
|
||||
func (cli *Client) Read(extraenvs, prehook, posthook string) (Message, error) {
|
||||
if cli.me.Endpoint() == nil {
|
||||
return Message{}, ErrClientNotConnected
|
||||
}
|
||||
|
||||
uri, inbox := SplitInbox(cli.me.Endpoint().String())
|
||||
bus := msgbus_client.NewClient(uri, nil)
|
||||
|
||||
@ -274,6 +284,10 @@ func (cli *Client) Read(extraenvs, prehook, posthook string) (Message, error) {
|
||||
|
||||
// Subscribe subscribers to this user's inbox for new messages
|
||||
func (cli *Client) Subscribe(ctx context.Context, extraenvs, prehook, posthook string) chan Message {
|
||||
if cli.me.Endpoint() == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
uri, inbox := SplitInbox(cli.me.Endpoint().String())
|
||||
bus := msgbus_client.NewClient(uri, nil)
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:05a9a7d9f718e94879b364181f280a00b50ffa4f39f7ca42f5110ab6f19ab0cf
|
||||
size 26673697
|
||||
oid sha256:7075736b07e9bd858ff854adfd5ca2814c029875d1346a0f09a8946dc11dec41
|
||||
size 26695945
|
||||
|
Loading…
Reference in New Issue
Block a user