Wrap returns an error that contains the given error and an error code derived from the given category, reason and the error. Currently, to avoid confusion, it is not allowed to create an error of category Success
(category Category, reason Reason, err error)
| 402 | // the given category, reason and the error. Currently, to avoid confusion, it is not |
| 403 | // allowed to create an error of category Success |
| 404 | func Wrap(category Category, reason Reason, err error) *Error { |
| 405 | errorCode := int(category) + int(reason) |
| 406 | if err == nil { |
| 407 | panic("Wrap needs a supplied error to initialize.") |
| 408 | } |
| 409 | |
| 410 | // do not double wrap a error |
| 411 | switch err.(type) { |
| 412 | case *Error: |
| 413 | panic("Unable to wrap a wrapped error.") |
| 414 | } |
| 415 | |
| 416 | switch category { |
| 417 | case CertificateError: |
| 418 | // given VerifyFailed , report the status with more detailed status code |
| 419 | // for some certificate errors we care. |
| 420 | if reason == VerifyFailed { |
| 421 | switch errorType := err.(type) { |
| 422 | case x509.CertificateInvalidError: |
| 423 | errorCode += certificateInvalid + int(errorType.Reason) |
| 424 | case x509.UnknownAuthorityError: |
| 425 | errorCode += unknownAuthority |
| 426 | } |
| 427 | } |
| 428 | case PrivateKeyError, IntermediatesError, RootError, PolicyError, DialError, |
| 429 | APIClientError, CSRError, CTError, CertStoreError, OCSPError: |
| 430 | // no-op, just use the error |
| 431 | default: |
| 432 | panic(fmt.Sprintf("Unsupported CFSSL error type: %d.", |
| 433 | category)) |
| 434 | } |
| 435 | |
| 436 | return &Error{ErrorCode: errorCode, Message: err.Error()} |
| 437 | |
| 438 | } |
searching dependent graphs…