-
Notifications
You must be signed in to change notification settings - Fork 292
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
indexers: update indexer error types. #2770
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2021 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
package indexers | ||
|
||
// ErrorKind identifies a kind of error. It has full support for errors.Is and | ||
// errors.As, so the caller can directly check against an error kind when | ||
// determining the reason for an error. | ||
type ErrorKind string | ||
|
||
// These constants are used to identify a specific IndexerError. | ||
const ( | ||
// ErrUnsupportedAddressType indicates an unsupported address type. | ||
ErrUnsupportedAddressType = ErrorKind("ErrUnsupportedAddressType") | ||
|
||
// ErrInvalidSpendConsumerType indicates an invalid spend consumer type. | ||
ErrInvalidSpendConsumerType = ErrorKind("ErrInvalidSpendConsumerType") | ||
|
||
// ErrConnectBlock indicates an error indexing a connected block. | ||
ErrConnectBlock = ErrorKind("ErrConnectBlock") | ||
|
||
// ErrDisconnectBlock indicates an error indexing a disconnected block. | ||
ErrDisconnectBlock = ErrorKind("ErrDisconnectBlock") | ||
|
||
// ErrRemoveSpendDependency indicates a spend dependency removal error. | ||
ErrRemoveSpendDependency = ErrorKind("ErrRemoveSpendDependency") | ||
|
||
// ErrInvalidNotificationType indicates an invalid indexer notification type. | ||
ErrInvalidNotificationType = ErrorKind("ErrInvalidNotificationType") | ||
|
||
// ErrInterruptRequested indicates an operation was cancelled due to | ||
// a user-requested interrupt. | ||
ErrInterruptRequested = ErrorKind("ErrInterruptRequested") | ||
|
||
// ErrFetchSubscription indicates an error fetching an index subscription. | ||
ErrFetchSubscription = ErrorKind("ErrFetchSubscription") | ||
|
||
// ErrFetchTip indicates an error fetching an index tip. | ||
ErrFetchTip = ErrorKind("ErrFetchTip") | ||
|
||
// ErrMissingNotification indicates a missing index notification. | ||
ErrMissingNotification = ErrorKind("ErrMissingNotification") | ||
|
||
// ErrBlockNotOnMainChain indicates the provided block is not on the | ||
// main chain. | ||
ErrBlockNotOnMainChain = ErrorKind("ErrBlockNotOnMainChain") | ||
) | ||
|
||
// Error satisfies the error interface and prints human-readable errors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also check with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deferring this for later if we decide it is better to be explicit about implementing the error interface throughout the codebase. |
||
func (e ErrorKind) Error() string { | ||
return string(e) | ||
} | ||
|
||
// IndexerError identifies an indexer error. It has full support for | ||
// errors.Is and errors.As, so the caller can ascertain the specific reason | ||
// for the error by checking the underlying error. | ||
type IndexerError struct { | ||
Description string | ||
Err error | ||
} | ||
|
||
// Error satisfies the error interface and prints human-readable errors. | ||
func (e IndexerError) Error() string { | ||
return e.Description | ||
} | ||
|
||
// Unwrap returns the underlying wrapped error. | ||
func (e IndexerError) Unwrap() error { | ||
return e.Err | ||
} | ||
|
||
// indexerError creates a IndexerError given a set of arguments. | ||
func indexerError(kind ErrorKind, desc string) IndexerError { | ||
return IndexerError{Err: kind, Description: desc} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if intended, but this changes the behavior to return rather than just log errors and the update tip below is no longer always called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's intended, if disconnecting a block fails for the index it'd be inaccurate to update its tip. Also to keep things synchronized, if removing a spend consumer dependency generates an error for an index it should return.