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

Creat a Fail-To_Bid error #636

Merged
merged 2 commits into from
Aug 2, 2018
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
18 changes: 18 additions & 0 deletions errortypes/errortypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const (
TimeoutCode
BadInputCode
BadServerResponseCode
FailedToRequestBidsCode
)

// We should use this code for any Error interface that is not in this package
Expand Down Expand Up @@ -70,6 +71,23 @@ func (err *BadServerResponse) Code() int {
return BadServerResponseCode
}

// FailedToRequestBids is an error to cover the case where an adapter failed to generate any http requests to get bids,
// but did not generate any error messages. This should not happen in practice and will signal that an adapter is poorly
// coded. If there was something wrong with a request such that an adapter could not generate a bid, then it should
// generate an error explaining the deficiency. Otherwise it will be extremely difficult to debug the reason why an
// adapter is not bidding.
type FailedToRequestBids struct {
Message string
}

func (err *FailedToRequestBids) Error() string {
return err.Message
}

func (err *FailedToRequestBids) Code() int {
return FailedToRequestBidsCode
}

// DecodeError provides the error code for an error, as defined above
func DecodeError(err error) int {
if ce, ok := err.(Coder); ok {
Expand Down
4 changes: 4 additions & 0 deletions exchange/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (bidder *bidderAdapter) requestBid(ctx context.Context, request *openrtb.Bi
reqData, errs := bidder.Bidder.MakeRequests(request)

if len(reqData) == 0 {
// If the adapter failed to generate both requests and errors, this is an error.
if len(errs) == 0 {
errs = append(errs, &errortypes.FailedToRequestBids{Message: "The adapter failed to generate any bid requests, but also failed to generate an error explaining why"})
}
return nil, errs
}

Expand Down
2 changes: 2 additions & 0 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ func errorsToMetric(errs []error) map[pbsmetrics.AdapterError]struct{} {
ret[pbsmetrics.AdapterErrorBadInput] = s
case errortypes.BadServerResponseCode:
ret[pbsmetrics.AdapterErrorBadServerResponse] = s
case errortypes.FailedToRequestBidsCode:
ret[pbsmetrics.AdapterErrorFailedToRequestBids] = s
default:
ret[pbsmetrics.AdapterErrorUnknown] = s
}
Expand Down
10 changes: 6 additions & 4 deletions pbsmetrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,19 @@ func AdapterBids() []AdapterBid {

// Adapter execution status
const (
AdapterErrorBadInput AdapterError = "badinput"
AdapterErrorBadServerResponse AdapterError = "badserverresponse"
AdapterErrorTimeout AdapterError = "timeout"
AdapterErrorUnknown AdapterError = "unknown_error"
AdapterErrorBadInput AdapterError = "badinput"
AdapterErrorBadServerResponse AdapterError = "badserverresponse"
AdapterErrorTimeout AdapterError = "timeout"
AdapterErrorFailedToRequestBids AdapterError = "failedtorequestbid"
AdapterErrorUnknown AdapterError = "unknown_error"
)

func AdapterErrors() []AdapterError {
return []AdapterError{
AdapterErrorBadInput,
AdapterErrorBadServerResponse,
AdapterErrorTimeout,
AdapterErrorFailedToRequestBids,
AdapterErrorUnknown,
}
}
Expand Down