Skip to content

Commit

Permalink
Improve error reporting [#3595]
Browse files Browse the repository at this point in the history
  • Loading branch information
firelizzard18 committed Apr 22, 2024
1 parent 2956b83 commit c34ed41
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
17 changes: 15 additions & 2 deletions pkg/api/v3/message/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,23 @@ func (c *RoutedTransport) dial(ctx context.Context, addr multiaddr.Multiaddr, st
return s, nil // Success
}

// Return the error if it's a client error (e.g. misdial)
var err2 *errors.Error
if errors.As(err, &err2) && err2.Code.IsClientError() {
return nil, errors.UnknownError.Wrap(err)
switch {
case err2.Code.IsClientError():
// Return the error if it's a client error (e.g. misdial)
return nil, errors.UnknownError.Wrap(err)

case err2.Code == errors.PeerMisbehaved:
// Find the cause of the misbehavior report
for err2.Cause != nil && err2.Code == errors.PeerMisbehaved {
err2 = err2.Cause
}

// If the error is an encoding issue, log it and return "internal error"
multi.BadDial(ctx, addr, s, err)
return nil, errors.InternalError.WithFormat("internal error: %w", err)
}
}

// Remove the stream from the dictionary
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/v3/p2p/dial/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,19 @@ func (d *dialer) Dial(ctx context.Context, addr multiaddr.Multiaddr) (stream mes
func (d *dialer) BadDial(ctx context.Context, addr multiaddr.Multiaddr, s message.Stream, err error) bool {
ss, ok := s.(*stream)
if !ok {
slog.InfoCtx(ctx, "Bad dial", "address", addr, "error", err)
return false
}

slog.InfoCtx(ctx, "Bad dial", "peer", ss.peer, "address", addr, "error", err)

var err2 *errors.Error
if errors.As(err, &err2) && err2.Code == errors.EncodingError {
// Don't mark a peer bad if there's an encoding failure. Is this a good
// idea?
return false
}

d.tracker.Mark(ss.peer, addr, api.PeerStatusIsKnownBad)
return true
}
Expand Down
8 changes: 0 additions & 8 deletions scripts/debug-in-docker.sh

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/delve-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

SCRIPT="dlv attach 1 --headless --listen=:2345 --accept-multiclient --api-version=2"

docker exec --privileged -it "$1" bash -c "$SCRIPT"

0 comments on commit c34ed41

Please sign in to comment.