MCPcopy
hub / github.com/PeerDB-io/peerdb / GetErrorClass

Function GetErrorClass

flow/alerting/classifier.go:275–1194  ·  view source on GitHub ↗
(ctx context.Context, err error)

Source from the content-addressed store, hash-verified

273}
274
275func GetErrorClass(ctx context.Context, err error) (ErrorClass, ErrorInfo) {
276 var pgErr *pgconn.PgError
277 if pgWalErr, ok := errors.AsType[*exceptions.PostgresWalError](err); ok {
278 pgErr = pgconn.ErrorResponseToPgError(pgWalErr.UnderlyingError())
279 }
280 var pgErrorInfo ErrorInfo
281 if pgErrFromErr, ok := errors.AsType[*pgconn.PgError](err); pgErr != nil || ok {
282 if pgErr == nil {
283 pgErr = pgErrFromErr
284 }
285 pgErrorInfo = ErrorInfo{
286 Source: ErrorSourcePostgres,
287 Code: pgErr.Code,
288 }
289
290 if _, ok := errors.AsType[*exceptions.CatalogError](err); ok {
291 errorClass := ErrorInternal
292 if pgErr != nil {
293 return errorClass, pgErrorInfo
294 }
295 return errorClass, ErrorInfo{
296 Source: ErrorSourcePostgresCatalog,
297 Code: "UNKNOWN",
298 }
299 }
300
301 if _, ok := errors.AsType[*exceptions.DropFlowError](err); ok {
302 errorClass := ErrorDropFlow
303 if pgErr != nil {
304 return errorClass, pgErrorInfo
305 }
306 // For now we are not making it as verbose, will take this up later
307 return errorClass, ErrorInfo{
308 Source: ErrorSourceOther,
309 Code: "UNKNOWN",
310 }
311 }
312
313 if _, ok := errors.AsType[*exceptions.PostgresSetupError](err); ok {
314 errorClass := ErrorNotifyConnectivity
315 if pgErr != nil {
316 return errorClass, pgErrorInfo
317 }
318 return errorClass, ErrorInfo{
319 Source: ErrorSourcePostgres,
320 Code: "UNKNOWN",
321 }
322 }
323 }
324
325 if errors.Is(err, context.Canceled) {
326 // Generally happens during workflow cancellation
327 return ErrorIgnoreContextCancelled, ErrorInfo{
328 Source: ErrorSourceOther,
329 Code: "CONTEXT_CANCELLED",
330 }
331 }
332

Calls 4

UnderlyingErrorMethod · 0.80
WarnMethod · 0.80
ErrorMethod · 0.45
StringMethod · 0.45