Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more descriptive error messages in model proxy #1320

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading