Skip to content

Commit

Permalink
use more descriptive error messages in model proxy (#1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
kian99 authored Aug 22, 2024
1 parent 970ec0c commit 8480f90
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func TestProxySockets(t *testing.T) {
LoginService: &mockLoginService{},
}
err := rpc.ProxySockets(ctx, proxyHelpers)
c.Check(err, qt.ErrorMatches, ".*use of closed network connection")
c.Check(err, qt.ErrorMatches, "error reading from (client|controller).*")
errChan <- err
return err
})
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestProxySocketsAuditLogs(t *testing.T) {
LoginService: &mockLoginService{},
}
err := rpc.ProxySockets(ctx, proxyHelpers)
c.Check(err, qt.ErrorMatches, ".*use of closed network connection")
c.Check(err, qt.ErrorMatches, `error reading from (client|controller).*`)
errChan <- err
return err
})
Expand Down
11 changes: 6 additions & 5 deletions internal/rpc/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -339,14 +340,14 @@ func (p *clientProxy) start(ctx context.Context) error {
msg := new(message)
if err := p.src.readJson(&msg); err != nil {
// Error reading on the socket implies it is closed, simply return.
return err
return fmt.Errorf("error reading from client: %w", err)
}
zapctx.Debug(ctx, "Read message from client", zap.Any("message", msg))
err := p.makeControllerConnection(ctx)
if err != nil {
zapctx.Error(ctx, "error connecting to controller", zap.Error(err))
p.sendError(p.src, msg, err)
return err
return fmt.Errorf("failed to connect to controller: %w", err)
}
if err := p.auditLogMessage(msg, false); err != nil {
zapctx.Error(ctx, "failed to audit log message", zap.Error(err))
Expand Down Expand Up @@ -438,7 +439,7 @@ func (p *controllerProxy) start(ctx context.Context) error {
msg := new(message)
if err := p.src.readJson(msg); err != nil {
// Error reading on the socket implies it is closed, simply return.
return err
return fmt.Errorf("error reading from controller: %w", err)
}
zapctx.Debug(ctx, "Received message from controller", zap.Any("Message", msg))
permissionsRequired, err := checkPermissionsRequired(ctx, msg)
Expand Down Expand Up @@ -467,7 +468,7 @@ func (p *controllerProxy) start(ctx context.Context) error {
zapctx.Error(ctx, "Failed to modify message", zap.Error(err))
p.handleError(msg, err)
// An error when modifying the message is a show stopper.
return err
return fmt.Errorf("error modifying controller response: %w", err)
}
}
p.msgs.removeMessage(msg.RequestID)
Expand All @@ -477,7 +478,7 @@ func (p *controllerProxy) start(ctx context.Context) error {
zapctx.Debug(ctx, "Writing modified message to client", zap.Any("Message", msg))
if err := p.dst.writeJson(msg); err != nil {
zapctx.Error(ctx, "controllerProxy error writing to dst", zap.Error(err))
return err
return fmt.Errorf("error writing message to client: %w", err)
}
}
}
Expand Down

0 comments on commit 8480f90

Please sign in to comment.