Documentation ¶
Overview ¶
Package errors provides the error package for Kusto. It wraps all errors for Kusto. No error should be generated that doesn't come from this package. This borrows heavily fron the Upspin errors paper written by Rob Pike. See: https://commandcenter.blogspot.com/2017/12/error-handling-in-upspin.html Key differences are that we support wrapped errors and the 1.13 Unwrap/Is/As additions to the go stdlib errors package and this is tailored for Kusto and not Upspin.
Usage is simply to pass an Op, a Kind, and either a standard error to be wrapped or string that will become a string error. See examples included in the file for more details.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Separator = ":\n\t"
Separator is the string used to separate nested errors. By default, to make errors easier on the eye, nested errors are indented on a new line. A server may instead choose to keep each error on a single line by modifying the separator string, perhaps to ":: ".
Functions ¶
Types ¶
type Error ¶
type Error struct { // Op is the operations that the client was trying to perform. Op Op // Kind is the error code we identify the error as. Kind Kind // Err is the error message. This may be of any error type and may also wrap errors. Err error // contains filtered or unexported fields }
Error is a core error for the Kusto package.
func E ¶
E constructs an Error. You may pass in an Op, Kind and error. This will strip a *errors.Error(the error in this package) if you pass one of its Kind and Op and wrap it in here. It will wrap a non-*Error implementation of error. If you want to wrap the *Error in an *Error, use W(). If you pass a nil error, it panics.
Example ¶
// Wrap a non-*Error type generated from other code. There should only ever be a single // non-typed error, as all errors in Kusto should be of type *Error. That underlying error // could be a wrapped error. err := E(OpQuery, KInternal, io.EOF) fmt.Println(err)
Output: Op(OpQuery): Kind(KInternal): EOF
func ES ¶
ES constructs an Error. You may pass in an Op, Kind, string and args to the string (like fmt.Sprintf). If the result of strings.TrimSpace(s+args) == "", it panics.
Example ¶
// Create a Kusto error holding an error string. err := ES(OpQuery, KInternal, "some type of client error") fmt.Println(err)
Output: Op(OpQuery): Kind(KInternal): some type of client error
func OneToErr ¶
OneToErr translates what we think is a Kusto OneApiError into an Error. If we don't recognize it, we return nil. This tries to wrap the internal errors, but the errors that are generated are some type of early draft of OneApiError, not the current spec. Because the errors we see don't conform to the current OneAPIError spec, had to take guesses on what we will receive. The spec says we shouldn't get a list of errors, but we do(we should get an embedded error). So I'm taking the guess that these are supposed to be wrapped errors.
func W ¶
W wraps error outer around inner. Both must be of type *Error or this will panic.
Example ¶
// Our inner *Error. err := E(OpQuery, KInternal, io.EOF) // Wrap an *Error in a *Error. Can only use an error type has a concrete type of *Error. // This wraps err inside the error generated by E(). err = W(err, ES(OpQuery, KTimeout, "database db does not exist")) fmt.Println(err) /* Output: Op(OpQuery): Kind(KTimeout): database db does not exist: EOF*/
Output: Op(OpQuery): Kind(KTimeout): database db does not exist: EOF
func (*Error) SetNoRetry ¶
SetNoRetry sets this error so that Retry() will always return false.
func (*Error) UnmarshalREST ¶
UnmarshalREST will unmarshal an error message from the server if the message is in JSON format or will return nil. This only occurs when the error is of Kind KHTTPError and the server responded with a JSON error.
type Kind ¶
type Kind uint16
Kind field classifies the error as one of a set of standard conditions.
const ( KOther Kind = 0 // Other indicates the error kind was not defined. KIO Kind = 1 // External I/O error such as network failure. KInternal Kind = 2 // Internal error or inconsistency at the server. KDBNotExist Kind = 3 // Database does not exist. KTimeout Kind = 4 // The request timed out. KLimitsExceeded Kind = 5 // The request was too large. KClientArgs Kind = 6 // The client supplied some type of arg(s) that were invalid. KHTTPError Kind = 7 // The HTTP client gave some type of error. This wraps the http library error types. KBlobstore Kind = 8 // The Blobstore API returned some type of error. KLocalFileSystem Kind = 9 // The local fileystem had an error. This could be permission, missing file, etc.... )
type Op ¶
type Op uint16
Op field denotes the operation being performed.
const ( OpUnknown Op = 0 // OpUnknown indicates that the operation that caused the problem is unknown. OpQuery Op = 1 // OpQuery indicates that a Query() call is being made. OpMgmt Op = 2 // OpMgmt indicates that a Mgmt() call is being made. OpServConn Op = 3 // OpServConn indicates that the client is attempting to connect to the service. OpIngestStream Op = 4 // OpIngestStream indicates the client is making a streaming ingestion call. OpFileIngest Op = 5 // OpFileIngest indicates the client is making a file ingestion call. )