diff --git a/access_application.go b/access_application.go index 8b5afd6aed6..aaa94d20ecc 100644 --- a/access_application.go +++ b/access_application.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // AccessApplicationType represents the application type. @@ -137,7 +135,7 @@ func (api *API) accessApplications(ctx context.Context, id string, pageOpts Pagi var accessApplicationListResponse AccessApplicationListResponse err = json.Unmarshal(res, &accessApplicationListResponse) if err != nil { - return []AccessApplication{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []AccessApplication{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessApplicationListResponse.Result, accessApplicationListResponse.ResultInfo, nil @@ -175,7 +173,7 @@ func (api *API) accessApplication(ctx context.Context, id, applicationID string, var accessApplicationDetailResponse AccessApplicationDetailResponse err = json.Unmarshal(res, &accessApplicationDetailResponse) if err != nil { - return AccessApplication{}, errors.Wrap(err, errUnmarshalError) + return AccessApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessApplicationDetailResponse.Result, nil @@ -206,7 +204,7 @@ func (api *API) createAccessApplication(ctx context.Context, id string, accessAp var accessApplicationDetailResponse AccessApplicationDetailResponse err = json.Unmarshal(res, &accessApplicationDetailResponse) if err != nil { - return AccessApplication{}, errors.Wrap(err, errUnmarshalError) + return AccessApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessApplicationDetailResponse.Result, nil @@ -228,7 +226,7 @@ func (api *API) UpdateZoneLevelAccessApplication(ctx context.Context, zoneID str func (api *API) updateAccessApplication(ctx context.Context, id string, accessApplication AccessApplication, routeRoot RouteRoot) (AccessApplication, error) { if accessApplication.ID == "" { - return AccessApplication{}, errors.Errorf("access application ID cannot be empty") + return AccessApplication{}, fmt.Errorf("access application ID cannot be empty") } uri := fmt.Sprintf( @@ -246,7 +244,7 @@ func (api *API) updateAccessApplication(ctx context.Context, id string, accessAp var accessApplicationDetailResponse AccessApplicationDetailResponse err = json.Unmarshal(res, &accessApplicationDetailResponse) if err != nil { - return AccessApplication{}, errors.Wrap(err, errUnmarshalError) + return AccessApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessApplicationDetailResponse.Result, nil diff --git a/access_audit_log.go b/access_audit_log.go index af67b72cc4d..1627914d834 100644 --- a/access_audit_log.go +++ b/access_audit_log.go @@ -8,8 +8,6 @@ import ( "net/url" "strconv" "time" - - "github.com/pkg/errors" ) // AccessAuditLogRecord is the structure of a single Access Audit Log entry. @@ -56,7 +54,7 @@ func (api *API) AccessAuditLogs(ctx context.Context, accountID string, opts Acce var accessAuditLogListResponse AccessAuditLogListResponse err = json.Unmarshal(res, &accessAuditLogListResponse) if err != nil { - return []AccessAuditLogRecord{}, errors.Wrap(err, errUnmarshalError) + return []AccessAuditLogRecord{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessAuditLogListResponse.Result, nil diff --git a/access_bookmark.go b/access_bookmark.go index 8ebf4603c67..12b7ce06031 100644 --- a/access_bookmark.go +++ b/access_bookmark.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // AccessBookmark represents an Access bookmark application. @@ -61,7 +59,7 @@ func (api *API) accessBookmarks(ctx context.Context, id string, pageOpts Paginat var accessBookmarkListResponse AccessBookmarkListResponse err = json.Unmarshal(res, &accessBookmarkListResponse) if err != nil { - return []AccessBookmark{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []AccessBookmark{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessBookmarkListResponse.Result, accessBookmarkListResponse.ResultInfo, nil @@ -99,7 +97,7 @@ func (api *API) accessBookmark(ctx context.Context, id, bookmarkID string, route var accessBookmarkDetailResponse AccessBookmarkDetailResponse err = json.Unmarshal(res, &accessBookmarkDetailResponse) if err != nil { - return AccessBookmark{}, errors.Wrap(err, errUnmarshalError) + return AccessBookmark{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessBookmarkDetailResponse.Result, nil @@ -130,7 +128,7 @@ func (api *API) createAccessBookmark(ctx context.Context, id string, accessBookm var accessBookmarkDetailResponse AccessBookmarkDetailResponse err = json.Unmarshal(res, &accessBookmarkDetailResponse) if err != nil { - return AccessBookmark{}, errors.Wrap(err, errUnmarshalError) + return AccessBookmark{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessBookmarkDetailResponse.Result, nil @@ -152,7 +150,7 @@ func (api *API) UpdateZoneLevelAccessBookmark(ctx context.Context, zoneID string func (api *API) updateAccessBookmark(ctx context.Context, id string, accessBookmark AccessBookmark, routeRoot RouteRoot) (AccessBookmark, error) { if accessBookmark.ID == "" { - return AccessBookmark{}, errors.Errorf("access bookmark ID cannot be empty") + return AccessBookmark{}, fmt.Errorf("access bookmark ID cannot be empty") } uri := fmt.Sprintf( @@ -170,7 +168,7 @@ func (api *API) updateAccessBookmark(ctx context.Context, id string, accessBookm var accessBookmarkDetailResponse AccessBookmarkDetailResponse err = json.Unmarshal(res, &accessBookmarkDetailResponse) if err != nil { - return AccessBookmark{}, errors.Wrap(err, errUnmarshalError) + return AccessBookmark{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessBookmarkDetailResponse.Result, nil diff --git a/access_ca_certificate.go b/access_ca_certificate.go index d19765bc2ae..1845bdb332a 100644 --- a/access_ca_certificate.go +++ b/access_ca_certificate.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // AccessCACertificate is the structure of the CA certificate used for @@ -56,7 +54,7 @@ func (api *API) accessCACertificates(ctx context.Context, id string, routeRoot R var accessCAListResponse AccessCACertificateListResponse err = json.Unmarshal(res, &accessCAListResponse) if err != nil { - return []AccessCACertificate{}, errors.Wrap(err, errUnmarshalError) + return []AccessCACertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessCAListResponse.Result, nil @@ -89,7 +87,7 @@ func (api *API) accessCACertificate(ctx context.Context, id, applicationID strin var accessCAResponse AccessCACertificateResponse err = json.Unmarshal(res, &accessCAResponse) if err != nil { - return AccessCACertificate{}, errors.Wrap(err, errUnmarshalError) + return AccessCACertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessCAResponse.Result, nil @@ -127,7 +125,7 @@ func (api *API) createAccessCACertificate(ctx context.Context, id string, applic var accessCACertificate AccessCACertificateResponse err = json.Unmarshal(res, &accessCACertificate) if err != nil { - return AccessCACertificate{}, errors.Wrap(err, errUnmarshalError) + return AccessCACertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessCACertificate.Result, nil diff --git a/access_group.go b/access_group.go index bcdbaeb0142..9527e57092f 100644 --- a/access_group.go +++ b/access_group.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // AccessGroup defines a group for allowing or disallowing access to @@ -237,7 +235,7 @@ func (api *API) accessGroups(ctx context.Context, id string, pageOpts Pagination var accessGroupListResponse AccessGroupListResponse err = json.Unmarshal(res, &accessGroupListResponse) if err != nil { - return []AccessGroup{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []AccessGroup{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessGroupListResponse.Result, accessGroupListResponse.ResultInfo, nil @@ -273,7 +271,7 @@ func (api *API) accessGroup(ctx context.Context, id, groupID string, routeRoot R var accessGroupDetailResponse AccessGroupDetailResponse err = json.Unmarshal(res, &accessGroupDetailResponse) if err != nil { - return AccessGroup{}, errors.Wrap(err, errUnmarshalError) + return AccessGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessGroupDetailResponse.Result, nil @@ -308,7 +306,7 @@ func (api *API) createAccessGroup(ctx context.Context, id string, accessGroup Ac var accessGroupDetailResponse AccessGroupDetailResponse err = json.Unmarshal(res, &accessGroupDetailResponse) if err != nil { - return AccessGroup{}, errors.Wrap(err, errUnmarshalError) + return AccessGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessGroupDetailResponse.Result, nil @@ -330,7 +328,7 @@ func (api *API) UpdateZoneLevelAccessGroup(ctx context.Context, zoneID string, a func (api *API) updateAccessGroup(ctx context.Context, id string, accessGroup AccessGroup, routeRoot RouteRoot) (AccessGroup, error) { if accessGroup.ID == "" { - return AccessGroup{}, errors.Errorf("access group ID cannot be empty") + return AccessGroup{}, fmt.Errorf("access group ID cannot be empty") } uri := fmt.Sprintf( @@ -348,7 +346,7 @@ func (api *API) updateAccessGroup(ctx context.Context, id string, accessGroup Ac var accessGroupDetailResponse AccessGroupDetailResponse err = json.Unmarshal(res, &accessGroupDetailResponse) if err != nil { - return AccessGroup{}, errors.Wrap(err, errUnmarshalError) + return AccessGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessGroupDetailResponse.Result, nil diff --git a/access_identity_provider.go b/access_identity_provider.go index 5ee4563edfa..fb986b4b232 100644 --- a/access_identity_provider.go +++ b/access_identity_provider.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // AccessIdentityProvider is the structure of the provider object. @@ -87,7 +85,7 @@ func (api *API) accessIdentityProviders(ctx context.Context, id string, routeRoo var accessIdentityProviderResponse AccessIdentityProvidersListResponse err = json.Unmarshal(res, &accessIdentityProviderResponse) if err != nil { - return []AccessIdentityProvider{}, errors.Wrap(err, errUnmarshalError) + return []AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessIdentityProviderResponse.Result, nil @@ -125,7 +123,7 @@ func (api *API) accessIdentityProviderDetails(ctx context.Context, id string, id var accessIdentityProviderResponse AccessIdentityProviderListResponse err = json.Unmarshal(res, &accessIdentityProviderResponse) if err != nil { - return AccessIdentityProvider{}, errors.Wrap(err, errUnmarshalError) + return AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessIdentityProviderResponse.Result, nil @@ -156,7 +154,7 @@ func (api *API) createAccessIdentityProvider(ctx context.Context, id string, ide var accessIdentityProviderResponse AccessIdentityProviderListResponse err = json.Unmarshal(res, &accessIdentityProviderResponse) if err != nil { - return AccessIdentityProvider{}, errors.Wrap(err, errUnmarshalError) + return AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessIdentityProviderResponse.Result, nil @@ -194,7 +192,7 @@ func (api *API) updateAccessIdentityProvider(ctx context.Context, id string, ide var accessIdentityProviderResponse AccessIdentityProviderListResponse err = json.Unmarshal(res, &accessIdentityProviderResponse) if err != nil { - return AccessIdentityProvider{}, errors.Wrap(err, errUnmarshalError) + return AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessIdentityProviderResponse.Result, nil @@ -230,7 +228,7 @@ func (api *API) deleteAccessIdentityProvider(ctx context.Context, id string, ide var accessIdentityProviderResponse AccessIdentityProviderListResponse err = json.Unmarshal(res, &accessIdentityProviderResponse) if err != nil { - return AccessIdentityProvider{}, errors.Wrap(err, errUnmarshalError) + return AccessIdentityProvider{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessIdentityProviderResponse.Result, nil diff --git a/access_keys.go b/access_keys.go index 1816dc6c5af..2edca03e67f 100644 --- a/access_keys.go +++ b/access_keys.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/pkg/errors" "net/http" "time" ) @@ -58,7 +57,7 @@ func (api *API) accessKeysRequest(ctx context.Context, method, uri string, param var keysConfigResponse accessKeysConfigResponse if err := json.Unmarshal(res, &keysConfigResponse); err != nil { - return AccessKeysConfig{}, errors.Wrap(err, errUnmarshalError) + return AccessKeysConfig{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return keysConfigResponse.Result, nil } diff --git a/access_mutual_tls_certificates.go b/access_mutual_tls_certificates.go index 007ddef21e8..af1eef535e6 100644 --- a/access_mutual_tls_certificates.go +++ b/access_mutual_tls_certificates.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // AccessMutualTLSCertificate is the structure of a single Access Mutual TLS @@ -68,7 +66,7 @@ func (api *API) accessMutualTLSCertificates(ctx context.Context, id string, rout var accessMutualTLSCertificateListResponse AccessMutualTLSCertificateListResponse err = json.Unmarshal(res, &accessMutualTLSCertificateListResponse) if err != nil { - return []AccessMutualTLSCertificate{}, errors.Wrap(err, errUnmarshalError) + return []AccessMutualTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessMutualTLSCertificateListResponse.Result, nil @@ -106,7 +104,7 @@ func (api *API) accessMutualTLSCertificate(ctx context.Context, id, certificateI var accessMutualTLSCertificateDetailResponse AccessMutualTLSCertificateDetailResponse err = json.Unmarshal(res, &accessMutualTLSCertificateDetailResponse) if err != nil { - return AccessMutualTLSCertificate{}, errors.Wrap(err, errUnmarshalError) + return AccessMutualTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessMutualTLSCertificateDetailResponse.Result, nil @@ -143,7 +141,7 @@ func (api *API) createAccessMutualTLSCertificate(ctx context.Context, id string, var accessMutualTLSCertificateDetailResponse AccessMutualTLSCertificateDetailResponse err = json.Unmarshal(res, &accessMutualTLSCertificateDetailResponse) if err != nil { - return AccessMutualTLSCertificate{}, errors.Wrap(err, errUnmarshalError) + return AccessMutualTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessMutualTLSCertificateDetailResponse.Result, nil @@ -181,7 +179,7 @@ func (api *API) updateAccessMutualTLSCertificate(ctx context.Context, id string, var accessMutualTLSCertificateDetailResponse AccessMutualTLSCertificateDetailResponse err = json.Unmarshal(res, &accessMutualTLSCertificateDetailResponse) if err != nil { - return AccessMutualTLSCertificate{}, errors.Wrap(err, errUnmarshalError) + return AccessMutualTLSCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessMutualTLSCertificateDetailResponse.Result, nil @@ -219,7 +217,7 @@ func (api *API) deleteAccessMutualTLSCertificate(ctx context.Context, id, certif var accessMutualTLSCertificateDetailResponse AccessMutualTLSCertificateDetailResponse err = json.Unmarshal(res, &accessMutualTLSCertificateDetailResponse) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil diff --git a/access_organization.go b/access_organization.go index a0ec7ff15f1..48a3d285653 100644 --- a/access_organization.go +++ b/access_organization.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // AccessOrganization represents an Access organization. @@ -70,7 +68,7 @@ func (api *API) accessOrganization(ctx context.Context, id string, routeRoot Rou var accessOrganizationListResponse AccessOrganizationListResponse err = json.Unmarshal(res, &accessOrganizationListResponse) if err != nil { - return AccessOrganization{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return AccessOrganization{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessOrganizationListResponse.Result, accessOrganizationListResponse.ResultInfo, nil @@ -101,7 +99,7 @@ func (api *API) createAccessOrganization(ctx context.Context, id string, accessO var accessOrganizationDetailResponse AccessOrganizationDetailResponse err = json.Unmarshal(res, &accessOrganizationDetailResponse) if err != nil { - return AccessOrganization{}, errors.Wrap(err, errUnmarshalError) + return AccessOrganization{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessOrganizationDetailResponse.Result, nil @@ -132,7 +130,7 @@ func (api *API) updateAccessOrganization(ctx context.Context, id string, accessO var accessOrganizationDetailResponse AccessOrganizationDetailResponse err = json.Unmarshal(res, &accessOrganizationDetailResponse) if err != nil { - return AccessOrganization{}, errors.Wrap(err, errUnmarshalError) + return AccessOrganization{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessOrganizationDetailResponse.Result, nil diff --git a/access_policy.go b/access_policy.go index 82718c1bcfd..abbbaf42d54 100644 --- a/access_policy.go +++ b/access_policy.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) type AccessApprovalGroup struct { @@ -94,7 +92,7 @@ func (api *API) accessPolicies(ctx context.Context, id string, applicationID str var accessPolicyListResponse AccessPolicyListResponse err = json.Unmarshal(res, &accessPolicyListResponse) if err != nil { - return []AccessPolicy{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []AccessPolicy{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessPolicyListResponse.Result, accessPolicyListResponse.ResultInfo, nil @@ -131,7 +129,7 @@ func (api *API) accessPolicy(ctx context.Context, id string, applicationID strin var accessPolicyDetailResponse AccessPolicyDetailResponse err = json.Unmarshal(res, &accessPolicyDetailResponse) if err != nil { - return AccessPolicy{}, errors.Wrap(err, errUnmarshalError) + return AccessPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessPolicyDetailResponse.Result, nil @@ -167,7 +165,7 @@ func (api *API) createAccessPolicy(ctx context.Context, id, applicationID string var accessPolicyDetailResponse AccessPolicyDetailResponse err = json.Unmarshal(res, &accessPolicyDetailResponse) if err != nil { - return AccessPolicy{}, errors.Wrap(err, errUnmarshalError) + return AccessPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessPolicyDetailResponse.Result, nil @@ -189,7 +187,7 @@ func (api *API) UpdateZoneLevelAccessPolicy(ctx context.Context, zoneID, applica func (api *API) updateAccessPolicy(ctx context.Context, id, applicationID string, accessPolicy AccessPolicy, routeRoot RouteRoot) (AccessPolicy, error) { if accessPolicy.ID == "" { - return AccessPolicy{}, errors.Errorf("access policy ID cannot be empty") + return AccessPolicy{}, fmt.Errorf("access policy ID cannot be empty") } uri := fmt.Sprintf( "/%s/%s/access/apps/%s/policies/%s", @@ -207,7 +205,7 @@ func (api *API) updateAccessPolicy(ctx context.Context, id, applicationID string var accessPolicyDetailResponse AccessPolicyDetailResponse err = json.Unmarshal(res, &accessPolicyDetailResponse) if err != nil { - return AccessPolicy{}, errors.Wrap(err, errUnmarshalError) + return AccessPolicy{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessPolicyDetailResponse.Result, nil diff --git a/access_service_tokens.go b/access_service_tokens.go index 110c1dbed48..fec466cb996 100644 --- a/access_service_tokens.go +++ b/access_service_tokens.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // AccessServiceToken represents an Access Service Token. @@ -105,7 +103,7 @@ func (api *API) accessServiceTokens(ctx context.Context, id string, routeRoot Ro var accessServiceTokensListResponse AccessServiceTokensListResponse err = json.Unmarshal(res, &accessServiceTokensListResponse) if err != nil { - return []AccessServiceToken{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []AccessServiceToken{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessServiceTokensListResponse.Result, accessServiceTokensListResponse.ResultInfo, nil @@ -140,7 +138,7 @@ func (api *API) createAccessServiceToken(ctx context.Context, id, name string, r var accessServiceTokenCreation AccessServiceTokensCreationDetailResponse err = json.Unmarshal(res, &accessServiceTokenCreation) if err != nil { - return AccessServiceTokenCreateResponse{}, errors.Wrap(err, errUnmarshalError) + return AccessServiceTokenCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessServiceTokenCreation.Result, nil @@ -177,7 +175,7 @@ func (api *API) updateAccessServiceToken(ctx context.Context, id, uuid, name str var accessServiceTokenUpdate AccessServiceTokensUpdateDetailResponse err = json.Unmarshal(res, &accessServiceTokenUpdate) if err != nil { - return AccessServiceTokenUpdateResponse{}, errors.Wrap(err, errUnmarshalError) + return AccessServiceTokenUpdateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessServiceTokenUpdate.Result, nil @@ -210,7 +208,7 @@ func (api *API) deleteAccessServiceToken(ctx context.Context, id, uuid string, r var accessServiceTokenUpdate AccessServiceTokensUpdateDetailResponse err = json.Unmarshal(res, &accessServiceTokenUpdate) if err != nil { - return AccessServiceTokenUpdateResponse{}, errors.Wrap(err, errUnmarshalError) + return AccessServiceTokenUpdateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accessServiceTokenUpdate.Result, nil diff --git a/access_user_tokens_test.go b/access_user_tokens_test.go index f69e7d9fe0f..c1cb268c9f3 100644 --- a/access_user_tokens_test.go +++ b/access_user_tokens_test.go @@ -3,9 +3,10 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" "net/http" "testing" + + "github.com/stretchr/testify/assert" ) func TestRevokeAccessUserTokens(t *testing.T) { diff --git a/account_members.go b/account_members.go index 7f0f5cbba20..052bcf54a60 100644 --- a/account_members.go +++ b/account_members.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // AccountMember is the definition of a member of an account. @@ -58,7 +56,7 @@ type AccountMemberInvitation struct { // API reference: https://api.cloudflare.com/#accounts-list-accounts func (api *API) AccountMembers(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]AccountMember, ResultInfo, error) { if accountID == "" { - return []AccountMember{}, ResultInfo{}, errors.New(errMissingAccountID) + return []AccountMember{}, ResultInfo{}, ErrMissingAccountID } uri := buildURI(fmt.Sprintf("/accounts/%s/members", accountID), pageOpts) @@ -71,7 +69,7 @@ func (api *API) AccountMembers(ctx context.Context, accountID string, pageOpts P var accountMemberListresponse AccountMembersListResponse err = json.Unmarshal(res, &accountMemberListresponse) if err != nil { - return []AccountMember{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []AccountMember{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accountMemberListresponse.Result, accountMemberListresponse.ResultInfo, nil @@ -84,7 +82,7 @@ func (api *API) AccountMembers(ctx context.Context, accountID string, pageOpts P // API reference: https://api.cloudflare.com/#account-members-add-member func (api *API) CreateAccountMemberWithStatus(ctx context.Context, accountID string, emailAddress string, roles []string, status string) (AccountMember, error) { if accountID == "" { - return AccountMember{}, errors.New(errMissingAccountID) + return AccountMember{}, ErrMissingAccountID } uri := fmt.Sprintf("/accounts/%s/members", accountID) @@ -102,7 +100,7 @@ func (api *API) CreateAccountMemberWithStatus(ctx context.Context, accountID str var accountMemberListResponse AccountMemberDetailResponse err = json.Unmarshal(res, &accountMemberListResponse) if err != nil { - return AccountMember{}, errors.Wrap(err, errUnmarshalError) + return AccountMember{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accountMemberListResponse.Result, nil @@ -121,7 +119,7 @@ func (api *API) CreateAccountMember(ctx context.Context, accountID string, email // API reference: https://api.cloudflare.com/#account-members-remove-member func (api *API) DeleteAccountMember(ctx context.Context, accountID string, userID string) error { if accountID == "" { - return errors.New(errMissingAccountID) + return ErrMissingAccountID } uri := fmt.Sprintf("/accounts/%s/members/%s", accountID, userID) @@ -139,7 +137,7 @@ func (api *API) DeleteAccountMember(ctx context.Context, accountID string, userI // API reference: https://api.cloudflare.com/#account-members-update-member func (api *API) UpdateAccountMember(ctx context.Context, accountID string, userID string, member AccountMember) (AccountMember, error) { if accountID == "" { - return AccountMember{}, errors.New(errMissingAccountID) + return AccountMember{}, ErrMissingAccountID } uri := fmt.Sprintf("/accounts/%s/members/%s", accountID, userID) @@ -152,7 +150,7 @@ func (api *API) UpdateAccountMember(ctx context.Context, accountID string, userI var accountMemberListResponse AccountMemberDetailResponse err = json.Unmarshal(res, &accountMemberListResponse) if err != nil { - return AccountMember{}, errors.Wrap(err, errUnmarshalError) + return AccountMember{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accountMemberListResponse.Result, nil @@ -163,7 +161,7 @@ func (api *API) UpdateAccountMember(ctx context.Context, accountID string, userI // API reference: https://api.cloudflare.com/#account-members-member-details func (api *API) AccountMember(ctx context.Context, accountID string, memberID string) (AccountMember, error) { if accountID == "" { - return AccountMember{}, errors.New(errMissingAccountID) + return AccountMember{}, ErrMissingAccountID } uri := fmt.Sprintf( @@ -180,7 +178,7 @@ func (api *API) AccountMember(ctx context.Context, accountID string, memberID st var accountMemberResponse AccountMemberDetailResponse err = json.Unmarshal(res, &accountMemberResponse) if err != nil { - return AccountMember{}, errors.Wrap(err, errUnmarshalError) + return AccountMember{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accountMemberResponse.Result, nil diff --git a/account_roles.go b/account_roles.go index ea1582e7050..2f51b3731b2 100644 --- a/account_roles.go +++ b/account_roles.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // AccountRole defines the roles that a member can have attached. @@ -55,7 +53,7 @@ func (api *API) AccountRoles(ctx context.Context, accountID string) ([]AccountRo var accountRolesListResponse AccountRolesListResponse err = json.Unmarshal(res, &accountRolesListResponse) if err != nil { - return []AccountRole{}, errors.Wrap(err, errUnmarshalError) + return []AccountRole{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accountRolesListResponse.Result, nil @@ -75,7 +73,7 @@ func (api *API) AccountRole(ctx context.Context, accountID string, roleID string var accountRole AccountRoleDetailResponse err = json.Unmarshal(res, &accountRole) if err != nil { - return AccountRole{}, errors.Wrap(err, errUnmarshalError) + return AccountRole{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accountRole.Result, nil diff --git a/accounts.go b/accounts.go index 6e5b161089a..7cca6e7b8c8 100644 --- a/accounts.go +++ b/accounts.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // AccountSettings outlines the available options for an account. @@ -66,7 +64,7 @@ func (api *API) Accounts(ctx context.Context, params AccountsListParams) ([]Acco var accListResponse AccountListResponse err = json.Unmarshal(res, &accListResponse) if err != nil { - return []Account{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []Account{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accListResponse.Result, accListResponse.ResultInfo, nil } @@ -85,7 +83,7 @@ func (api *API) Account(ctx context.Context, accountID string) (Account, ResultI var accResponse AccountResponse err = json.Unmarshal(res, &accResponse) if err != nil { - return Account{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return Account{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return accResponse.Result, accResponse.ResultInfo, nil @@ -105,7 +103,7 @@ func (api *API) UpdateAccount(ctx context.Context, accountID string, account Acc var a AccountDetailResponse err = json.Unmarshal(res, &a) if err != nil { - return Account{}, errors.Wrap(err, errUnmarshalError) + return Account{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return a.Result, nil @@ -126,7 +124,7 @@ func (api *API) CreateAccount(ctx context.Context, account Account) (Account, er var a AccountDetailResponse err = json.Unmarshal(res, &a) if err != nil { - return Account{}, errors.Wrap(err, errUnmarshalError) + return Account{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return a.Result, nil @@ -138,7 +136,7 @@ func (api *API) CreateAccount(ctx context.Context, account Account) (Account, er // API reference: https://developers.cloudflare.com/tenant/tutorial/provisioning-resources#optional-deleting-accounts func (api *API) DeleteAccount(ctx context.Context, accountID string) error { if accountID == "" { - return errors.New(errMissingAccountID) + return ErrMissingAccountID } uri := fmt.Sprintf("/accounts/%s", accountID) diff --git a/api_token.go b/api_token.go index a028a0d8cc1..41bd85db3a5 100644 --- a/api_token.go +++ b/api_token.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // APIToken is the full API token. @@ -105,7 +103,7 @@ func (api *API) GetAPIToken(ctx context.Context, tokenID string) (APIToken, erro var apiTokenResponse APITokenResponse err = json.Unmarshal(res, &apiTokenResponse) if err != nil { - return APIToken{}, errors.Wrap(err, errUnmarshalError) + return APIToken{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return apiTokenResponse.Result, nil @@ -123,7 +121,7 @@ func (api *API) APITokens(ctx context.Context) ([]APIToken, error) { var apiTokenListResponse APITokenListResponse err = json.Unmarshal(res, &apiTokenListResponse) if err != nil { - return []APIToken{}, errors.Wrap(err, errUnmarshalError) + return []APIToken{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return apiTokenListResponse.Result, nil @@ -146,7 +144,7 @@ func (api *API) CreateAPIToken(ctx context.Context, token APIToken) (APIToken, e var createTokenAPIResponse APITokenResponse err = json.Unmarshal(res, &createTokenAPIResponse) if err != nil { - return APIToken{}, errors.Wrap(err, errUnmarshalError) + return APIToken{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return createTokenAPIResponse.Result, nil @@ -164,7 +162,7 @@ func (api *API) UpdateAPIToken(ctx context.Context, tokenID string, token APITok var updatedTokenResponse APITokenResponse err = json.Unmarshal(res, &updatedTokenResponse) if err != nil { - return APIToken{}, errors.Wrap(err, errUnmarshalError) + return APIToken{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return updatedTokenResponse.Result, nil @@ -184,7 +182,7 @@ func (api *API) RollAPIToken(ctx context.Context, tokenID string) (string, error var apiTokenRollResponse APITokenRollResponse err = json.Unmarshal(res, &apiTokenRollResponse) if err != nil { - return "", errors.Wrap(err, errUnmarshalError) + return "", fmt.Errorf("%s: %w", errUnmarshalError, err) } return apiTokenRollResponse.Result, nil @@ -202,7 +200,7 @@ func (api *API) VerifyAPIToken(ctx context.Context) (APITokenVerifyBody, error) var apiTokenVerifyResponse APITokenVerifyResponse err = json.Unmarshal(res, &apiTokenVerifyResponse) if err != nil { - return APITokenVerifyBody{}, errors.Wrap(err, errUnmarshalError) + return APITokenVerifyBody{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return apiTokenVerifyResponse.Result, nil @@ -232,7 +230,7 @@ func (api *API) ListAPITokensPermissionGroups(ctx context.Context) ([]APITokenPe err = json.Unmarshal(res, &r) if err != nil { - return []APITokenPermissionGroups{}, errors.Wrap(err, errUnmarshalError) + return []APITokenPermissionGroups{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil diff --git a/argo.go b/argo.go index 6254be90582..8cf1944d701 100644 --- a/argo.go +++ b/argo.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) var validSettingValues = []string{"on", "off"} @@ -42,7 +42,7 @@ func (api *API) ArgoSmartRouting(ctx context.Context, zoneID string) (ArgoFeatur var argoDetailsResponse ArgoDetailsResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return ArgoFeatureSetting{}, errors.Wrap(err, errUnmarshalError) + return ArgoFeatureSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil } @@ -65,7 +65,7 @@ func (api *API) UpdateArgoSmartRouting(ctx context.Context, zoneID, settingValue var argoDetailsResponse ArgoDetailsResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return ArgoFeatureSetting{}, errors.Wrap(err, errUnmarshalError) + return ArgoFeatureSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil } @@ -84,7 +84,7 @@ func (api *API) ArgoTieredCaching(ctx context.Context, zoneID string) (ArgoFeatu var argoDetailsResponse ArgoDetailsResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return ArgoFeatureSetting{}, errors.Wrap(err, errUnmarshalError) + return ArgoFeatureSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil } @@ -107,7 +107,7 @@ func (api *API) UpdateArgoTieredCaching(ctx context.Context, zoneID, settingValu var argoDetailsResponse ArgoDetailsResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return ArgoFeatureSetting{}, errors.Wrap(err, errUnmarshalError) + return ArgoFeatureSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil } diff --git a/argo_tunnel.go b/argo_tunnel.go index 91d9586220a..89f6ae8cce8 100644 --- a/argo_tunnel.go +++ b/argo_tunnel.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // ArgoTunnel is the struct definition of a tunnel. @@ -57,7 +55,7 @@ func (api *API) ArgoTunnels(ctx context.Context, accountID string) ([]ArgoTunnel var argoDetailsResponse ArgoTunnelsDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return []ArgoTunnel{}, errors.Wrap(err, errUnmarshalError) + return []ArgoTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil } @@ -78,7 +76,7 @@ func (api *API) ArgoTunnel(ctx context.Context, accountID, tunnelUUID string) (A var argoDetailsResponse ArgoTunnelDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return ArgoTunnel{}, errors.Wrap(err, errUnmarshalError) + return ArgoTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil } @@ -101,7 +99,7 @@ func (api *API) CreateArgoTunnel(ctx context.Context, accountID, name, secret st var argoDetailsResponse ArgoTunnelDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return ArgoTunnel{}, errors.Wrap(err, errUnmarshalError) + return ArgoTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil @@ -123,7 +121,7 @@ func (api *API) DeleteArgoTunnel(ctx context.Context, accountID, tunnelUUID stri var argoDetailsResponse ArgoTunnelDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil @@ -145,7 +143,7 @@ func (api *API) CleanupArgoTunnelConnections(ctx context.Context, accountID, tun var argoDetailsResponse ArgoTunnelDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil diff --git a/authenticated_origin_pulls.go b/authenticated_origin_pulls.go index 0efa33c94e8..2936f65bdfa 100644 --- a/authenticated_origin_pulls.go +++ b/authenticated_origin_pulls.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // AuthenticatedOriginPulls represents global AuthenticatedOriginPulls (tls_client_auth) metadata. @@ -35,7 +33,7 @@ func (api *API) GetAuthenticatedOriginPullsStatus(ctx context.Context, zoneID st } var r AuthenticatedOriginPullsResponse if err := json.Unmarshal(res, &r); err != nil { - return AuthenticatedOriginPulls{}, errors.Wrap(err, errUnmarshalError) + return AuthenticatedOriginPulls{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -62,7 +60,7 @@ func (api *API) SetAuthenticatedOriginPullsStatus(ctx context.Context, zoneID st } var r AuthenticatedOriginPullsResponse if err := json.Unmarshal(res, &r); err != nil { - return AuthenticatedOriginPulls{}, errors.Wrap(err, errUnmarshalError) + return AuthenticatedOriginPulls{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/authenticated_origin_pulls_per_hostname.go b/authenticated_origin_pulls_per_hostname.go index 4242e07547e..8a488c57883 100644 --- a/authenticated_origin_pulls_per_hostname.go +++ b/authenticated_origin_pulls_per_hostname.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // PerHostnameAuthenticatedOriginPullsCertificateDetails represents the metadata for a Per Hostname AuthenticatedOriginPulls certificate. @@ -87,7 +85,7 @@ func (api *API) ListPerHostnameAuthenticatedOriginPullsCertificates(ctx context. } var r PerHostnamesAuthenticatedOriginPullsDetailsResponse if err := json.Unmarshal(res, &r); err != nil { - return []PerHostnameAuthenticatedOriginPullsDetails{}, errors.Wrap(err, errUnmarshalError) + return []PerHostnameAuthenticatedOriginPullsDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -103,7 +101,7 @@ func (api *API) UploadPerHostnameAuthenticatedOriginPullsCertificate(ctx context } var r PerHostnameAuthenticatedOriginPullsCertificateResponse if err := json.Unmarshal(res, &r); err != nil { - return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, errors.Wrap(err, errUnmarshalError) + return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -119,7 +117,7 @@ func (api *API) GetPerHostnameAuthenticatedOriginPullsCertificate(ctx context.Co } var r PerHostnameAuthenticatedOriginPullsCertificateResponse if err := json.Unmarshal(res, &r); err != nil { - return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, errors.Wrap(err, errUnmarshalError) + return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -135,7 +133,7 @@ func (api *API) DeletePerHostnameAuthenticatedOriginPullsCertificate(ctx context } var r PerHostnameAuthenticatedOriginPullsCertificateResponse if err := json.Unmarshal(res, &r); err != nil { - return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, errors.Wrap(err, errUnmarshalError) + return PerHostnameAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -154,7 +152,7 @@ func (api *API) EditPerHostnameAuthenticatedOriginPullsConfig(ctx context.Contex } var r PerHostnamesAuthenticatedOriginPullsDetailsResponse if err := json.Unmarshal(res, &r); err != nil { - return []PerHostnameAuthenticatedOriginPullsDetails{}, errors.Wrap(err, errUnmarshalError) + return []PerHostnameAuthenticatedOriginPullsDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -170,7 +168,7 @@ func (api *API) GetPerHostnameAuthenticatedOriginPullsConfig(ctx context.Context } var r PerHostnameAuthenticatedOriginPullsDetailsResponse if err := json.Unmarshal(res, &r); err != nil { - return PerHostnameAuthenticatedOriginPullsDetails{}, errors.Wrap(err, errUnmarshalError) + return PerHostnameAuthenticatedOriginPullsDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/authenticated_origin_pulls_per_zone.go b/authenticated_origin_pulls_per_zone.go index 7c32be9f7b5..65431194011 100644 --- a/authenticated_origin_pulls_per_zone.go +++ b/authenticated_origin_pulls_per_zone.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // PerZoneAuthenticatedOriginPullsSettings represents the settings for Per Zone AuthenticatedOriginPulls. @@ -61,7 +59,7 @@ func (api *API) GetPerZoneAuthenticatedOriginPullsStatus(ctx context.Context, zo } var r PerZoneAuthenticatedOriginPullsSettingsResponse if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsSettings{}, errors.Wrap(err, errUnmarshalError) + return PerZoneAuthenticatedOriginPullsSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -82,7 +80,7 @@ func (api *API) SetPerZoneAuthenticatedOriginPullsStatus(ctx context.Context, zo } var r PerZoneAuthenticatedOriginPullsSettingsResponse if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsSettings{}, errors.Wrap(err, errUnmarshalError) + return PerZoneAuthenticatedOriginPullsSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -98,7 +96,7 @@ func (api *API) UploadPerZoneAuthenticatedOriginPullsCertificate(ctx context.Con } var r PerZoneAuthenticatedOriginPullsCertificateResponse if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsCertificateDetails{}, errors.Wrap(err, errUnmarshalError) + return PerZoneAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -114,7 +112,7 @@ func (api *API) ListPerZoneAuthenticatedOriginPullsCertificates(ctx context.Cont } var r PerZoneAuthenticatedOriginPullsCertificatesResponse if err := json.Unmarshal(res, &r); err != nil { - return []PerZoneAuthenticatedOriginPullsCertificateDetails{}, errors.Wrap(err, errUnmarshalError) + return []PerZoneAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -130,7 +128,7 @@ func (api *API) GetPerZoneAuthenticatedOriginPullsCertificateDetails(ctx context } var r PerZoneAuthenticatedOriginPullsCertificateResponse if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsCertificateDetails{}, errors.Wrap(err, errUnmarshalError) + return PerZoneAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -146,7 +144,7 @@ func (api *API) DeletePerZoneAuthenticatedOriginPullsCertificate(ctx context.Con } var r PerZoneAuthenticatedOriginPullsCertificateResponse if err := json.Unmarshal(res, &r); err != nil { - return PerZoneAuthenticatedOriginPullsCertificateDetails{}, errors.Wrap(err, errUnmarshalError) + return PerZoneAuthenticatedOriginPullsCertificateDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/certificate_packs.go b/certificate_packs.go index 2f26eb21f53..08847049807 100644 --- a/certificate_packs.go +++ b/certificate_packs.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // CertificatePackGeoRestrictions is for the structure of the geographic @@ -96,7 +94,7 @@ func (api *API) ListCertificatePacks(ctx context.Context, zoneID string) ([]Cert var certificatePacksResponse CertificatePacksResponse err = json.Unmarshal(res, &certificatePacksResponse) if err != nil { - return []CertificatePack{}, errors.Wrap(err, errUnmarshalError) + return []CertificatePack{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return certificatePacksResponse.Result, nil @@ -115,7 +113,7 @@ func (api *API) CertificatePack(ctx context.Context, zoneID, certificatePackID s var certificatePacksDetailResponse CertificatePacksDetailResponse err = json.Unmarshal(res, &certificatePacksDetailResponse) if err != nil { - return CertificatePack{}, errors.Wrap(err, errUnmarshalError) + return CertificatePack{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return certificatePacksDetailResponse.Result, nil @@ -134,7 +132,7 @@ func (api *API) CreateCertificatePack(ctx context.Context, zoneID string, cert C var certificatePacksDetailResponse CertificatePacksDetailResponse err = json.Unmarshal(res, &certificatePacksDetailResponse) if err != nil { - return CertificatePack{}, errors.Wrap(err, errUnmarshalError) + return CertificatePack{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return certificatePacksDetailResponse.Result, nil @@ -166,7 +164,7 @@ func (api *API) CreateAdvancedCertificatePack(ctx context.Context, zoneID string var advancedCertificatePacksDetailResponse CertificatePacksAdvancedDetailResponse err = json.Unmarshal(res, &advancedCertificatePacksDetailResponse) if err != nil { - return CertificatePackAdvancedCertificate{}, errors.Wrap(err, errUnmarshalError) + return CertificatePackAdvancedCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return advancedCertificatePacksDetailResponse.Result, nil @@ -186,7 +184,7 @@ func (api *API) RestartAdvancedCertificateValidation(ctx context.Context, zoneID var advancedCertificatePacksDetailResponse CertificatePacksAdvancedDetailResponse err = json.Unmarshal(res, &advancedCertificatePacksDetailResponse) if err != nil { - return CertificatePackAdvancedCertificate{}, errors.Wrap(err, errUnmarshalError) + return CertificatePackAdvancedCertificate{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return advancedCertificatePacksDetailResponse.Result, nil diff --git a/cloudflare.go b/cloudflare.go index c4fb1d3c3d2..5049d48a9ae 100644 --- a/cloudflare.go +++ b/cloudflare.go @@ -16,7 +16,8 @@ import ( "strings" "time" - "github.com/pkg/errors" + "errors" + "golang.org/x/time/rate" ) @@ -74,7 +75,7 @@ func newClient(opts ...Option) (*API, error) { err := api.parseOptions(opts...) if err != nil { - return nil, errors.Wrap(err, "options parsing failed") + return nil, fmt.Errorf("options parsing failed: %w", err) } // Fall back to http.DefaultClient if the package user does not provide @@ -148,7 +149,7 @@ func (api *API) ZoneIDByName(zoneName string) (string, error) { zoneName = normalizeZoneName(zoneName) res, err := api.ListZonesContext(context.Background(), WithZoneFilters(zoneName, api.AccountID, "")) if err != nil { - return "", errors.Wrap(err, "ListZonesContext command failed") + return "", fmt.Errorf("ListZonesContext command failed: %w", err) } switch len(res.Result) { @@ -201,7 +202,7 @@ func (api *API) makeRequestWithAuthTypeAndHeaders(ctx context.Context, method, u var jsonBody []byte jsonBody, err = json.Marshal(params) if err != nil { - return nil, errors.Wrap(err, "error marshalling params to JSON") + return nil, fmt.Errorf("error marshalling params to JSON: %w", err) } reqBody = bytes.NewReader(jsonBody) } @@ -222,13 +223,13 @@ func (api *API) makeRequestWithAuthTypeAndHeaders(ctx context.Context, method, u select { case <-time.After(sleepDuration): case <-ctx.Done(): - return nil, errors.Wrap(ctx.Err(), "operation aborted during backoff") + return nil, fmt.Errorf("operation aborted during backoff: %w", ctx.Err()) } } err = api.rateLimiter.Wait(ctx) if err != nil { - return nil, errors.Wrap(err, "Error caused by request rate limiting") + return nil, fmt.Errorf("error caused by request rate limiting: %w", err) } if api.Debug { @@ -256,7 +257,7 @@ func (api *API) makeRequestWithAuthTypeAndHeaders(ctx context.Context, method, u respBody, err = ioutil.ReadAll(resp.Body) resp.Body.Close() - respErr = errors.Wrap(err, "could not read response body") + respErr = fmt.Errorf("could not read response body: %w", err) api.logger.Printf("Request: %s %s got an error response %d: %s\n", method, uri, resp.StatusCode, strings.Replace(strings.Replace(string(respBody), "\n", "", -1), "\t", "", -1)) @@ -268,7 +269,7 @@ func (api *API) makeRequestWithAuthTypeAndHeaders(ctx context.Context, method, u respBody, err = ioutil.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { - return nil, errors.Wrap(err, "could not read response body") + return nil, fmt.Errorf("could not read response body: %w", err) } break } @@ -278,12 +279,12 @@ func (api *API) makeRequestWithAuthTypeAndHeaders(ctx context.Context, method, u } if api.Debug { - fmt.Printf("cloudflare-go [DEBUG] RESPONSE URI:%s StatusCode:%d Body:%#v RayID:%s\n", api.BaseURL, resp.StatusCode, string(respBody), resp.Header.Get("cf-ray")) + fmt.Printf("cloudflare-go [DEBUG] RESPONSE StatusCode:%d Body:%#v RayID:%s\n", resp.StatusCode, string(respBody), resp.Header.Get("cf-ray")) } if resp.StatusCode >= http.StatusBadRequest { if strings.HasSuffix(resp.Request.URL.Path, "/filters/validate-expr") { - return nil, errors.Errorf("%s", respBody) + return nil, fmt.Errorf("%s", respBody) } if resp.StatusCode >= http.StatusInternalServerError { @@ -299,7 +300,7 @@ func (api *API) makeRequestWithAuthTypeAndHeaders(ctx context.Context, method, u errBody := &Response{} err = json.Unmarshal(respBody, &errBody) if err != nil { - return nil, errors.Wrap(err, errUnmarshalErrorBody) + return nil, fmt.Errorf(errUnmarshalErrorBody+": %w", err) } errCodes := make([]int, 0, len(errBody.Errors)) @@ -345,7 +346,7 @@ func (api *API) makeRequestWithAuthTypeAndHeaders(ctx context.Context, method, u func (api *API) request(ctx context.Context, method, uri string, reqBody io.Reader, authType int, headers http.Header) (*http.Response, error) { req, err := http.NewRequestWithContext(ctx, method, api.BaseURL+uri, reqBody) if err != nil { - return nil, errors.Wrap(err, "HTTP request creation failed") + return nil, fmt.Errorf("HTTP request creation failed: %w", err) } combinedHeaders := make(http.Header) @@ -374,7 +375,7 @@ func (api *API) request(ctx context.Context, method, uri string, reqBody io.Read resp, err := api.httpClient.Do(req) if err != nil { - return nil, errors.Wrap(err, "HTTP request failed") + return nil, fmt.Errorf("HTTP request failed: %w", err) } return resp, nil @@ -449,7 +450,7 @@ func (api *API) Raw(method, endpoint string, data interface{}) (json.RawMessage, var r RawResponse if err := json.Unmarshal(res, &r); err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/cloudflare_experimental.go b/cloudflare_experimental.go index d47b0277ef7..950442cc2a8 100644 --- a/cloudflare_experimental.go +++ b/cloudflare_experimental.go @@ -15,7 +15,8 @@ import ( "sync" "time" - "github.com/pkg/errors" + "errors" + "golang.org/x/time/rate" ) @@ -148,7 +149,7 @@ func NewExperimental(config *ClientParams) (*Client, error) { func (c *Client) request(ctx context.Context, method, uri string, reqBody io.Reader, headers http.Header) (*http.Response, error) { req, err := http.NewRequestWithContext(ctx, method, c.BaseURL.String()+uri, reqBody) if err != nil { - return nil, errors.Wrap(err, "HTTP request creation failed") + return nil, fmt.Errorf("HTTP request creation failed: %w", err) } combinedHeaders := make(http.Header) @@ -183,7 +184,7 @@ func (c *Client) request(ctx context.Context, method, uri string, reqBody io.Rea resp, err := c.HTTPClient.Do(req) if err != nil { - return nil, errors.Wrap(err, "HTTP request failed") + return nil, fmt.Errorf("HTTP request failed: %w", err) } return resp, nil @@ -202,7 +203,7 @@ func (c *Client) makeRequest(ctx context.Context, method, uri string, params int var jsonBody []byte jsonBody, err = json.Marshal(params) if err != nil { - return nil, errors.Wrap(err, "error marshalling params to JSON") + return nil, fmt.Errorf("error marshalling params to JSON: %w", err) } reqBody = bytes.NewReader(jsonBody) } @@ -261,7 +262,7 @@ func (c *Client) makeRequest(ctx context.Context, method, uri string, params int respBody, err = ioutil.ReadAll(resp.Body) resp.Body.Close() - respErr = errors.Wrap(err, "could not read response body") + respErr = fmt.Errorf("could not read response body: %w", err) } else { c.Logger.Printf("Error performing request: %s %s : %s \n", method, uri, respErr.Error()) } @@ -270,7 +271,7 @@ func (c *Client) makeRequest(ctx context.Context, method, uri string, params int respBody, err = ioutil.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { - return nil, errors.Wrap(err, "could not read response body") + return nil, fmt.Errorf("could not read response body: %w", err) } break } @@ -286,7 +287,7 @@ func (c *Client) makeRequest(ctx context.Context, method, uri string, params int if resp.StatusCode >= http.StatusBadRequest { if strings.HasSuffix(resp.Request.URL.Path, "/filters/validate-expr") { - return nil, errors.Errorf("%s", respBody) + return nil, fmt.Errorf("%s", respBody) } if resp.StatusCode >= http.StatusInternalServerError { diff --git a/cmd/flarectl/firewall.go b/cmd/flarectl/firewall.go index a8df00cfaf7..16d047d4776 100644 --- a/cmd/flarectl/firewall.go +++ b/cmd/flarectl/firewall.go @@ -7,8 +7,9 @@ import ( "os" "strconv" + "errors" + "github.com/cloudflare/cloudflare-go" - "github.com/pkg/errors" "github.com/urfave/cli/v2" ) @@ -167,19 +168,19 @@ func firewallAccessRuleUpdate(c *cli.Context) error { case accountID != "": resp, err := api.UpdateAccountAccessRule(context.Background(), accountID, id, rule) if err != nil { - errors.Wrap(err, errUpdating) //nolint + return fmt.Errorf(errUpdating+": %w", err) } rules = append(rules, resp.Result) case zoneID != "": resp, err := api.UpdateZoneAccessRule(context.Background(), zoneID, id, rule) if err != nil { - errors.Wrap(err, errUpdating) //nolint + return fmt.Errorf(errUpdating+": %w", err) } rules = append(rules, resp.Result) default: resp, err := api.UpdateUserAccessRule(context.Background(), id, rule) if err != nil { - errors.Wrap(err, errUpdating) //nolint + return fmt.Errorf(errUpdating+": %w", err) } rules = append(rules, resp.Result) } @@ -283,19 +284,19 @@ func firewallAccessRuleDelete(c *cli.Context) error { case accountID != "": resp, err := api.DeleteAccountAccessRule(context.Background(), accountID, ruleID) if err != nil { - errors.Wrap(err, errDeleting) //nolint + return fmt.Errorf(errDeleting+": %w", err) } rules = append(rules, resp.Result) case zoneID != "": resp, err := api.DeleteZoneAccessRule(context.Background(), zoneID, ruleID) if err != nil { - errors.Wrap(err, errDeleting) //nolint + return fmt.Errorf(errDeleting+": %w", err) } rules = append(rules, resp.Result) default: resp, err := api.DeleteUserAccessRule(context.Background(), ruleID) if err != nil { - errors.Wrap(err, errDeleting) //nolint + return fmt.Errorf(errDeleting+": %w", err) } rules = append(rules, resp.Result) } diff --git a/cmd/flarectl/misc.go b/cmd/flarectl/misc.go index 2a1b196b6f0..836dc2582aa 100644 --- a/cmd/flarectl/misc.go +++ b/cmd/flarectl/misc.go @@ -7,9 +7,10 @@ import ( "os" "strings" + "errors" + cloudflare "github.com/cloudflare/cloudflare-go" "github.com/olekukonko/tablewriter" - "github.com/pkg/errors" "github.com/urfave/cli/v2" ) @@ -93,7 +94,7 @@ func checkFlags(c *cli.Context, flags ...string) error { for _, flag := range flags { if c.String(flag) == "" { cli.ShowSubcommandHelp(c) //nolint - err := errors.Errorf("error: the required flag %q was empty or not provided", flag) + err := fmt.Errorf("error: the required flag %q was empty or not provided", flag) fmt.Fprintln(os.Stderr, err) return err } diff --git a/custom_hostname.go b/custom_hostname.go index fd25bc050a3..fe1be31bcef 100644 --- a/custom_hostname.go +++ b/custom_hostname.go @@ -9,7 +9,7 @@ import ( "strconv" "time" - "github.com/pkg/errors" + "errors" ) // CustomHostnameStatus is the enumeration of valid state values in the CustomHostnameSSL. @@ -149,7 +149,7 @@ func (api *API) UpdateCustomHostnameSSL(ctx context.Context, zoneID string, cust var response *CustomHostnameResponse err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil } @@ -168,7 +168,7 @@ func (api *API) UpdateCustomHostname(ctx context.Context, zoneID string, customH var response *CustomHostnameResponse err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil } @@ -187,7 +187,7 @@ func (api *API) DeleteCustomHostname(ctx context.Context, zoneID string, customH var response *CustomHostnameResponse err = json.Unmarshal(res, &response) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil @@ -206,7 +206,7 @@ func (api *API) CreateCustomHostname(ctx context.Context, zoneID string, ch Cust var response *CustomHostnameResponse err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -253,7 +253,7 @@ func (api *API) CustomHostname(ctx context.Context, zoneID string, customHostnam var response CustomHostnameResponse err = json.Unmarshal(res, &response) if err != nil { - return CustomHostname{}, errors.Wrap(err, errUnmarshalError) + return CustomHostname{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil @@ -263,7 +263,7 @@ func (api *API) CustomHostname(ctx context.Context, zoneID string, customHostnam func (api *API) CustomHostnameIDByName(ctx context.Context, zoneID string, hostname string) (string, error) { customHostnames, _, err := api.CustomHostnames(ctx, zoneID, 1, CustomHostname{Hostname: hostname}) if err != nil { - return "", errors.Wrap(err, "CustomHostnames command failed") + return "", fmt.Errorf("CustomHostnames command failed: %w", err) } for _, ch := range customHostnames { if ch.Hostname == hostname { @@ -286,7 +286,7 @@ func (api *API) UpdateCustomHostnameFallbackOrigin(ctx context.Context, zoneID s var response *CustomHostnameFallbackOriginResponse err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil } @@ -304,7 +304,7 @@ func (api *API) DeleteCustomHostnameFallbackOrigin(ctx context.Context, zoneID s var response *CustomHostnameFallbackOriginResponse err = json.Unmarshal(res, &response) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } @@ -322,7 +322,7 @@ func (api *API) CustomHostnameFallbackOrigin(ctx context.Context, zoneID string) var response CustomHostnameFallbackOriginResponse err = json.Unmarshal(res, &response) if err != nil { - return CustomHostnameFallbackOrigin{}, errors.Wrap(err, errUnmarshalError) + return CustomHostnameFallbackOrigin{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil diff --git a/custom_pages.go b/custom_pages.go index 45fd504af17..9f60222b35d 100644 --- a/custom_pages.go +++ b/custom_pages.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // CustomPage represents a custom page configuration. @@ -61,11 +59,11 @@ func (api *API) CustomPages(ctx context.Context, options *CustomPageOptions) ([] ) if options.AccountID == "" && options.ZoneID == "" { - return nil, errors.New("either account ID or zone ID must be provided") + return nil, ErrAccountIDOrZoneIDAreRequired } if options.AccountID != "" && options.ZoneID != "" { - return nil, errors.New("account ID and zone ID are mutually exclusive") + return nil, ErrAccountIDAndZoneIDAreMutuallyExclusive } // Should the account ID be defined, treat this as an account level operation. @@ -87,7 +85,7 @@ func (api *API) CustomPages(ctx context.Context, options *CustomPageOptions) ([] var customPageResponse CustomPageResponse err = json.Unmarshal(res, &customPageResponse) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return customPageResponse.Result, nil @@ -103,11 +101,11 @@ func (api *API) CustomPage(ctx context.Context, options *CustomPageOptions, cust ) if options.AccountID == "" && options.ZoneID == "" { - return CustomPage{}, errors.New("either account ID or zone ID must be provided") + return CustomPage{}, ErrAccountIDOrZoneIDAreRequired } if options.AccountID != "" && options.ZoneID != "" { - return CustomPage{}, errors.New("account ID and zone ID are mutually exclusive") + return CustomPage{}, ErrAccountIDAndZoneIDAreMutuallyExclusive } // Should the account ID be defined, treat this as an account level operation. @@ -129,7 +127,7 @@ func (api *API) CustomPage(ctx context.Context, options *CustomPageOptions, cust var customPageResponse CustomPageDetailResponse err = json.Unmarshal(res, &customPageResponse) if err != nil { - return CustomPage{}, errors.Wrap(err, errUnmarshalError) + return CustomPage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return customPageResponse.Result, nil @@ -145,11 +143,11 @@ func (api *API) UpdateCustomPage(ctx context.Context, options *CustomPageOptions ) if options.AccountID == "" && options.ZoneID == "" { - return CustomPage{}, errors.New("either account ID or zone ID must be provided") + return CustomPage{}, ErrAccountIDOrZoneIDAreRequired } if options.AccountID != "" && options.ZoneID != "" { - return CustomPage{}, errors.New("account ID and zone ID are mutually exclusive") + return CustomPage{}, ErrAccountIDAndZoneIDAreMutuallyExclusive } // Should the account ID be defined, treat this as an account level operation. @@ -171,7 +169,7 @@ func (api *API) UpdateCustomPage(ctx context.Context, options *CustomPageOptions var customPageResponse CustomPageDetailResponse err = json.Unmarshal(res, &customPageResponse) if err != nil { - return CustomPage{}, errors.Wrap(err, errUnmarshalError) + return CustomPage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return customPageResponse.Result, nil diff --git a/device_posture_rule.go b/device_posture_rule.go index f9afad56006..77031046ea0 100644 --- a/device_posture_rule.go +++ b/device_posture_rule.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // DevicePostureIntegrationConfig contains authentication information @@ -60,7 +58,7 @@ func (api *API) CreateDevicePostureIntegration(ctx context.Context, accountID st var devicePostureIntegrationResponse DevicePostureIntegrationResponse err = json.Unmarshal(res, &devicePostureIntegrationResponse) if err != nil { - return DevicePostureIntegration{}, errors.Wrap(err, errUnmarshalError) + return DevicePostureIntegration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return devicePostureIntegrationResponse.Result, nil @@ -80,7 +78,7 @@ func (api *API) UpdateDevicePostureIntegration(ctx context.Context, accountID st var devicePostureIntegrationResponse DevicePostureIntegrationResponse err = json.Unmarshal(res, &devicePostureIntegrationResponse) if err != nil { - return DevicePostureIntegration{}, errors.Wrap(err, errUnmarshalError) + return DevicePostureIntegration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return devicePostureIntegrationResponse.Result, nil @@ -100,7 +98,7 @@ func (api *API) DevicePostureIntegration(ctx context.Context, accountID, integra var devicePostureIntegrationResponse DevicePostureIntegrationResponse err = json.Unmarshal(res, &devicePostureIntegrationResponse) if err != nil { - return DevicePostureIntegration{}, errors.Wrap(err, errUnmarshalError) + return DevicePostureIntegration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return devicePostureIntegrationResponse.Result, nil @@ -120,7 +118,7 @@ func (api *API) DevicePostureIntegrations(ctx context.Context, accountID string) var devicePostureIntegrationListResponse DevicePostureIntegrationListResponse err = json.Unmarshal(res, &devicePostureIntegrationListResponse) if err != nil { - return []DevicePostureIntegration{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []DevicePostureIntegration{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return devicePostureIntegrationListResponse.Result, devicePostureIntegrationListResponse.ResultInfo, nil @@ -208,7 +206,7 @@ func (api *API) DevicePostureRules(ctx context.Context, accountID string) ([]Dev var devicePostureRuleListResponse DevicePostureRuleListResponse err = json.Unmarshal(res, &devicePostureRuleListResponse) if err != nil { - return []DevicePostureRule{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []DevicePostureRule{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return devicePostureRuleListResponse.Result, devicePostureRuleListResponse.ResultInfo, nil @@ -233,7 +231,7 @@ func (api *API) DevicePostureRule(ctx context.Context, accountID, ruleID string) var devicePostureRuleDetailResponse DevicePostureRuleDetailResponse err = json.Unmarshal(res, &devicePostureRuleDetailResponse) if err != nil { - return DevicePostureRule{}, errors.Wrap(err, errUnmarshalError) + return DevicePostureRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return devicePostureRuleDetailResponse.Result, nil @@ -253,7 +251,7 @@ func (api *API) CreateDevicePostureRule(ctx context.Context, accountID string, r var devicePostureRuleDetailResponse DevicePostureRuleDetailResponse err = json.Unmarshal(res, &devicePostureRuleDetailResponse) if err != nil { - return DevicePostureRule{}, errors.Wrap(err, errUnmarshalError) + return DevicePostureRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return devicePostureRuleDetailResponse.Result, nil @@ -264,7 +262,7 @@ func (api *API) CreateDevicePostureRule(ctx context.Context, accountID string, r // API reference: https://api.cloudflare.com/#device-posture-rules-update-device-posture-rule func (api *API) UpdateDevicePostureRule(ctx context.Context, accountID string, rule DevicePostureRule) (DevicePostureRule, error) { if rule.ID == "" { - return DevicePostureRule{}, errors.Errorf("device posture rule ID cannot be empty") + return DevicePostureRule{}, fmt.Errorf("device posture rule ID cannot be empty") } uri := fmt.Sprintf( @@ -282,7 +280,7 @@ func (api *API) UpdateDevicePostureRule(ctx context.Context, accountID string, r var devicePostureRuleDetailResponse DevicePostureRuleDetailResponse err = json.Unmarshal(res, &devicePostureRuleDetailResponse) if err != nil { - return DevicePostureRule{}, errors.Wrap(err, errUnmarshalError) + return DevicePostureRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return devicePostureRuleDetailResponse.Result, nil diff --git a/devices_policy.go b/devices_policy.go index b78d152127b..ae2d3cfd73e 100644 --- a/devices_policy.go +++ b/devices_policy.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) type Enabled struct { @@ -32,7 +30,7 @@ func (api *API) UpdateDeviceClientCertificatesZone(ctx context.Context, zoneID s } if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -51,7 +49,7 @@ func (api *API) GetDeviceClientCertificatesZone(ctx context.Context, zoneID stri } if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err diff --git a/diagnostics.go b/diagnostics.go index 6fc2daac459..a6a8bfedafd 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // DiagnosticsTracerouteConfiguration is the overarching structure of the @@ -96,7 +94,7 @@ func (api *API) PerformTraceroute(ctx context.Context, accountID string, targets var diagnosticsResponse DiagnosticsTracerouteResponse err = json.Unmarshal(res, &diagnosticsResponse) if err != nil { - return []DiagnosticsTracerouteResponseResult{}, errors.Wrap(err, errUnmarshalError) + return []DiagnosticsTracerouteResponseResult{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return diagnosticsResponse.Result, nil diff --git a/dns.go b/dns.go index 017d6f0f761..affb167efb6 100644 --- a/dns.go +++ b/dns.go @@ -9,7 +9,6 @@ import ( "strconv" "time" - "github.com/pkg/errors" "golang.org/x/net/idna" ) @@ -80,7 +79,7 @@ func (api *API) CreateDNSRecord(ctx context.Context, zoneID string, rr DNSRecord var recordResp *DNSRecordResponse err = json.Unmarshal(res, &recordResp) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return recordResp, nil @@ -119,7 +118,7 @@ func (api *API) DNSRecords(ctx context.Context, zoneID string, rr DNSRecord) ([] var r DNSListResponse err = json.Unmarshal(res, &r) if err != nil { - return []DNSRecord{}, errors.Wrap(err, errUnmarshalError) + return []DNSRecord{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } records = append(records, r.Result...) if r.ResultInfo.Page >= r.ResultInfo.TotalPages { @@ -144,7 +143,7 @@ func (api *API) DNSRecord(ctx context.Context, zoneID, recordID string) (DNSReco var r DNSRecordResponse err = json.Unmarshal(res, &r) if err != nil { - return DNSRecord{}, errors.Wrap(err, errUnmarshalError) + return DNSRecord{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -179,7 +178,7 @@ func (api *API) UpdateDNSRecord(ctx context.Context, zoneID, recordID string, rr var r DNSRecordResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } @@ -197,7 +196,7 @@ func (api *API) DeleteDNSRecord(ctx context.Context, zoneID, recordID string) er var r DNSRecordResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } diff --git a/dns_firewall.go b/dns_firewall.go index 1e3849dbfbb..f2cfa42ae8c 100644 --- a/dns_firewall.go +++ b/dns_firewall.go @@ -8,8 +8,6 @@ import ( "net/url" "strings" "time" - - "github.com/pkg/errors" ) // DNSFirewallCluster represents a DNS Firewall configuration. @@ -81,7 +79,7 @@ func (api *API) CreateDNSFirewallCluster(ctx context.Context, v DNSFirewallClust response := &dnsFirewallResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil @@ -100,7 +98,7 @@ func (api *API) DNSFirewallCluster(ctx context.Context, clusterID string) (*DNSF response := &dnsFirewallResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil @@ -119,7 +117,7 @@ func (api *API) ListDNSFirewallClusters(ctx context.Context) ([]*DNSFirewallClus response := &dnsFirewallListResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil @@ -138,7 +136,7 @@ func (api *API) UpdateDNSFirewallCluster(ctx context.Context, clusterID string, response := &dnsFirewallResponse{} err = json.Unmarshal(res, &response) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil @@ -158,7 +156,7 @@ func (api *API) DeleteDNSFirewallCluster(ctx context.Context, clusterID string) response := &dnsFirewallResponse{} err = json.Unmarshal(res, &response) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil @@ -190,7 +188,7 @@ func (api *API) DNSFirewallUserAnalytics(ctx context.Context, clusterID string, response := dnsFirewallAnalyticsResponse{} err = json.Unmarshal(res, &response) if err != nil { - return DNSFirewallAnalytics{}, errors.Wrap(err, errUnmarshalError) + return DNSFirewallAnalytics{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil diff --git a/errors.go b/errors.go index fe9abf7f3f5..89e02b27aaf 100644 --- a/errors.go +++ b/errors.go @@ -5,30 +5,35 @@ import ( "net/http" "strings" - "github.com/pkg/errors" + "errors" ) -// Error messages. const ( - errEmptyCredentials = "invalid credentials: key & email must not be empty" //nolint:gosec,unused - errEmptyAPIToken = "invalid credentials: API Token must not be empty" //nolint:gosec,unused - errInternalServiceError = "internal service error" - errMakeRequestError = "error from makeRequest" - errUnmarshalError = "error unmarshalling the JSON response" - errUnmarshalErrorBody = "error unmarshalling the JSON response error body" - errRequestNotSuccessful = "error reported by API" - errMissingAccountID = "account ID is empty and must be provided" - errOperationStillRunning = "bulk operation did not finish before timeout" - errOperationUnexpectedStatus = "bulk operation returned an unexpected status" - errResultInfo = "incorrect pagination info (result_info) in responses" - errManualPagination = "unexpected pagination options passed to functions that handle pagination automatically" - errInvalidZoneIdentifer = "invalid zone identifier: %s" + errEmptyCredentials = "invalid credentials: key & email must not be empty" //nolint:gosec,unused + errEmptyAPIToken = "invalid credentials: API Token must not be empty" //nolint:gosec,unused + errInternalServiceError = "internal service error" + errMakeRequestError = "error from makeRequest" + errUnmarshalError = "error unmarshalling the JSON response" + errUnmarshalErrorBody = "error unmarshalling the JSON response error body" + errRequestNotSuccessful = "error reported by API" + errMissingAccountID = "required missing account ID" + errMissingZoneID = "required missing zone ID" + errMissingAccountOrZoneID = "either account ID or zone ID must be provided" + errAccountIDAndZoneIDAreMutuallyExclusive = "account ID and zone ID are mutually exclusive" + errMissingResourceIdentifier = "required missing resource identifier" + errOperationStillRunning = "bulk operation did not finish before timeout" + errOperationUnexpectedStatus = "bulk operation returned an unexpected status" + errResultInfo = "incorrect pagination info (result_info) in responses" + errManualPagination = "unexpected pagination options passed to functions that handle pagination automatically" + errInvalidZoneIdentifer = "invalid zone identifier: %s" ) var ( - ErrMissingAccountID = errors.New("required missing account ID") - ErrMissingZoneID = errors.New("required missing zone ID") - ErrMissingResourceIdentifier = errors.New("required missing resource identifier") + ErrMissingAccountID = errors.New(errMissingAccountID) + ErrMissingZoneID = errors.New(errMissingZoneID) + ErrAccountIDOrZoneIDAreRequired = errors.New(errMissingAccountOrZoneID) + ErrAccountIDAndZoneIDAreMutuallyExclusive = errors.New(errAccountIDAndZoneIDAreMutuallyExclusive) + ErrMissingResourceIdentifier = errors.New(errMissingResourceIdentifier) ) type ErrorType string diff --git a/fallback_domain.go b/fallback_domain.go index 6110b965acb..b0aa4a78b60 100644 --- a/fallback_domain.go +++ b/fallback_domain.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // FallbackDomainResponse represents the response from the get fallback @@ -37,7 +35,7 @@ func (api *API) ListFallbackDomains(ctx context.Context, accountID string) ([]Fa var fallbackDomainResponse FallbackDomainResponse err = json.Unmarshal(res, &fallbackDomainResponse) if err != nil { - return []FallbackDomain{}, errors.Wrap(err, errUnmarshalError) + return []FallbackDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return fallbackDomainResponse.Result, nil @@ -57,7 +55,7 @@ func (api *API) UpdateFallbackDomain(ctx context.Context, accountID string, doma var fallbackDomainResponse FallbackDomainResponse err = json.Unmarshal(res, &fallbackDomainResponse) if err != nil { - return []FallbackDomain{}, errors.Wrap(err, errUnmarshalError) + return []FallbackDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return fallbackDomainResponse.Result, nil diff --git a/filter.go b/filter.go index 784036f1dfc..2505955a505 100644 --- a/filter.go +++ b/filter.go @@ -7,7 +7,7 @@ import ( "net/http" "net/url" - "github.com/pkg/errors" + "errors" ) var ErrNotEnoughFilterIDsProvided = errors.New("at least one filter ID must be provided.") @@ -74,7 +74,7 @@ func (api *API) Filter(ctx context.Context, zoneID, filterID string) (Filter, er var filterResponse FilterDetailResponse err = json.Unmarshal(res, &filterResponse) if err != nil { - return Filter{}, errors.Wrap(err, errUnmarshalError) + return Filter{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return filterResponse.Result, nil @@ -94,7 +94,7 @@ func (api *API) Filters(ctx context.Context, zoneID string, pageOpts PaginationO var filtersResponse FiltersDetailResponse err = json.Unmarshal(res, &filtersResponse) if err != nil { - return []Filter{}, errors.Wrap(err, errUnmarshalError) + return []Filter{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return filtersResponse.Result, nil @@ -114,7 +114,7 @@ func (api *API) CreateFilters(ctx context.Context, zoneID string, filters []Filt var filtersResponse FiltersDetailResponse err = json.Unmarshal(res, &filtersResponse) if err != nil { - return []Filter{}, errors.Wrap(err, errUnmarshalError) + return []Filter{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return filtersResponse.Result, nil @@ -125,7 +125,7 @@ func (api *API) CreateFilters(ctx context.Context, zoneID string, filters []Filt // API reference: https://developers.cloudflare.com/firewall/api/cf-filters/put/#update-a-single-filter func (api *API) UpdateFilter(ctx context.Context, zoneID string, filter Filter) (Filter, error) { if filter.ID == "" { - return Filter{}, errors.Errorf("filter ID cannot be empty") + return Filter{}, fmt.Errorf("filter ID cannot be empty") } uri := fmt.Sprintf("/zones/%s/filters/%s", zoneID, filter.ID) @@ -138,7 +138,7 @@ func (api *API) UpdateFilter(ctx context.Context, zoneID string, filter Filter) var filterResponse FilterDetailResponse err = json.Unmarshal(res, &filterResponse) if err != nil { - return Filter{}, errors.Wrap(err, errUnmarshalError) + return Filter{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return filterResponse.Result, nil @@ -150,7 +150,7 @@ func (api *API) UpdateFilter(ctx context.Context, zoneID string, filter Filter) func (api *API) UpdateFilters(ctx context.Context, zoneID string, filters []Filter) ([]Filter, error) { for _, filter := range filters { if filter.ID == "" { - return []Filter{}, errors.Errorf("filter ID cannot be empty") + return []Filter{}, fmt.Errorf("filter ID cannot be empty") } } @@ -164,7 +164,7 @@ func (api *API) UpdateFilters(ctx context.Context, zoneID string, filters []Filt var filtersResponse FiltersDetailResponse err = json.Unmarshal(res, &filtersResponse) if err != nil { - return []Filter{}, errors.Wrap(err, errUnmarshalError) + return []Filter{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return filtersResponse.Result, nil @@ -175,7 +175,7 @@ func (api *API) UpdateFilters(ctx context.Context, zoneID string, filters []Filt // API reference: https://developers.cloudflare.com/firewall/api/cf-filters/delete/#delete-a-single-filter func (api *API) DeleteFilter(ctx context.Context, zoneID, filterID string) error { if filterID == "" { - return errors.Errorf("filter ID cannot be empty") + return fmt.Errorf("filter ID cannot be empty") } uri := fmt.Sprintf("/zones/%s/filters/%s", zoneID, filterID) @@ -227,13 +227,13 @@ func (api *API) ValidateFilterExpression(ctx context.Context, expression string) jsonErr := json.Unmarshal([]byte(err.Error()), &filterValidationResponse) if jsonErr != nil { - return errors.Wrap(jsonErr, errUnmarshalError) + return fmt.Errorf(errUnmarshalError+": %w", jsonErr) } if !filterValidationResponse.Success { // Unsure why but the API returns `errors` as an array but it only // ever shows the issue with one problem at a time ¯\_(ツ)_/¯ - return errors.Errorf(filterValidationResponse.Errors[0].Message) + return fmt.Errorf(filterValidationResponse.Errors[0].Message) } } diff --git a/firewall.go b/firewall.go index cbf78da5bbf..51f004a62fc 100644 --- a/firewall.go +++ b/firewall.go @@ -8,8 +8,6 @@ import ( "net/url" "strconv" "time" - - "github.com/pkg/errors" ) // AccessRule represents a firewall access rule. @@ -211,7 +209,7 @@ func (api *API) listAccessRules(ctx context.Context, prefix string, accessRule A response := &AccessRuleListResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil } @@ -226,7 +224,7 @@ func (api *API) createAccessRule(ctx context.Context, prefix string, accessRule response := &AccessRuleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -244,7 +242,7 @@ func (api *API) retrieveAccessRule(ctx context.Context, prefix, accessRuleID str response := &AccessRuleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -260,7 +258,7 @@ func (api *API) updateAccessRule(ctx context.Context, prefix, accessRuleID strin response := &AccessRuleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil } @@ -275,7 +273,7 @@ func (api *API) deleteAccessRule(ctx context.Context, prefix, accessRuleID strin response := &AccessRuleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil diff --git a/firewall_rules.go b/firewall_rules.go index 0e19a5e4be7..8b5288cfdf3 100644 --- a/firewall_rules.go +++ b/firewall_rules.go @@ -7,8 +7,6 @@ import ( "net/http" "net/url" "time" - - "github.com/pkg/errors" ) // FirewallRule is the struct of the firewall rule. @@ -54,7 +52,7 @@ func (api *API) FirewallRules(ctx context.Context, zoneID string, pageOpts Pagin var firewallDetailResponse FirewallRulesDetailResponse err = json.Unmarshal(res, &firewallDetailResponse) if err != nil { - return []FirewallRule{}, errors.Wrap(err, errUnmarshalError) + return []FirewallRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return firewallDetailResponse.Result, nil @@ -74,7 +72,7 @@ func (api *API) FirewallRule(ctx context.Context, zoneID, firewallRuleID string) var firewallRuleResponse FirewallRuleResponse err = json.Unmarshal(res, &firewallRuleResponse) if err != nil { - return FirewallRule{}, errors.Wrap(err, errUnmarshalError) + return FirewallRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return firewallRuleResponse.Result, nil @@ -94,7 +92,7 @@ func (api *API) CreateFirewallRules(ctx context.Context, zoneID string, firewall var firewallRulesDetailResponse FirewallRulesDetailResponse err = json.Unmarshal(res, &firewallRulesDetailResponse) if err != nil { - return []FirewallRule{}, errors.Wrap(err, errUnmarshalError) + return []FirewallRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return firewallRulesDetailResponse.Result, nil @@ -105,7 +103,7 @@ func (api *API) CreateFirewallRules(ctx context.Context, zoneID string, firewall // API reference: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/put/#update-a-single-rule func (api *API) UpdateFirewallRule(ctx context.Context, zoneID string, firewallRule FirewallRule) (FirewallRule, error) { if firewallRule.ID == "" { - return FirewallRule{}, errors.Errorf("firewall rule ID cannot be empty") + return FirewallRule{}, fmt.Errorf("firewall rule ID cannot be empty") } uri := fmt.Sprintf("/zones/%s/firewall/rules/%s", zoneID, firewallRule.ID) @@ -118,7 +116,7 @@ func (api *API) UpdateFirewallRule(ctx context.Context, zoneID string, firewallR var firewallRuleResponse FirewallRuleResponse err = json.Unmarshal(res, &firewallRuleResponse) if err != nil { - return FirewallRule{}, errors.Wrap(err, errUnmarshalError) + return FirewallRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return firewallRuleResponse.Result, nil @@ -130,7 +128,7 @@ func (api *API) UpdateFirewallRule(ctx context.Context, zoneID string, firewallR func (api *API) UpdateFirewallRules(ctx context.Context, zoneID string, firewallRules []FirewallRule) ([]FirewallRule, error) { for _, firewallRule := range firewallRules { if firewallRule.ID == "" { - return []FirewallRule{}, errors.Errorf("firewall ID cannot be empty") + return []FirewallRule{}, fmt.Errorf("firewall ID cannot be empty") } } @@ -144,7 +142,7 @@ func (api *API) UpdateFirewallRules(ctx context.Context, zoneID string, firewall var firewallRulesDetailResponse FirewallRulesDetailResponse err = json.Unmarshal(res, &firewallRulesDetailResponse) if err != nil { - return []FirewallRule{}, errors.Wrap(err, errUnmarshalError) + return []FirewallRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return firewallRulesDetailResponse.Result, nil @@ -155,7 +153,7 @@ func (api *API) UpdateFirewallRules(ctx context.Context, zoneID string, firewall // API reference: https://developers.cloudflare.com/firewall/api/cf-firewall-rules/delete/#delete-a-single-rule func (api *API) DeleteFirewallRule(ctx context.Context, zoneID, firewallRuleID string) error { if firewallRuleID == "" { - return errors.Errorf("firewall rule ID cannot be empty") + return fmt.Errorf("firewall rule ID cannot be empty") } uri := fmt.Sprintf("/zones/%s/firewall/rules/%s", zoneID, firewallRuleID) diff --git a/healthchecks.go b/healthchecks.go index d40965e8730..32ca4dc7eee 100644 --- a/healthchecks.go +++ b/healthchecks.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // Healthcheck describes a Healthcheck object. @@ -84,7 +82,7 @@ func (api *API) Healthchecks(ctx context.Context, zoneID string) ([]Healthcheck, var r HealthcheckListResponse err = json.Unmarshal(res, &r) if err != nil { - return []Healthcheck{}, errors.Wrap(err, errUnmarshalError) + return []Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -101,7 +99,7 @@ func (api *API) Healthcheck(ctx context.Context, zoneID, healthcheckID string) ( var r HealthcheckResponse err = json.Unmarshal(res, &r) if err != nil { - return Healthcheck{}, errors.Wrap(err, errUnmarshalError) + return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -118,7 +116,7 @@ func (api *API) CreateHealthcheck(ctx context.Context, zoneID string, healthchec var r HealthcheckResponse err = json.Unmarshal(res, &r) if err != nil { - return Healthcheck{}, errors.Wrap(err, errUnmarshalError) + return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -135,7 +133,7 @@ func (api *API) UpdateHealthcheck(ctx context.Context, zoneID string, healthchec var r HealthcheckResponse err = json.Unmarshal(res, &r) if err != nil { - return Healthcheck{}, errors.Wrap(err, errUnmarshalError) + return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -152,7 +150,7 @@ func (api *API) DeleteHealthcheck(ctx context.Context, zoneID string, healthchec var r HealthcheckResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } @@ -169,7 +167,7 @@ func (api *API) CreateHealthcheckPreview(ctx context.Context, zoneID string, hea var r HealthcheckResponse err = json.Unmarshal(res, &r) if err != nil { - return Healthcheck{}, errors.Wrap(err, errUnmarshalError) + return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -186,7 +184,7 @@ func (api *API) HealthcheckPreview(ctx context.Context, zoneID, id string) (Heal var r HealthcheckResponse err = json.Unmarshal(res, &r) if err != nil { - return Healthcheck{}, errors.Wrap(err, errUnmarshalError) + return Healthcheck{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -203,7 +201,7 @@ func (api *API) DeleteHealthcheckPreview(ctx context.Context, zoneID string, id var r HealthcheckResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } diff --git a/images.go b/images.go index b8e96fd53b5..d9f749ab1bf 100644 --- a/images.go +++ b/images.go @@ -10,7 +10,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) // Image represents a Cloudflare Image. @@ -134,7 +134,7 @@ func (api *API) UploadImage(ctx context.Context, accountID string, upload ImageU w := multipart.NewWriter(body) if err := upload.write(w); err != nil { _ = w.Close() - return Image{}, errors.Wrap(err, "error writing multipart body") + return Image{}, fmt.Errorf("error writing multipart body: %w", err) } _ = w.Close() @@ -156,7 +156,7 @@ func (api *API) UploadImage(ctx context.Context, accountID string, upload ImageU var imageDetailsResponse ImageDetailsResponse err = json.Unmarshal(res, &imageDetailsResponse) if err != nil { - return Image{}, errors.Wrap(err, errUnmarshalError) + return Image{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return imageDetailsResponse.Result, nil } @@ -175,7 +175,7 @@ func (api *API) UpdateImage(ctx context.Context, accountID string, id string, im var imageDetailsResponse ImageDetailsResponse err = json.Unmarshal(res, &imageDetailsResponse) if err != nil { - return Image{}, errors.Wrap(err, errUnmarshalError) + return Image{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return imageDetailsResponse.Result, nil } @@ -194,7 +194,7 @@ func (api *API) CreateImageDirectUploadURL(ctx context.Context, accountID string var imageDirectUploadURLResponse ImageDirectUploadURLResponse err = json.Unmarshal(res, &imageDirectUploadURLResponse) if err != nil { - return ImageDirectUploadURL{}, errors.Wrap(err, errUnmarshalError) + return ImageDirectUploadURL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return imageDirectUploadURLResponse.Result, nil } @@ -213,7 +213,7 @@ func (api *API) ListImages(ctx context.Context, accountID string, pageOpts Pagin var imagesListResponse ImagesListResponse err = json.Unmarshal(res, &imagesListResponse) if err != nil { - return []Image{}, errors.Wrap(err, errUnmarshalError) + return []Image{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return imagesListResponse.Result.Images, nil } @@ -232,7 +232,7 @@ func (api *API) ImageDetails(ctx context.Context, accountID string, id string) ( var imageDetailsResponse ImageDetailsResponse err = json.Unmarshal(res, &imageDetailsResponse) if err != nil { - return Image{}, errors.Wrap(err, errUnmarshalError) + return Image{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return imageDetailsResponse.Result, nil } @@ -277,7 +277,7 @@ func (api *API) ImagesStats(ctx context.Context, accountID string) (ImagesStatsC var imagesStatsResponse ImagesStatsResponse err = json.Unmarshal(res, &imagesStatsResponse) if err != nil { - return ImagesStatsCount{}, errors.Wrap(err, errUnmarshalError) + return ImagesStatsCount{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return imagesStatsResponse.Result.Count, nil } diff --git a/ip_address_management.go b/ip_address_management.go index 838626635d7..52b71e93f83 100644 --- a/ip_address_management.go +++ b/ip_address_management.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // IPPrefix contains information about an IP prefix. @@ -71,7 +69,7 @@ func (api *API) ListPrefixes(ctx context.Context, accountID string) ([]IPPrefix, result := ListIPPrefixResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []IPPrefix{}, errors.Wrap(err, errUnmarshalError) + return []IPPrefix{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -89,7 +87,7 @@ func (api *API) GetPrefix(ctx context.Context, accountID, ID string) (IPPrefix, result := GetIPPrefixResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPPrefix{}, errors.Wrap(err, errUnmarshalError) + return IPPrefix{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -107,7 +105,7 @@ func (api *API) UpdatePrefixDescription(ctx context.Context, accountID, ID strin result := GetIPPrefixResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPPrefix{}, errors.Wrap(err, errUnmarshalError) + return IPPrefix{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -125,7 +123,7 @@ func (api *API) GetAdvertisementStatus(ctx context.Context, accountID, ID string result := GetAdvertisementStatusResponse{} if err := json.Unmarshal(res, &result); err != nil { - return AdvertisementStatus{}, errors.Wrap(err, errUnmarshalError) + return AdvertisementStatus{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -143,7 +141,7 @@ func (api *API) UpdateAdvertisementStatus(ctx context.Context, accountID, ID str result := GetAdvertisementStatusResponse{} if err := json.Unmarshal(res, &result); err != nil { - return AdvertisementStatus{}, errors.Wrap(err, errUnmarshalError) + return AdvertisementStatus{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil diff --git a/ip_list.go b/ip_list.go index 9f0dd0203de..d1f6f95c6ee 100644 --- a/ip_list.go +++ b/ip_list.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) // The definitions in this file are deprecated and should be removed after @@ -145,7 +145,7 @@ func (api *API) ListIPLists(ctx context.Context, accountID string) ([]IPList, er result := IPListListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []IPList{}, errors.Wrap(err, errUnmarshalError) + return []IPList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -167,7 +167,7 @@ func (api *API) CreateIPList(ctx context.Context, accountID, name, description, result := IPListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPList{}, errors.Wrap(err, errUnmarshalError) + return IPList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -187,7 +187,7 @@ func (api *API) GetIPList(ctx context.Context, accountID, ID string) (IPList, er result := IPListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPList{}, errors.Wrap(err, errUnmarshalError) + return IPList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -207,7 +207,7 @@ func (api *API) UpdateIPList(ctx context.Context, accountID, ID, description str result := IPListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPList{}, errors.Wrap(err, errUnmarshalError) + return IPList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -227,7 +227,7 @@ func (api *API) DeleteIPList(ctx context.Context, accountID, ID string) (IPListD result := IPListDeleteResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPListDeleteResponse{}, errors.Wrap(err, errUnmarshalError) + return IPListDeleteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -255,7 +255,7 @@ func (api *API) ListIPListItems(ctx context.Context, accountID, ID string) ([]IP result := IPListItemsListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []IPListItem{}, errors.Wrap(err, errUnmarshalError) + return []IPListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } list = append(list, result.Result...) @@ -283,7 +283,7 @@ func (api *API) CreateIPListItemAsync(ctx context.Context, accountID, ID, ip, co result := IPListItemCreateResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPListItemCreateResponse{}, errors.Wrap(err, errUnmarshalError) + return IPListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -325,7 +325,7 @@ func (api *API) CreateIPListItemsAsync(ctx context.Context, accountID, ID string result := IPListItemCreateResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPListItemCreateResponse{}, errors.Wrap(err, errUnmarshalError) + return IPListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -367,7 +367,7 @@ func (api *API) ReplaceIPListItemsAsync(ctx context.Context, accountID, ID strin result := IPListItemCreateResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPListItemCreateResponse{}, errors.Wrap(err, errUnmarshalError) + return IPListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -409,7 +409,7 @@ func (api *API) DeleteIPListItemsAsync(ctx context.Context, accountID, ID string result := IPListItemDeleteResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPListItemDeleteResponse{}, errors.Wrap(err, errUnmarshalError) + return IPListItemDeleteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -448,7 +448,7 @@ func (api *API) GetIPListItem(ctx context.Context, accountID, listID, id string) result := IPListItemsGetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPListItem{}, errors.Wrap(err, errUnmarshalError) + return IPListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -468,7 +468,7 @@ func (api *API) GetIPListBulkOperation(ctx context.Context, accountID, ID string result := IPListBulkOperationResponse{} if err := json.Unmarshal(res, &result); err != nil { - return IPListBulkOperation{}, errors.Wrap(err, errUnmarshalError) + return IPListBulkOperation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -483,7 +483,7 @@ func (api *API) pollIPListBulkOperation(ctx context.Context, accountID, ID strin select { case <-time.After(sleepDuration): case <-ctx.Done(): - return errors.Wrap(ctx.Err(), "operation aborted during backoff") + return fmt.Errorf("operation aborted during backoff: %w", ctx.Err()) } bulkResult, err := api.GetIPListBulkOperation(ctx, accountID, ID) diff --git a/ips.go b/ips.go index 090d3c7cafe..f6e4add3da5 100644 --- a/ips.go +++ b/ips.go @@ -6,8 +6,6 @@ import ( "io/ioutil" "net/http" "strings" - - "github.com/pkg/errors" ) // IPRangesResponse contains the structure for the API response, not modified. @@ -40,17 +38,17 @@ func IPs() (IPRanges, error) { uri := fmt.Sprintf("%s/ips?china_colo=1", apiURL) resp, err := http.Get(uri) //nolint:gosec if err != nil { - return IPRanges{}, errors.Wrap(err, "HTTP request failed") + return IPRanges{}, fmt.Errorf("HTTP request failed: %w", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { - return IPRanges{}, errors.Wrap(err, "Response body could not be read") + return IPRanges{}, fmt.Errorf("Response body could not be read: %w", err) } var r IPsResponse err = json.Unmarshal(body, &r) if err != nil { - return IPRanges{}, errors.Wrap(err, errUnmarshalError) + return IPRanges{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } var ips IPRanges diff --git a/keyless.go b/keyless.go index 4558091d0e8..2171d4ab340 100644 --- a/keyless.go +++ b/keyless.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // KeylessSSL represents Keyless SSL configuration. @@ -66,7 +64,7 @@ func (api *API) CreateKeylessSSL(ctx context.Context, zoneID string, keylessSSL var keylessSSLDetailResponse KeylessSSLDetailResponse err = json.Unmarshal(res, &keylessSSLDetailResponse) if err != nil { - return KeylessSSL{}, errors.Wrap(err, errUnmarshalError) + return KeylessSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return keylessSSLDetailResponse.Result, nil @@ -86,7 +84,7 @@ func (api *API) ListKeylessSSL(ctx context.Context, zoneID string) ([]KeylessSSL var keylessSSLListResponse KeylessSSLListResponse err = json.Unmarshal(res, &keylessSSLListResponse) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return keylessSSLListResponse.Result, nil @@ -106,7 +104,7 @@ func (api *API) KeylessSSL(ctx context.Context, zoneID, keylessSSLID string) (Ke var keylessResponse KeylessSSLDetailResponse err = json.Unmarshal(res, &keylessResponse) if err != nil { - return KeylessSSL{}, errors.Wrap(err, errUnmarshalError) + return KeylessSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return keylessResponse.Result, nil @@ -126,7 +124,7 @@ func (api *API) UpdateKeylessSSL(ctx context.Context, zoneID, kelessSSLID string var keylessSSLDetailResponse KeylessSSLDetailResponse err = json.Unmarshal(res, &keylessSSLDetailResponse) if err != nil { - return KeylessSSL{}, errors.Wrap(err, errUnmarshalError) + return KeylessSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return keylessSSLDetailResponse.Result, nil diff --git a/list.go b/list.go index e831fb708cd..4b12486d338 100644 --- a/list.go +++ b/list.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) const ( @@ -225,7 +225,7 @@ func (api *API) ListLists(ctx context.Context, params ListListsParams) ([]List, result := ListListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []List{}, errors.Wrap(err, errUnmarshalError) + return []List{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -248,7 +248,7 @@ func (api *API) CreateList(ctx context.Context, params ListCreateParams) (List, result := ListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return List{}, errors.Wrap(err, errUnmarshalError) + return List{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -274,7 +274,7 @@ func (api *API) GetList(ctx context.Context, params ListGetParams) (List, error) result := ListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return List{}, errors.Wrap(err, errUnmarshalError) + return List{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -300,7 +300,7 @@ func (api *API) UpdateList(ctx context.Context, params ListUpdateParams) (List, result := ListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return List{}, errors.Wrap(err, errUnmarshalError) + return List{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -326,7 +326,7 @@ func (api *API) DeleteList(ctx context.Context, params ListDeleteParams) (ListDe result := ListDeleteResponse{} if err := json.Unmarshal(res, &result); err != nil { - return ListDeleteResponse{}, errors.Wrap(err, errUnmarshalError) + return ListDeleteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -352,7 +352,7 @@ func (api *API) ListListItems(ctx context.Context, params ListListItemsParams) ( result := ListItemsListResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []ListItem{}, errors.Wrap(err, errUnmarshalError) + return []ListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } list = append(list, result.Result...) @@ -385,7 +385,7 @@ func (api *API) CreateListItemAsync(ctx context.Context, params ListCreateItemPa result := ListItemCreateResponse{} if err := json.Unmarshal(res, &result); err != nil { - return ListItemCreateResponse{}, errors.Wrap(err, errUnmarshalError) + return ListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -429,7 +429,7 @@ func (api *API) CreateListItemsAsync(ctx context.Context, params ListCreateItems result := ListItemCreateResponse{} if err := json.Unmarshal(res, &result); err != nil { - return ListItemCreateResponse{}, errors.Wrap(err, errUnmarshalError) + return ListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -473,7 +473,7 @@ func (api *API) ReplaceListItemsAsync(ctx context.Context, params ListReplaceIte result := ListItemCreateResponse{} if err := json.Unmarshal(res, &result); err != nil { - return ListItemCreateResponse{}, errors.Wrap(err, errUnmarshalError) + return ListItemCreateResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -518,7 +518,7 @@ func (api *API) DeleteListItemsAsync(ctx context.Context, params ListDeleteItems result := ListItemDeleteResponse{} if err := json.Unmarshal(res, &result); err != nil { - return ListItemDeleteResponse{}, errors.Wrap(err, errUnmarshalError) + return ListItemDeleteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, nil @@ -564,7 +564,7 @@ func (api *API) GetListItem(ctx context.Context, params ListGetItemParams) (List result := ListItemsGetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return ListItem{}, errors.Wrap(err, errUnmarshalError) + return ListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -590,7 +590,7 @@ func (api *API) GetListBulkOperation(ctx context.Context, params ListGetBulkOper result := ListBulkOperationResponse{} if err := json.Unmarshal(res, &result); err != nil { - return ListBulkOperation{}, errors.Wrap(err, errUnmarshalError) + return ListBulkOperation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -605,7 +605,7 @@ func (api *API) pollListBulkOperation(ctx context.Context, accountID, ID string) select { case <-time.After(sleepDuration): case <-ctx.Done(): - return errors.Wrap(ctx.Err(), "operation aborted during backoff") + return fmt.Errorf("operation aborted during backoff: %w", ctx.Err()) } bulkResult, err := api.GetListBulkOperation(ctx, ListGetBulkOperationParams{AccountID: accountID, ID: ID}) diff --git a/load_balancing.go b/load_balancing.go index 82242704203..2df80a8c6f0 100644 --- a/load_balancing.go +++ b/load_balancing.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // LoadBalancerPool represents a load balancer pool's properties. @@ -265,7 +263,7 @@ func (api *API) CreateLoadBalancerPool(ctx context.Context, pool LoadBalancerPoo } var r loadBalancerPoolResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerPool{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancerPool{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -281,7 +279,7 @@ func (api *API) ListLoadBalancerPools(ctx context.Context) ([]LoadBalancerPool, } var r loadBalancerPoolListResponse if err := json.Unmarshal(res, &r); err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -297,7 +295,7 @@ func (api *API) LoadBalancerPoolDetails(ctx context.Context, poolID string) (Loa } var r loadBalancerPoolResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerPool{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancerPool{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -324,7 +322,7 @@ func (api *API) ModifyLoadBalancerPool(ctx context.Context, pool LoadBalancerPoo } var r loadBalancerPoolResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerPool{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancerPool{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -340,7 +338,7 @@ func (api *API) CreateLoadBalancerMonitor(ctx context.Context, monitor LoadBalan } var r loadBalancerMonitorResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerMonitor{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancerMonitor{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -356,7 +354,7 @@ func (api *API) ListLoadBalancerMonitors(ctx context.Context) ([]LoadBalancerMon } var r loadBalancerMonitorListResponse if err := json.Unmarshal(res, &r); err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -372,7 +370,7 @@ func (api *API) LoadBalancerMonitorDetails(ctx context.Context, monitorID string } var r loadBalancerMonitorResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerMonitor{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancerMonitor{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -399,7 +397,7 @@ func (api *API) ModifyLoadBalancerMonitor(ctx context.Context, monitor LoadBalan } var r loadBalancerMonitorResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerMonitor{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancerMonitor{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -415,7 +413,7 @@ func (api *API) CreateLoadBalancer(ctx context.Context, zoneID string, lb LoadBa } var r loadBalancerResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancer{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancer{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -431,7 +429,7 @@ func (api *API) ListLoadBalancers(ctx context.Context, zoneID string) ([]LoadBal } var r loadBalancerListResponse if err := json.Unmarshal(res, &r); err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -447,7 +445,7 @@ func (api *API) LoadBalancerDetails(ctx context.Context, zoneID, lbID string) (L } var r loadBalancerResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancer{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancer{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -474,7 +472,7 @@ func (api *API) ModifyLoadBalancer(ctx context.Context, zoneID string, lb LoadBa } var r loadBalancerResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancer{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancer{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -490,7 +488,7 @@ func (api *API) PoolHealthDetails(ctx context.Context, poolID string) (LoadBalan } var r loadBalancerPoolHealthResponse if err := json.Unmarshal(res, &r); err != nil { - return LoadBalancerPoolHealth{}, errors.Wrap(err, errUnmarshalError) + return LoadBalancerPoolHealth{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/lockdown.go b/lockdown.go index ef17ac8fc48..50009f796fc 100644 --- a/lockdown.go +++ b/lockdown.go @@ -8,8 +8,6 @@ import ( "net/url" "strconv" "time" - - "github.com/pkg/errors" ) // ZoneLockdown represents a Zone Lockdown rule. A rule only permits access to @@ -61,7 +59,7 @@ func (api *API) CreateZoneLockdown(ctx context.Context, zoneID string, ld ZoneLo response := &ZoneLockdownResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -81,7 +79,7 @@ func (api *API) UpdateZoneLockdown(ctx context.Context, zoneID string, id string response := &ZoneLockdownResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -101,7 +99,7 @@ func (api *API) DeleteZoneLockdown(ctx context.Context, zoneID string, id string response := &ZoneLockdownResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -121,7 +119,7 @@ func (api *API) ZoneLockdown(ctx context.Context, zoneID string, id string) (*Zo response := &ZoneLockdownResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -149,7 +147,7 @@ func (api *API) ListZoneLockdowns(ctx context.Context, zoneID string, page int) response := &ZoneLockdownListResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil diff --git a/logpull.go b/logpull.go index 24c401f76e9..b458ac80751 100644 --- a/logpull.go +++ b/logpull.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // LogpullRetentionConfiguration describes a the structure of a Logpull Retention @@ -34,7 +32,7 @@ func (api *API) GetLogpullRetentionFlag(ctx context.Context, zoneID string) (*Lo var r LogpullRetentionConfigurationResponse err = json.Unmarshal(res, &r) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return &r.Result, nil } diff --git a/logpush.go b/logpush.go index 856f2270f71..3c519df60a4 100644 --- a/logpush.go +++ b/logpush.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) // LogpushJob describes a Logpush job. @@ -187,7 +187,7 @@ func (filter *LogpushJobFilter) Validate() error { for i, element := range filter.And { err := element.Validate() if err != nil { - return errors.WithMessagef(err, "element %v in And is invalid", i) + return fmt.Errorf("element %v in And is invalid: %w", i, err) } } return nil @@ -199,7 +199,7 @@ func (filter *LogpushJobFilter) Validate() error { for i, element := range filter.Or { err := element.Validate() if err != nil { - return errors.WithMessagef(err, "element %v in Or is invalid", i) + return fmt.Errorf("element %v in Or is invalid: %w", i, err) } } return nil @@ -252,7 +252,7 @@ func (api *API) createLogpushJob(ctx context.Context, identifierType RouteRoot, var r LogpushJobDetailsResponse err = json.Unmarshal(res, &r) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return &r.Result, nil } @@ -290,7 +290,7 @@ func (api *API) listLogpushJobs(ctx context.Context, identifierType RouteRoot, i var r LogpushJobsResponse err = json.Unmarshal(res, &r) if err != nil { - return []LogpushJob{}, errors.Wrap(err, errUnmarshalError) + return []LogpushJob{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -329,7 +329,7 @@ func (api *API) listLogpushJobsForDataset(ctx context.Context, identifierType Ro var r LogpushJobsResponse err = json.Unmarshal(res, &r) if err != nil { - return []LogpushJob{}, errors.Wrap(err, errUnmarshalError) + return []LogpushJob{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -371,7 +371,7 @@ func (api *API) getLogpushFields(ctx context.Context, identifierType RouteRoot, var r LogpushFieldsResponse err = json.Unmarshal(res, &r) if err != nil { - return LogpushFields{}, errors.Wrap(err, errUnmarshalError) + return LogpushFields{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -409,7 +409,7 @@ func (api *API) getLogpushJob(ctx context.Context, identifierType RouteRoot, ide var r LogpushJobDetailsResponse err = json.Unmarshal(res, &r) if err != nil { - return LogpushJob{}, errors.Wrap(err, errUnmarshalError) + return LogpushJob{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -447,7 +447,7 @@ func (api *API) updateLogpushJob(ctx context.Context, identifierType RouteRoot, var r LogpushJobDetailsResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } @@ -485,7 +485,7 @@ func (api *API) deleteLogpushJob(ctx context.Context, identifierType RouteRoot, var r LogpushJobDetailsResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } @@ -526,7 +526,7 @@ func (api *API) getLogpushOwnershipChallenge(ctx context.Context, identifierType var r LogpushGetOwnershipChallengeResponse err = json.Unmarshal(res, &r) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !r.Result.Valid { @@ -573,7 +573,7 @@ func (api *API) validateLogpushOwnershipChallenge(ctx context.Context, identifie var r LogpushGetOwnershipChallengeResponse err = json.Unmarshal(res, &r) if err != nil { - return false, errors.Wrap(err, errUnmarshalError) + return false, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result.Valid, nil } @@ -614,7 +614,7 @@ func (api *API) checkLogpushDestinationExists(ctx context.Context, identifierTyp var r LogpushDestinationExistsResponse err = json.Unmarshal(res, &r) if err != nil { - return false, errors.Wrap(err, errUnmarshalError) + return false, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result.Exists, nil } diff --git a/magic_firewall_rulesets.go b/magic_firewall_rulesets.go index d17f4f8933e..3423d7e0246 100644 --- a/magic_firewall_rulesets.go +++ b/magic_firewall_rulesets.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) const ( @@ -110,7 +110,7 @@ func (api *API) ListMagicFirewallRulesets(ctx context.Context, accountID string) result := ListMagicFirewallRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []MagicFirewallRuleset{}, errors.Wrap(err, errUnmarshalError) + return []MagicFirewallRuleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -130,7 +130,7 @@ func (api *API) GetMagicFirewallRuleset(ctx context.Context, accountID, ID strin result := GetMagicFirewallRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicFirewallRuleset{}, errors.Wrap(err, errUnmarshalError) + return MagicFirewallRuleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -156,7 +156,7 @@ func (api *API) CreateMagicFirewallRuleset(ctx context.Context, accountID, name, result := CreateMagicFirewallRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicFirewallRuleset{}, errors.Wrap(err, errUnmarshalError) + return MagicFirewallRuleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -178,7 +178,7 @@ func (api *API) DeleteMagicFirewallRuleset(ctx context.Context, accountID, ID st // Firewall API is not implementing the standard response blob but returns an empty response (204) in case // of a success. So we are checking for the response body size here if len(res) > 0 { - return errors.Wrap(errors.New(string(res)), errMakeRequestError) + return fmt.Errorf(errMakeRequestError+": %w", errors.New(string(res))) } return nil @@ -199,7 +199,7 @@ func (api *API) UpdateMagicFirewallRuleset(ctx context.Context, accountID, ID st result := UpdateMagicFirewallRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicFirewallRuleset{}, errors.Wrap(err, errUnmarshalError) + return MagicFirewallRuleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil diff --git a/magic_transit_gre_tunnel.go b/magic_transit_gre_tunnel.go index 76281c790c4..6c7bf6b0c00 100644 --- a/magic_transit_gre_tunnel.go +++ b/magic_transit_gre_tunnel.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) // Magic Transit GRE Tunnel Error messages. @@ -89,7 +89,7 @@ func (api *API) ListMagicTransitGRETunnels(ctx context.Context, accountID string result := ListMagicTransitGRETunnelsResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitGRETunnel{}, errors.Wrap(err, errUnmarshalError) + return []MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.GRETunnels, nil @@ -107,7 +107,7 @@ func (api *API) GetMagicTransitGRETunnel(ctx context.Context, accountID string, result := GetMagicTransitGRETunnelResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitGRETunnel{}, errors.Wrap(err, errUnmarshalError) + return MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.GRETunnel, nil @@ -128,7 +128,7 @@ func (api *API) CreateMagicTransitGRETunnels(ctx context.Context, accountID stri result := ListMagicTransitGRETunnelsResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitGRETunnel{}, errors.Wrap(err, errUnmarshalError) + return []MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.GRETunnels, nil @@ -147,7 +147,7 @@ func (api *API) UpdateMagicTransitGRETunnel(ctx context.Context, accountID strin result := UpdateMagicTransitGRETunnelResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitGRETunnel{}, errors.Wrap(err, errUnmarshalError) + return MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !result.Result.Modified { @@ -170,7 +170,7 @@ func (api *API) DeleteMagicTransitGRETunnel(ctx context.Context, accountID strin result := DeleteMagicTransitGRETunnelResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitGRETunnel{}, errors.Wrap(err, errUnmarshalError) + return MagicTransitGRETunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !result.Result.Deleted { diff --git a/magic_transit_ipsec_tunnel.go b/magic_transit_ipsec_tunnel.go index 4824e612352..1caecfd003e 100644 --- a/magic_transit_ipsec_tunnel.go +++ b/magic_transit_ipsec_tunnel.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) // Magic Transit IPsec Tunnel Error messages. @@ -104,7 +104,7 @@ func (api *API) ListMagicTransitIPsecTunnels(ctx context.Context, accountID stri result := ListMagicTransitIPsecTunnelsResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitIPsecTunnel{}, errors.Wrap(err, errUnmarshalError) + return []MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.IPsecTunnels, nil @@ -122,7 +122,7 @@ func (api *API) GetMagicTransitIPsecTunnel(ctx context.Context, accountID string result := GetMagicTransitIPsecTunnelResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitIPsecTunnel{}, errors.Wrap(err, errUnmarshalError) + return MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.IPsecTunnel, nil @@ -143,7 +143,7 @@ func (api *API) CreateMagicTransitIPsecTunnels(ctx context.Context, accountID st result := ListMagicTransitIPsecTunnelsResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitIPsecTunnel{}, errors.Wrap(err, errUnmarshalError) + return []MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.IPsecTunnels, nil @@ -162,7 +162,7 @@ func (api *API) UpdateMagicTransitIPsecTunnel(ctx context.Context, accountID str result := UpdateMagicTransitIPsecTunnelResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitIPsecTunnel{}, errors.Wrap(err, errUnmarshalError) + return MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !result.Result.Modified { @@ -185,7 +185,7 @@ func (api *API) DeleteMagicTransitIPsecTunnel(ctx context.Context, accountID str result := DeleteMagicTransitIPsecTunnelResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitIPsecTunnel{}, errors.Wrap(err, errUnmarshalError) + return MagicTransitIPsecTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !result.Result.Deleted { @@ -208,7 +208,7 @@ func (api *API) GenerateMagicTransitIPsecTunnelPSK(ctx context.Context, accountI result := GenerateMagicTransitIPsecTunnelPSKResponse{} if err := json.Unmarshal(res, &result); err != nil { - return "", nil, errors.Wrap(err, errUnmarshalError) + return "", nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.Psk, result.Result.PskMetadata, nil diff --git a/magic_transit_static_routes.go b/magic_transit_static_routes.go index f08638c029f..adf62ebec38 100644 --- a/magic_transit_static_routes.go +++ b/magic_transit_static_routes.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) // Magic Transit Static Routes Error messages. @@ -86,7 +86,7 @@ func (api *API) ListMagicTransitStaticRoutes(ctx context.Context, accountID stri result := ListMagicTransitStaticRoutesResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitStaticRoute{}, errors.Wrap(err, errUnmarshalError) + return []MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.Routes, nil @@ -104,7 +104,7 @@ func (api *API) GetMagicTransitStaticRoute(ctx context.Context, accountID, ID st result := GetMagicTransitStaticRouteResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitStaticRoute{}, errors.Wrap(err, errUnmarshalError) + return MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.Route, nil @@ -127,7 +127,7 @@ func (api *API) CreateMagicTransitStaticRoute(ctx context.Context, accountID str result := ListMagicTransitStaticRoutesResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []MagicTransitStaticRoute{}, errors.Wrap(err, errUnmarshalError) + return []MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.Routes, nil @@ -146,7 +146,7 @@ func (api *API) UpdateMagicTransitStaticRoute(ctx context.Context, accountID, ID result := UpdateMagicTransitStaticRouteResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitStaticRoute{}, errors.Wrap(err, errUnmarshalError) + return MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !result.Result.Modified { @@ -169,7 +169,7 @@ func (api *API) DeleteMagicTransitStaticRoute(ctx context.Context, accountID, ID result := DeleteMagicTransitStaticRouteResponse{} if err := json.Unmarshal(res, &result); err != nil { - return MagicTransitStaticRoute{}, errors.Wrap(err, errUnmarshalError) + return MagicTransitStaticRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !result.Result.Deleted { diff --git a/managed_headers.go b/managed_headers.go index 60a00bdca93..d696ea3b0cc 100644 --- a/managed_headers.go +++ b/managed_headers.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) type ListManagedHeadersResponse struct { @@ -49,7 +47,7 @@ func (api *API) ListZoneManagedHeaders(ctx context.Context, params ListManagedHe result := ListManagedHeadersResponse{} if err := json.Unmarshal(res, &result); err != nil { - return ManagedHeaders{}, errors.Wrap(err, errUnmarshalError) + return ManagedHeaders{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -74,7 +72,7 @@ func (api *API) UpdateZoneManagedHeaders(ctx context.Context, params UpdateManag result := ListManagedHeadersResponse{} if err := json.Unmarshal(res, &result); err != nil { - return ManagedHeaders{}, errors.Wrap(err, errUnmarshalError) + return ManagedHeaders{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil diff --git a/origin_ca.go b/origin_ca.go index 94bc2536a05..7e83a3e6a1e 100644 --- a/origin_ca.go +++ b/origin_ca.go @@ -9,7 +9,7 @@ import ( "net/url" "time" - "github.com/pkg/errors" + "errors" ) // OriginCACertificate represents a Cloudflare-issued certificate. @@ -105,7 +105,7 @@ func (api *API) CreateOriginCertificate(ctx context.Context, certificate OriginC err = json.Unmarshal(res, &originResponse) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !originResponse.Success { @@ -137,7 +137,7 @@ func (api *API) OriginCertificates(ctx context.Context, options OriginCACertific err = json.Unmarshal(res, &originResponse) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !originResponse.Success { @@ -165,7 +165,7 @@ func (api *API) OriginCertificate(ctx context.Context, certificateID string) (*O err = json.Unmarshal(res, &originResponse) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !originResponse.Success { @@ -193,7 +193,7 @@ func (api *API) RevokeOriginCertificate(ctx context.Context, certificateID strin err = json.Unmarshal(res, &originResponse) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !originResponse.Success { @@ -218,7 +218,7 @@ func OriginCARootCertificate(algorithm string) ([]byte, error) { resp, err := http.Get(url) //nolint:gosec if err != nil { - return nil, errors.Wrap(err, "HTTP request failed") + return nil, fmt.Errorf("HTTP request failed: %w", err) } defer resp.Body.Close() @@ -228,7 +228,7 @@ func OriginCARootCertificate(algorithm string) ([]byte, error) { body, err := ioutil.ReadAll(resp.Body) if err != nil { - return nil, errors.Wrap(err, "Response body could not be read") + return nil, fmt.Errorf("Response body could not be read: %w", err) } return body, nil diff --git a/page_rules.go b/page_rules.go index f345b646efe..cb32bc27267 100644 --- a/page_rules.go +++ b/page_rules.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // PageRuleTarget is the target to evaluate on a request. @@ -147,7 +145,7 @@ func (api *API) CreatePageRule(ctx context.Context, zoneID string, rule PageRule var r PageRuleDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return &r.Result, nil } @@ -164,7 +162,7 @@ func (api *API) ListPageRules(ctx context.Context, zoneID string) ([]PageRule, e var r PageRulesResponse err = json.Unmarshal(res, &r) if err != nil { - return []PageRule{}, errors.Wrap(err, errUnmarshalError) + return []PageRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -181,7 +179,7 @@ func (api *API) PageRule(ctx context.Context, zoneID, ruleID string) (PageRule, var r PageRuleDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return PageRule{}, errors.Wrap(err, errUnmarshalError) + return PageRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -199,7 +197,7 @@ func (api *API) ChangePageRule(ctx context.Context, zoneID, ruleID string, rule var r PageRuleDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } @@ -217,7 +215,7 @@ func (api *API) UpdatePageRule(ctx context.Context, zoneID, ruleID string, rule var r PageRuleDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } @@ -234,7 +232,7 @@ func (api *API) DeletePageRule(ctx context.Context, zoneID, ruleID string) error var r PageRuleDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } diff --git a/pages_deployment.go b/pages_deployment.go index ab643f2941f..1d5838b678d 100644 --- a/pages_deployment.go +++ b/pages_deployment.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) // SizeOptions can be passed to a list request to configure size and cursor location. @@ -155,7 +155,7 @@ func (api *API) ListPagesDeployments(ctx context.Context, params ListPagesDeploy var r pagesDeploymentListResponse err = json.Unmarshal(res, &r) if err != nil { - return []PagesProjectDeployment{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []PagesProjectDeployment{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, r.ResultInfo, nil } @@ -185,7 +185,7 @@ func (api *API) GetPagesDeploymentInfo(ctx context.Context, params GetPagesDeplo var r pagesDeploymentResponse err = json.Unmarshal(res, &r) if err != nil { - return PagesProjectDeployment{}, errors.Wrap(err, errUnmarshalError) + return PagesProjectDeployment{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -224,7 +224,7 @@ func (api *API) GetPagesDeploymentStageLogs(ctx context.Context, params GetPages var r pagesDeploymentStageLogsResponse err = json.Unmarshal(res, &r) if err != nil { - return PagesDeploymentStageLogs{}, errors.Wrap(err, errUnmarshalError) + return PagesDeploymentStageLogs{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -257,7 +257,7 @@ func (api *API) GetPagesDeploymentLogs(ctx context.Context, params GetPagesDeplo var r pagesDeploymentLogsResponse err = json.Unmarshal(res, &r) if err != nil { - return PagesDeploymentLogs{}, errors.Wrap(err, errUnmarshalError) + return PagesDeploymentLogs{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -308,7 +308,7 @@ func (api *API) CreatePagesDeployment(ctx context.Context, params CreatePagesDep var r pagesDeploymentResponse err = json.Unmarshal(res, &r) if err != nil { - return PagesProjectDeployment{}, errors.Wrap(err, errUnmarshalError) + return PagesProjectDeployment{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -338,7 +338,7 @@ func (api *API) RetryPagesDeployment(ctx context.Context, params RetryPagesDeplo var r pagesDeploymentResponse err = json.Unmarshal(res, &r) if err != nil { - return PagesProjectDeployment{}, errors.Wrap(err, errUnmarshalError) + return PagesProjectDeployment{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -368,7 +368,7 @@ func (api *API) RollbackPagesDeployment(ctx context.Context, params RollbackPage var r pagesDeploymentResponse err = json.Unmarshal(res, &r) if err != nil { - return PagesProjectDeployment{}, errors.Wrap(err, errUnmarshalError) + return PagesProjectDeployment{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/pages_project.go b/pages_project.go index a03f2ce495b..1873fbb8f9c 100644 --- a/pages_project.go +++ b/pages_project.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // PagesProject represents a Pages project. @@ -128,7 +126,7 @@ func (api *API) ListPagesProjects(ctx context.Context, accountID string, pageOpt var r pagesProjectListResponse err = json.Unmarshal(res, &r) if err != nil { - return []PagesProject{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []PagesProject{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, r.ResultInfo, nil } @@ -145,7 +143,7 @@ func (api *API) PagesProject(ctx context.Context, accountID, projectName string) var r pagesProjectResponse err = json.Unmarshal(res, &r) if err != nil { - return PagesProject{}, errors.Wrap(err, errUnmarshalError) + return PagesProject{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -162,7 +160,7 @@ func (api *API) CreatePagesProject(ctx context.Context, accountID string, pagesP var r pagesProjectResponse err = json.Unmarshal(res, &r) if err != nil { - return PagesProject{}, errors.Wrap(err, errUnmarshalError) + return PagesProject{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -179,7 +177,7 @@ func (api *API) UpdatePagesProject(ctx context.Context, accountID, projectName s var r pagesProjectResponse err = json.Unmarshal(res, &r) if err != nil { - return PagesProject{}, errors.Wrap(err, errUnmarshalError) + return PagesProject{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -196,7 +194,7 @@ func (api *API) DeletePagesProject(ctx context.Context, accountID, projectName s var r pagesProjectResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } diff --git a/railgun.go b/railgun.go index b85e0336f1f..e189124131b 100644 --- a/railgun.go +++ b/railgun.go @@ -7,8 +7,6 @@ import ( "net/http" "net/url" "time" - - "github.com/pkg/errors" ) // Railgun represents a Railgun's properties. @@ -64,7 +62,7 @@ func (api *API) CreateRailgun(ctx context.Context, name string) (Railgun, error) } var r railgunResponse if err := json.Unmarshal(res, &r); err != nil { - return Railgun{}, errors.Wrap(err, errUnmarshalError) + return Railgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -84,7 +82,7 @@ func (api *API) ListRailguns(ctx context.Context, options RailgunListOptions) ([ } var r railgunsResponse if err := json.Unmarshal(res, &r); err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -100,7 +98,7 @@ func (api *API) RailgunDetails(ctx context.Context, railgunID string) (Railgun, } var r railgunResponse if err := json.Unmarshal(res, &r); err != nil { - return Railgun{}, errors.Wrap(err, errUnmarshalError) + return Railgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -116,7 +114,7 @@ func (api *API) RailgunZones(ctx context.Context, railgunID string) ([]Zone, err } var r ZonesResponse if err := json.Unmarshal(res, &r); err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -137,7 +135,7 @@ func (api *API) enableRailgun(ctx context.Context, railgunID string, enable bool } var r railgunResponse if err := json.Unmarshal(res, &r); err != nil { - return Railgun{}, errors.Wrap(err, errUnmarshalError) + return Railgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -227,7 +225,7 @@ func (api *API) ZoneRailguns(ctx context.Context, zoneID string) ([]ZoneRailgun, } var r zoneRailgunsResponse if err := json.Unmarshal(res, &r); err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -243,7 +241,7 @@ func (api *API) ZoneRailgunDetails(ctx context.Context, zoneID, railgunID string } var r zoneRailgunResponse if err := json.Unmarshal(res, &r); err != nil { - return ZoneRailgun{}, errors.Wrap(err, errUnmarshalError) + return ZoneRailgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -259,7 +257,7 @@ func (api *API) TestRailgunConnection(ctx context.Context, zoneID, railgunID str } var r railgunDiagnosisResponse if err := json.Unmarshal(res, &r); err != nil { - return RailgunDiagnosis{}, errors.Wrap(err, errUnmarshalError) + return RailgunDiagnosis{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -280,7 +278,7 @@ func (api *API) connectZoneRailgun(ctx context.Context, zoneID, railgunID string } var r zoneRailgunResponse if err := json.Unmarshal(res, &r); err != nil { - return ZoneRailgun{}, errors.Wrap(err, errUnmarshalError) + return ZoneRailgun{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/rate_limiting.go b/rate_limiting.go index d8fcc798d1b..d40ae731189 100644 --- a/rate_limiting.go +++ b/rate_limiting.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // RateLimit is a policy than can be applied to limit traffic within a customer domain. @@ -96,7 +94,7 @@ func (api *API) CreateRateLimit(ctx context.Context, zoneID string, limit RateLi } var r rateLimitResponse if err := json.Unmarshal(res, &r); err != nil { - return RateLimit{}, errors.Wrap(err, errUnmarshalError) + return RateLimit{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -115,7 +113,7 @@ func (api *API) ListRateLimits(ctx context.Context, zoneID string, pageOpts Pagi var r rateLimitListResponse err = json.Unmarshal(res, &r) if err != nil { - return []RateLimit{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []RateLimit{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, r.ResultInfo, nil } @@ -161,7 +159,7 @@ func (api *API) RateLimit(ctx context.Context, zoneID, limitID string) (RateLimi var r rateLimitResponse err = json.Unmarshal(res, &r) if err != nil { - return RateLimit{}, errors.Wrap(err, errUnmarshalError) + return RateLimit{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -177,7 +175,7 @@ func (api *API) UpdateRateLimit(ctx context.Context, zoneID, limitID string, lim } var r rateLimitResponse if err := json.Unmarshal(res, &r); err != nil { - return RateLimit{}, errors.Wrap(err, errUnmarshalError) + return RateLimit{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -194,7 +192,7 @@ func (api *API) DeleteRateLimit(ctx context.Context, zoneID, limitID string) err var r rateLimitResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } diff --git a/registrar.go b/registrar.go index 76fd7bf6cff..e0a210f010e 100644 --- a/registrar.go +++ b/registrar.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // RegistrarDomain is the structure of the API response for a new @@ -93,7 +91,7 @@ func (api *API) RegistrarDomain(ctx context.Context, accountID, domainName strin var r RegistrarDomainDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + return RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -113,7 +111,7 @@ func (api *API) RegistrarDomains(ctx context.Context, accountID string) ([]Regis var r RegistrarDomainsDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return []RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + return []RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -133,7 +131,7 @@ func (api *API) TransferRegistrarDomain(ctx context.Context, accountID, domainNa var r RegistrarDomainsDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return []RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + return []RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -152,7 +150,7 @@ func (api *API) CancelRegistrarDomainTransfer(ctx context.Context, accountID, do var r RegistrarDomainsDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return []RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + return []RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -171,7 +169,7 @@ func (api *API) UpdateRegistrarDomain(ctx context.Context, accountID, domainName var r RegistrarDomainDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + return RegistrarDomain{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/rulesets.go b/rulesets.go index aefa66f1ad1..e2925b27903 100644 --- a/rulesets.go +++ b/rulesets.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) const ( @@ -487,7 +487,7 @@ func (api *API) listRulesets(ctx context.Context, identifierType RouteRoot, iden result := ListRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []Ruleset{}, errors.Wrap(err, errUnmarshalError) + return []Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -518,7 +518,7 @@ func (api *API) getRuleset(ctx context.Context, identifierType RouteRoot, identi result := GetRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, errors.Wrap(err, errUnmarshalError) + return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -547,7 +547,7 @@ func (api *API) createRuleset(ctx context.Context, identifierType RouteRoot, ide result := CreateRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, errors.Wrap(err, errUnmarshalError) + return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -579,7 +579,7 @@ func (api *API) deleteRuleset(ctx context.Context, identifierType RouteRoot, ide // empty response (204) in case of a success. So we are checking for the // response body size here. if len(res) > 0 { - return errors.Wrap(errors.New(string(res)), errMakeRequestError) + return fmt.Errorf(errMakeRequestError+": %w", errors.New(string(res))) } return nil @@ -610,7 +610,7 @@ func (api *API) updateRuleset(ctx context.Context, identifierType RouteRoot, ide result := UpdateRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, errors.Wrap(err, errUnmarshalError) + return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -641,7 +641,7 @@ func (api *API) getRulesetPhase(ctx context.Context, identifierType RouteRoot, i result := GetRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, errors.Wrap(err, errUnmarshalError) + return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -672,7 +672,7 @@ func (api *API) updateRulesetPhase(ctx context.Context, identifierType RouteRoot result := GetRulesetResponse{} if err := json.Unmarshal(res, &result); err != nil { - return Ruleset{}, errors.Wrap(err, errUnmarshalError) + return Ruleset{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil diff --git a/secondary_dns_primaries.go b/secondary_dns_primaries.go index dc0b57a49dd..7a81acfa9f4 100644 --- a/secondary_dns_primaries.go +++ b/secondary_dns_primaries.go @@ -6,7 +6,7 @@ import ( "fmt" "net/http" - "github.com/pkg/errors" + "errors" ) const ( @@ -53,7 +53,7 @@ func (api *API) GetSecondaryDNSPrimary(ctx context.Context, accountID, primaryID var r SecondaryDNSPrimaryDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return SecondaryDNSPrimary{}, errors.Wrap(err, errUnmarshalError) + return SecondaryDNSPrimary{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -72,7 +72,7 @@ func (api *API) ListSecondaryDNSPrimaries(ctx context.Context, accountID string) var r SecondaryDNSPrimaryListResponse err = json.Unmarshal(res, &r) if err != nil { - return []SecondaryDNSPrimary{}, errors.Wrap(err, errUnmarshalError) + return []SecondaryDNSPrimary{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -101,7 +101,7 @@ func (api *API) CreateSecondaryDNSPrimary(ctx context.Context, accountID string, var r SecondaryDNSPrimaryDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return SecondaryDNSPrimary{}, errors.Wrap(err, errUnmarshalError) + return SecondaryDNSPrimary{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -133,7 +133,7 @@ func (api *API) UpdateSecondaryDNSPrimary(ctx context.Context, accountID string, var r SecondaryDNSPrimaryDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return SecondaryDNSPrimary{}, errors.Wrap(err, errUnmarshalError) + return SecondaryDNSPrimary{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/secondary_dns_tsig.go b/secondary_dns_tsig.go index 255c409b03c..71d8456b8ae 100644 --- a/secondary_dns_tsig.go +++ b/secondary_dns_tsig.go @@ -6,7 +6,7 @@ import ( "fmt" "net/http" - "github.com/pkg/errors" + "errors" ) const ( @@ -49,7 +49,7 @@ func (api *API) GetSecondaryDNSTSIG(ctx context.Context, accountID, tsigID strin var r SecondaryDNSTSIGDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return SecondaryDNSTSIG{}, errors.Wrap(err, errUnmarshalError) + return SecondaryDNSTSIG{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -69,7 +69,7 @@ func (api *API) ListSecondaryDNSTSIGs(ctx context.Context, accountID string) ([] var r SecondaryDNSTSIGListResponse err = json.Unmarshal(res, &r) if err != nil { - return []SecondaryDNSTSIG{}, errors.Wrap(err, errUnmarshalError) + return []SecondaryDNSTSIG{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -87,7 +87,7 @@ func (api *API) CreateSecondaryDNSTSIG(ctx context.Context, accountID string, ts result := SecondaryDNSTSIGDetailResponse{} if err := json.Unmarshal(res, &result); err != nil { - return SecondaryDNSTSIG{}, errors.Wrap(err, errUnmarshalError) + return SecondaryDNSTSIG{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -111,7 +111,7 @@ func (api *API) UpdateSecondaryDNSTSIG(ctx context.Context, accountID string, ts result := SecondaryDNSTSIGDetailResponse{} if err := json.Unmarshal(res, &result); err != nil { - return SecondaryDNSTSIG{}, errors.Wrap(err, errUnmarshalError) + return SecondaryDNSTSIG{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil diff --git a/secondary_dns_zone.go b/secondary_dns_zone.go index 034defc9f8f..41ee823f11a 100644 --- a/secondary_dns_zone.go +++ b/secondary_dns_zone.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) const ( @@ -57,7 +57,7 @@ func (api *API) GetSecondaryDNSZone(ctx context.Context, zoneID string) (Seconda var r SecondaryDNSZoneDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return SecondaryDNSZone{}, errors.Wrap(err, errUnmarshalError) + return SecondaryDNSZone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -85,7 +85,7 @@ func (api *API) CreateSecondaryDNSZone(ctx context.Context, zoneID string, zone result := SecondaryDNSZoneDetailResponse{} if err := json.Unmarshal(res, &result); err != nil { - return SecondaryDNSZone{}, errors.Wrap(err, errUnmarshalError) + return SecondaryDNSZone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -114,7 +114,7 @@ func (api *API) UpdateSecondaryDNSZone(ctx context.Context, zoneID string, zone result := SecondaryDNSZoneDetailResponse{} if err := json.Unmarshal(res, &result); err != nil { - return SecondaryDNSZone{}, errors.Wrap(err, errUnmarshalError) + return SecondaryDNSZone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result, nil @@ -147,7 +147,7 @@ func (api *API) ForceSecondaryDNSZoneAXFR(ctx context.Context, zoneID string) er result := SecondaryDNSZoneAXFRResponse{} if err := json.Unmarshal(res, &result); err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil diff --git a/spectrum.go b/spectrum.go index 641ec1d03c4..949813a7579 100644 --- a/spectrum.go +++ b/spectrum.go @@ -10,7 +10,7 @@ import ( "strings" "time" - "github.com/pkg/errors" + "errors" ) // ProxyProtocol implements json.Unmarshaler in order to support deserializing of the deprecated boolean @@ -275,7 +275,7 @@ func (api *API) SpectrumApplications(ctx context.Context, zoneID string) ([]Spec var spectrumApplications SpectrumApplicationsDetailResponse err = json.Unmarshal(res, &spectrumApplications) if err != nil { - return []SpectrumApplication{}, errors.Wrap(err, errUnmarshalError) + return []SpectrumApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return spectrumApplications.Result, nil @@ -299,7 +299,7 @@ func (api *API) SpectrumApplication(ctx context.Context, zoneID string, applicat var spectrumApplication SpectrumApplicationDetailResponse err = json.Unmarshal(res, &spectrumApplication) if err != nil { - return SpectrumApplication{}, errors.Wrap(err, errUnmarshalError) + return SpectrumApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return spectrumApplication.Result, nil @@ -319,7 +319,7 @@ func (api *API) CreateSpectrumApplication(ctx context.Context, zoneID string, ap var spectrumApplication SpectrumApplicationDetailResponse err = json.Unmarshal(res, &spectrumApplication) if err != nil { - return SpectrumApplication{}, errors.Wrap(err, errUnmarshalError) + return SpectrumApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return spectrumApplication.Result, nil @@ -343,7 +343,7 @@ func (api *API) UpdateSpectrumApplication(ctx context.Context, zoneID, appID str var spectrumApplication SpectrumApplicationDetailResponse err = json.Unmarshal(res, &spectrumApplication) if err != nil { - return SpectrumApplication{}, errors.Wrap(err, errUnmarshalError) + return SpectrumApplication{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return spectrumApplication.Result, nil diff --git a/split_tunnel.go b/split_tunnel.go index 04a34bedcc3..21d9297c6df 100644 --- a/split_tunnel.go +++ b/split_tunnel.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // SplitTunnelResponse represents the response from the get split @@ -38,7 +36,7 @@ func (api *API) ListSplitTunnels(ctx context.Context, accountID string, mode str var splitTunnelResponse SplitTunnelResponse err = json.Unmarshal(res, &splitTunnelResponse) if err != nil { - return []SplitTunnel{}, errors.Wrap(err, errUnmarshalError) + return []SplitTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return splitTunnelResponse.Result, nil @@ -59,7 +57,7 @@ func (api *API) UpdateSplitTunnel(ctx context.Context, accountID string, mode st var splitTunnelResponse SplitTunnelResponse err = json.Unmarshal(res, &splitTunnelResponse) if err != nil { - return []SplitTunnel{}, errors.Wrap(err, errUnmarshalError) + return []SplitTunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return splitTunnelResponse.Result, nil diff --git a/ssl.go b/ssl.go index c5fb60f5b88..125ab02ac8b 100644 --- a/ssl.go +++ b/ssl.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // ZoneCustomSSL represents custom SSL certificate metadata. @@ -73,7 +71,7 @@ func (api *API) CreateSSL(ctx context.Context, zoneID string, options ZoneCustom } var r zoneCustomSSLResponse if err := json.Unmarshal(res, &r); err != nil { - return ZoneCustomSSL{}, errors.Wrap(err, errUnmarshalError) + return ZoneCustomSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -89,7 +87,7 @@ func (api *API) ListSSL(ctx context.Context, zoneID string) ([]ZoneCustomSSL, er } var r zoneCustomSSLsResponse if err := json.Unmarshal(res, &r); err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -105,7 +103,7 @@ func (api *API) SSLDetails(ctx context.Context, zoneID, certificateID string) (Z } var r zoneCustomSSLResponse if err := json.Unmarshal(res, &r); err != nil { - return ZoneCustomSSL{}, errors.Wrap(err, errUnmarshalError) + return ZoneCustomSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -121,7 +119,7 @@ func (api *API) UpdateSSL(ctx context.Context, zoneID, certificateID string, opt } var r zoneCustomSSLResponse if err := json.Unmarshal(res, &r); err != nil { - return ZoneCustomSSL{}, errors.Wrap(err, errUnmarshalError) + return ZoneCustomSSL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -143,7 +141,7 @@ func (api *API) ReprioritizeSSL(ctx context.Context, zoneID string, p []ZoneCust } var r zoneCustomSSLsResponse if err := json.Unmarshal(res, &r); err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/stream.go b/stream.go index b4908308015..9529c4025e4 100644 --- a/stream.go +++ b/stream.go @@ -4,8 +4,8 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" - "github.com/pkg/errors" "io" "mime/multipart" "net/http" diff --git a/stream_test.go b/stream_test.go index 2211d897725..094d794d05b 100644 --- a/stream_test.go +++ b/stream_test.go @@ -3,11 +3,12 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "net/http" "testing" "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) const ( diff --git a/teams_accounts.go b/teams_accounts.go index d4ec553ca0f..04ed8df9bba 100644 --- a/teams_accounts.go +++ b/teams_accounts.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) type TeamsAccount struct { @@ -124,7 +122,7 @@ func (api *API) TeamsAccount(ctx context.Context, accountID string) (TeamsAccoun var teamsAccountResponse TeamsAccountResponse err = json.Unmarshal(res, &teamsAccountResponse) if err != nil { - return TeamsAccount{}, errors.Wrap(err, errUnmarshalError) + return TeamsAccount{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsAccountResponse.Result, nil @@ -144,7 +142,7 @@ func (api *API) TeamsAccountConfiguration(ctx context.Context, accountID string) var teamsConfigResponse TeamsConfigResponse err = json.Unmarshal(res, &teamsConfigResponse) if err != nil { - return TeamsConfiguration{}, errors.Wrap(err, errUnmarshalError) + return TeamsConfiguration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsConfigResponse.Result, nil @@ -164,7 +162,7 @@ func (api *API) TeamsAccountDeviceConfiguration(ctx context.Context, accountID s var teamsDeviceResponse TeamsDeviceSettingsResponse err = json.Unmarshal(res, &teamsDeviceResponse) if err != nil { - return TeamsDeviceSettings{}, errors.Wrap(err, errUnmarshalError) + return TeamsDeviceSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsDeviceResponse.Result, nil @@ -184,7 +182,7 @@ func (api *API) TeamsAccountLoggingConfiguration(ctx context.Context, accountID var teamsConfigResponse TeamsLoggingSettingsResponse err = json.Unmarshal(res, &teamsConfigResponse) if err != nil { - return TeamsLoggingSettings{}, errors.Wrap(err, errUnmarshalError) + return TeamsLoggingSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsConfigResponse.Result, nil @@ -204,7 +202,7 @@ func (api *API) TeamsAccountUpdateConfiguration(ctx context.Context, accountID s var teamsConfigResponse TeamsConfigResponse err = json.Unmarshal(res, &teamsConfigResponse) if err != nil { - return TeamsConfiguration{}, errors.Wrap(err, errUnmarshalError) + return TeamsConfiguration{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsConfigResponse.Result, nil @@ -224,7 +222,7 @@ func (api *API) TeamsAccountUpdateLoggingConfiguration(ctx context.Context, acco var teamsConfigResponse TeamsLoggingSettingsResponse err = json.Unmarshal(res, &teamsConfigResponse) if err != nil { - return TeamsLoggingSettings{}, errors.Wrap(err, errUnmarshalError) + return TeamsLoggingSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsConfigResponse.Result, nil @@ -244,7 +242,7 @@ func (api *API) TeamsAccountDeviceUpdateConfiguration(ctx context.Context, accou var teamsDeviceResponse TeamsDeviceSettingsResponse err = json.Unmarshal(res, &teamsDeviceResponse) if err != nil { - return TeamsDeviceSettings{}, errors.Wrap(err, errUnmarshalError) + return TeamsDeviceSettings{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsDeviceResponse.Result, nil diff --git a/teams_devices.go b/teams_devices.go index e97f2ec295f..2e20e824f90 100644 --- a/teams_devices.go +++ b/teams_devices.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) type TeamsDevicesList struct { @@ -59,7 +57,7 @@ func (api *API) ListTeamsDevices(ctx context.Context, accountID string) ([]Teams var response TeamsDevicesList err = json.Unmarshal(res, &response) if err != nil { - return []TeamsDeviceListItem{}, errors.Wrap(err, errUnmarshalError) + return []TeamsDeviceListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil @@ -78,7 +76,7 @@ func (api *API) RevokeTeamsDevices(ctx context.Context, accountID string, device result := Response{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -98,7 +96,7 @@ func (api *API) GetTeamsDeviceDetails(ctx context.Context, accountID string, dev var response TeamsDeviceDetail err = json.Unmarshal(res, &response) if err != nil { - return TeamsDeviceListItem{}, errors.Wrap(err, errUnmarshalError) + return TeamsDeviceListItem{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil diff --git a/teams_list.go b/teams_list.go index 93b829d4e77..ec1f18bc46c 100644 --- a/teams_list.go +++ b/teams_list.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) var ErrMissingListID = errors.New("required missing list ID") @@ -81,7 +81,7 @@ func (api *API) TeamsLists(ctx context.Context, accountID string) ([]TeamsList, var teamsListListResponse TeamsListListResponse err = json.Unmarshal(res, &teamsListListResponse) if err != nil { - return []TeamsList{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []TeamsList{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsListListResponse.Result, teamsListListResponse.ResultInfo, nil @@ -106,7 +106,7 @@ func (api *API) TeamsList(ctx context.Context, accountID, listID string) (TeamsL var teamsListDetailResponse TeamsListDetailResponse err = json.Unmarshal(res, &teamsListDetailResponse) if err != nil { - return TeamsList{}, errors.Wrap(err, errUnmarshalError) + return TeamsList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsListDetailResponse.Result, nil @@ -137,7 +137,7 @@ func (api *API) TeamsListItems(ctx context.Context, params TeamsListItemsParams) var teamsListItemsListResponse TeamsListItemsListResponse err = json.Unmarshal(res, &teamsListItemsListResponse) if err != nil { - return []TeamsListItem{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []TeamsListItem{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsListItemsListResponse.Result, teamsListItemsListResponse.ResultInfo, nil @@ -157,7 +157,7 @@ func (api *API) CreateTeamsList(ctx context.Context, accountID string, teamsList var teamsListDetailResponse TeamsListDetailResponse err = json.Unmarshal(res, &teamsListDetailResponse) if err != nil { - return TeamsList{}, errors.Wrap(err, errUnmarshalError) + return TeamsList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsListDetailResponse.Result, nil @@ -168,7 +168,7 @@ func (api *API) CreateTeamsList(ctx context.Context, accountID string, teamsList // API reference: https://api.cloudflare.com/#teams-lists-update-teams-list func (api *API) UpdateTeamsList(ctx context.Context, accountID string, teamsList TeamsList) (TeamsList, error) { if teamsList.ID == "" { - return TeamsList{}, errors.Errorf("teams list ID cannot be empty") + return TeamsList{}, fmt.Errorf("teams list ID cannot be empty") } uri := fmt.Sprintf( @@ -186,7 +186,7 @@ func (api *API) UpdateTeamsList(ctx context.Context, accountID string, teamsList var teamsListDetailResponse TeamsListDetailResponse err = json.Unmarshal(res, &teamsListDetailResponse) if err != nil { - return TeamsList{}, errors.Wrap(err, errUnmarshalError) + return TeamsList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsListDetailResponse.Result, nil @@ -197,7 +197,7 @@ func (api *API) UpdateTeamsList(ctx context.Context, accountID string, teamsList // API reference: https://api.cloudflare.com/#teams-lists-patch-teams-list func (api *API) PatchTeamsList(ctx context.Context, accountID string, listPatch PatchTeamsList) (TeamsList, error) { if listPatch.ID == "" { - return TeamsList{}, errors.Errorf("teams list ID cannot be empty") + return TeamsList{}, fmt.Errorf("teams list ID cannot be empty") } uri := fmt.Sprintf( @@ -215,7 +215,7 @@ func (api *API) PatchTeamsList(ctx context.Context, accountID string, listPatch var teamsListDetailResponse TeamsListDetailResponse err = json.Unmarshal(res, &teamsListDetailResponse) if err != nil { - return TeamsList{}, errors.Wrap(err, errUnmarshalError) + return TeamsList{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsListDetailResponse.Result, nil diff --git a/teams_locations.go b/teams_locations.go index b6b95a49f16..dab63b5c970 100644 --- a/teams_locations.go +++ b/teams_locations.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) type TeamsLocationsListResponse struct { @@ -55,7 +53,7 @@ func (api *API) TeamsLocations(ctx context.Context, accountID string) ([]TeamsLo var teamsLocationsListResponse TeamsLocationsListResponse err = json.Unmarshal(res, &teamsLocationsListResponse) if err != nil { - return []TeamsLocation{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []TeamsLocation{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsLocationsListResponse.Result, teamsLocationsListResponse.ResultInfo, nil @@ -80,7 +78,7 @@ func (api *API) TeamsLocation(ctx context.Context, accountID, locationID string) var teamsLocationDetailResponse TeamsLocationDetailResponse err = json.Unmarshal(res, &teamsLocationDetailResponse) if err != nil { - return TeamsLocation{}, errors.Wrap(err, errUnmarshalError) + return TeamsLocation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsLocationDetailResponse.Result, nil @@ -100,7 +98,7 @@ func (api *API) CreateTeamsLocation(ctx context.Context, accountID string, teams var teamsLocationDetailResponse TeamsLocationDetailResponse err = json.Unmarshal(res, &teamsLocationDetailResponse) if err != nil { - return TeamsLocation{}, errors.Wrap(err, errUnmarshalError) + return TeamsLocation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsLocationDetailResponse.Result, nil @@ -111,7 +109,7 @@ func (api *API) CreateTeamsLocation(ctx context.Context, accountID string, teams // API reference: https://api.cloudflare.com/#teams-locations-update-teams-location func (api *API) UpdateTeamsLocation(ctx context.Context, accountID string, teamsLocation TeamsLocation) (TeamsLocation, error) { if teamsLocation.ID == "" { - return TeamsLocation{}, errors.Errorf("teams location ID cannot be empty") + return TeamsLocation{}, fmt.Errorf("teams location ID cannot be empty") } uri := fmt.Sprintf( @@ -129,7 +127,7 @@ func (api *API) UpdateTeamsLocation(ctx context.Context, accountID string, teams var teamsLocationDetailResponse TeamsLocationDetailResponse err = json.Unmarshal(res, &teamsLocationDetailResponse) if err != nil { - return TeamsLocation{}, errors.Wrap(err, errUnmarshalError) + return TeamsLocation{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsLocationDetailResponse.Result, nil diff --git a/teams_proxy_endpoints.go b/teams_proxy_endpoints.go index 27eee10f8fa..e11aecd42ef 100644 --- a/teams_proxy_endpoints.go +++ b/teams_proxy_endpoints.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/pkg/errors" "net/http" "time" ) @@ -42,7 +41,7 @@ func (api *API) TeamsProxyEndpoint(ctx context.Context, accountID, proxyEndpoint var teamsProxyEndpointDetailResponse TeamsProxyEndpointDetailResponse err = json.Unmarshal(res, &teamsProxyEndpointDetailResponse) if err != nil { - return TeamsProxyEndpoint{}, errors.Wrap(err, errUnmarshalError) + return TeamsProxyEndpoint{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsProxyEndpointDetailResponse.Result, nil @@ -62,7 +61,7 @@ func (api *API) TeamsProxyEndpoints(ctx context.Context, accountID string) ([]Te var teamsProxyEndpointListResponse TeamsProxyEndpointListResponse err = json.Unmarshal(res, &teamsProxyEndpointListResponse) if err != nil { - return []TeamsProxyEndpoint{}, ResultInfo{}, errors.Wrap(err, errUnmarshalError) + return []TeamsProxyEndpoint{}, ResultInfo{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsProxyEndpointListResponse.Result, teamsProxyEndpointListResponse.ResultInfo, nil @@ -82,7 +81,7 @@ func (api *API) CreateTeamsProxyEndpoint(ctx context.Context, accountID string, var teamsProxyEndpointDetailResponse TeamsProxyEndpointDetailResponse err = json.Unmarshal(res, &teamsProxyEndpointDetailResponse) if err != nil { - return TeamsProxyEndpoint{}, errors.Wrap(err, errUnmarshalError) + return TeamsProxyEndpoint{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsProxyEndpointDetailResponse.Result, nil @@ -93,7 +92,7 @@ func (api *API) CreateTeamsProxyEndpoint(ctx context.Context, accountID string, // API reference: https://api.cloudflare.com/#zero-trust-gateway-proxy-endpoints-update-proxy-endpoint func (api *API) UpdateTeamsProxyEndpoint(ctx context.Context, accountID string, proxyEndpoint TeamsProxyEndpoint) (TeamsProxyEndpoint, error) { if proxyEndpoint.ID == "" { - return TeamsProxyEndpoint{}, errors.Errorf("Proxy Endpoint ID cannot be empty") + return TeamsProxyEndpoint{}, fmt.Errorf("Proxy Endpoint ID cannot be empty") } uri := fmt.Sprintf( @@ -111,7 +110,7 @@ func (api *API) UpdateTeamsProxyEndpoint(ctx context.Context, accountID string, var teamsProxyEndpointDetailResponse TeamsProxyEndpointDetailResponse err = json.Unmarshal(res, &teamsProxyEndpointDetailResponse) if err != nil { - return TeamsProxyEndpoint{}, errors.Wrap(err, errUnmarshalError) + return TeamsProxyEndpoint{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsProxyEndpointDetailResponse.Result, nil diff --git a/teams_proxy_endpoints_test.go b/teams_proxy_endpoints_test.go index f042e58d598..e4bc158a1dc 100644 --- a/teams_proxy_endpoints_test.go +++ b/teams_proxy_endpoints_test.go @@ -3,11 +3,12 @@ package cloudflare import ( "context" "fmt" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "net/http" "testing" "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestProxyEndpoint(t *testing.T) { diff --git a/teams_rules.go b/teams_rules.go index c5d67dfd338..5a7732049b1 100644 --- a/teams_rules.go +++ b/teams_rules.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) type TeamsRuleSettings struct { @@ -156,7 +154,7 @@ func (api *API) TeamsRules(ctx context.Context, accountID string) ([]TeamsRule, var teamsRulesResponse TeamsRulesResponse err = json.Unmarshal(res, &teamsRulesResponse) if err != nil { - return []TeamsRule{}, errors.Wrap(err, errUnmarshalError) + return []TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsRulesResponse.Result, nil @@ -176,7 +174,7 @@ func (api *API) TeamsRule(ctx context.Context, accountID string, ruleId string) var teamsRuleResponse TeamsRuleResponse err = json.Unmarshal(res, &teamsRuleResponse) if err != nil { - return TeamsRule{}, errors.Wrap(err, errUnmarshalError) + return TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsRuleResponse.Result, nil @@ -196,7 +194,7 @@ func (api *API) TeamsCreateRule(ctx context.Context, accountID string, rule Team var teamsRuleResponse TeamsRuleResponse err = json.Unmarshal(res, &teamsRuleResponse) if err != nil { - return TeamsRule{}, errors.Wrap(err, errUnmarshalError) + return TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsRuleResponse.Result, nil @@ -216,7 +214,7 @@ func (api *API) TeamsUpdateRule(ctx context.Context, accountID string, ruleId st var teamsRuleResponse TeamsRuleResponse err = json.Unmarshal(res, &teamsRuleResponse) if err != nil { - return TeamsRule{}, errors.Wrap(err, errUnmarshalError) + return TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsRuleResponse.Result, nil @@ -236,7 +234,7 @@ func (api *API) TeamsPatchRule(ctx context.Context, accountID string, ruleId str var teamsRuleResponse TeamsRuleResponse err = json.Unmarshal(res, &teamsRuleResponse) if err != nil { - return TeamsRule{}, errors.Wrap(err, errUnmarshalError) + return TeamsRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return teamsRuleResponse.Result, nil diff --git a/tunnel.go b/tunnel.go index 04025423d72..5aa304364bf 100644 --- a/tunnel.go +++ b/tunnel.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) // ErrMissingTunnelID is for when a required tunnel ID is missing from the @@ -219,7 +219,7 @@ func (api *API) Tunnels(ctx context.Context, params TunnelListParams) ([]Tunnel, var argoDetailsResponse TunnelsDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return []Tunnel{}, errors.Wrap(err, errUnmarshalError) + return []Tunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil } @@ -246,7 +246,7 @@ func (api *API) Tunnel(ctx context.Context, params TunnelParams) (Tunnel, error) var argoDetailsResponse TunnelDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return Tunnel{}, errors.Wrap(err, errUnmarshalError) + return Tunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil } @@ -279,7 +279,7 @@ func (api *API) CreateTunnel(ctx context.Context, params TunnelCreateParams) (Tu var argoDetailsResponse TunnelDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return Tunnel{}, errors.Wrap(err, errUnmarshalError) + return Tunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil @@ -313,7 +313,7 @@ func (api *API) UpdateTunnel(ctx context.Context, params TunnelUpdateParams) (Tu var argoDetailsResponse TunnelDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return Tunnel{}, errors.Wrap(err, errUnmarshalError) + return Tunnel{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return argoDetailsResponse.Result, nil @@ -345,7 +345,7 @@ func (api *API) UpdateTunnelConfiguration(ctx context.Context, params TunnelConf var tunnelDetailsResponse TunnelConfigurationStringifiedConfigResponse err = json.Unmarshal(res, &tunnelDetailsResponse) if err != nil { - return TunnelConfigurationResult{}, errors.Wrap(err, errUnmarshalError) + return TunnelConfigurationResult{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } var tunnelDetails TunnelConfigurationResult @@ -353,7 +353,7 @@ func (api *API) UpdateTunnelConfiguration(ctx context.Context, params TunnelConf err = json.Unmarshal([]byte(tunnelDetailsResponse.Result.Config), &tunnelConfig) if err != nil { - return TunnelConfigurationResult{}, errors.Wrap(err, errUnmarshalError) + return TunnelConfigurationResult{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } tunnelDetails.Config = tunnelConfig @@ -389,7 +389,7 @@ func (api *API) GetTunnelConfiguration(ctx context.Context, params GetTunnelConf var tunnelDetailsResponse TunnelConfigurationStringifiedConfigResponse err = json.Unmarshal(res, &tunnelDetailsResponse) if err != nil { - return TunnelConfigurationResult{}, errors.Wrap(err, errUnmarshalError) + return TunnelConfigurationResult{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } var tunnelDetails TunnelConfigurationResult @@ -397,7 +397,7 @@ func (api *API) GetTunnelConfiguration(ctx context.Context, params GetTunnelConf err = json.Unmarshal([]byte(tunnelDetailsResponse.Result.Config), &tunnelConfig) if err != nil { - return TunnelConfigurationResult{}, errors.Wrap(err, errUnmarshalError) + return TunnelConfigurationResult{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } tunnelDetails.Config = tunnelConfig @@ -421,7 +421,7 @@ func (api *API) DeleteTunnel(ctx context.Context, params TunnelDeleteParams) err var argoDetailsResponse TunnelDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil @@ -449,7 +449,7 @@ func (api *API) CleanupTunnelConnections(ctx context.Context, params TunnelClean var argoDetailsResponse TunnelDetailResponse err = json.Unmarshal(res, &argoDetailsResponse) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil @@ -477,7 +477,7 @@ func (api *API) TunnelToken(ctx context.Context, params TunnelTokenParams) (stri var tunnelTokenResponse TunnelTokenResponse err = json.Unmarshal(res, &tunnelTokenResponse) if err != nil { - return "", errors.Wrap(err, errUnmarshalError) + return "", fmt.Errorf("%s: %w", errUnmarshalError, err) } return tunnelTokenResponse.Result, nil diff --git a/tunnel_routes.go b/tunnel_routes.go index 3ba73c78943..0a8eb72e72b 100644 --- a/tunnel_routes.go +++ b/tunnel_routes.go @@ -9,7 +9,7 @@ import ( "strings" "time" - "github.com/pkg/errors" + "errors" ) var ( @@ -96,7 +96,7 @@ func (api *API) ListTunnelRoutes(ctx context.Context, params TunnelRoutesListPar var resp tunnelRouteListResponse err = json.Unmarshal(res, &resp) if err != nil { - return []TunnelRoute{}, errors.Wrap(err, errUnmarshalError) + return []TunnelRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return resp.Result, nil @@ -128,7 +128,7 @@ func (api *API) GetTunnelRouteForIP(ctx context.Context, params TunnelRoutesForI var routeResponse tunnelRouteResponse err = json.Unmarshal(responseBody, &routeResponse) if err != nil { - return TunnelRoute{}, errors.Wrap(err, errUnmarshalError) + return TunnelRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return routeResponse.Result, nil @@ -157,7 +157,7 @@ func (api *API) CreateTunnelRoute(ctx context.Context, params TunnelRoutesCreate var routeResponse tunnelRouteResponse err = json.Unmarshal(responseBody, &routeResponse) if err != nil { - return TunnelRoute{}, errors.Wrap(err, errUnmarshalError) + return TunnelRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return routeResponse.Result, nil @@ -185,7 +185,7 @@ func (api *API) DeleteTunnelRoute(ctx context.Context, params TunnelRoutesDelete var routeResponse tunnelRouteResponse err = json.Unmarshal(responseBody, &routeResponse) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil @@ -210,7 +210,7 @@ func (api *API) UpdateTunnelRoute(ctx context.Context, params TunnelRoutesUpdate var routeResponse tunnelRouteResponse err = json.Unmarshal(responseBody, &routeResponse) if err != nil { - return TunnelRoute{}, errors.Wrap(err, errUnmarshalError) + return TunnelRoute{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return routeResponse.Result, nil diff --git a/tunnel_virtual_networks.go b/tunnel_virtual_networks.go index 29ff4b4340c..eb80c67afe7 100644 --- a/tunnel_virtual_networks.go +++ b/tunnel_virtual_networks.go @@ -7,7 +7,7 @@ import ( "net/http" "time" - "github.com/pkg/errors" + "errors" ) var ErrMissingVnetName = errors.New("required missing virtual network name") @@ -83,7 +83,7 @@ func (api *API) ListTunnelVirtualNetworks(ctx context.Context, params TunnelVirt var resp tunnelVirtualNetworkListResponse err = json.Unmarshal(res, &resp) if err != nil { - return []TunnelVirtualNetwork{}, errors.Wrap(err, errUnmarshalError) + return []TunnelVirtualNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return resp.Result, nil @@ -111,7 +111,7 @@ func (api *API) CreateTunnelVirtualNetwork(ctx context.Context, params TunnelVir var resp tunnelVirtualNetworkResponse err = json.Unmarshal(responseBody, &resp) if err != nil { - return TunnelVirtualNetwork{}, errors.Wrap(err, errUnmarshalError) + return TunnelVirtualNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return resp.Result, nil @@ -136,7 +136,7 @@ func (api *API) DeleteTunnelVirtualNetwork(ctx context.Context, params TunnelVir var resp tunnelVirtualNetworkResponse err = json.Unmarshal(responseBody, &resp) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil @@ -160,7 +160,7 @@ func (api *API) UpdateTunnelVirtualNetwork(ctx context.Context, params TunnelVir var resp tunnelVirtualNetworkResponse err = json.Unmarshal(responseBody, &resp) if err != nil { - return TunnelVirtualNetwork{}, errors.Wrap(err, errUnmarshalError) + return TunnelVirtualNetwork{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return resp.Result, nil diff --git a/universal_ssl.go b/universal_ssl.go index 9a349e6ce97..fed72d88750 100644 --- a/universal_ssl.go +++ b/universal_ssl.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // UniversalSSLSetting represents a universal ssl setting's properties. @@ -55,7 +53,7 @@ func (api *API) UniversalSSLSettingDetails(ctx context.Context, zoneID string) ( } var r universalSSLSettingResponse if err := json.Unmarshal(res, &r); err != nil { - return UniversalSSLSetting{}, errors.Wrap(err, errUnmarshalError) + return UniversalSSLSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -71,7 +69,7 @@ func (api *API) EditUniversalSSLSetting(ctx context.Context, zoneID string, sett } var r universalSSLSettingResponse if err := json.Unmarshal(res, &r); err != nil { - return UniversalSSLSetting{}, errors.Wrap(err, errUnmarshalError) + return UniversalSSLSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -87,7 +85,7 @@ func (api *API) UniversalSSLVerificationDetails(ctx context.Context, zoneID stri } var r universalSSLVerificationResponse if err := json.Unmarshal(res, &r); err != nil { - return []UniversalSSLVerificationDetails{}, errors.Wrap(err, errUnmarshalError) + return []UniversalSSLVerificationDetails{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -103,7 +101,7 @@ func (api *API) UpdateUniversalSSLCertificatePackValidationMethod(ctx context.Co } var r universalSSLCertificatePackValidationMethodSettingResponse if err := json.Unmarshal(res, &r); err != nil { - return UniversalSSLCertificatePackValidationMethodSetting{}, errors.Wrap(err, errUnmarshalError) + return UniversalSSLCertificatePackValidationMethodSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/user.go b/user.go index 60012c69064..08c2f07f2a6 100644 --- a/user.go +++ b/user.go @@ -3,10 +3,9 @@ package cloudflare import ( "context" "encoding/json" + "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // User describes a user account. @@ -101,7 +100,7 @@ func (api *API) UserDetails(ctx context.Context) (User, error) { err = json.Unmarshal(res, &r) if err != nil { - return User{}, errors.Wrap(err, errUnmarshalError) + return User{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -119,7 +118,7 @@ func (api *API) UpdateUser(ctx context.Context, user *User) (User, error) { err = json.Unmarshal(res, &r) if err != nil { - return User{}, errors.Wrap(err, errUnmarshalError) + return User{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -137,7 +136,7 @@ func (api *API) UserBillingProfile(ctx context.Context) (UserBillingProfile, err err = json.Unmarshal(res, &r) if err != nil { - return UserBillingProfile{}, errors.Wrap(err, errUnmarshalError) + return UserBillingProfile{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -155,7 +154,7 @@ func (api *API) UserBillingHistory(ctx context.Context, pageOpts UserBillingOpti var r UserBillingHistoryResponse err = json.Unmarshal(res, &r) if err != nil { - return []UserBillingHistory{}, errors.Wrap(err, errUnmarshalError) + return []UserBillingHistory{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/user_agent.go b/user_agent.go index bb48ef8158b..9e33ded4ad4 100644 --- a/user_agent.go +++ b/user_agent.go @@ -8,7 +8,7 @@ import ( "net/url" "strconv" - "github.com/pkg/errors" + "errors" ) // UserAgentRule represents a User-Agent Block. These rules can be used to @@ -60,7 +60,7 @@ func (api *API) CreateUserAgentRule(ctx context.Context, zoneID string, ld UserA response := &UserAgentRuleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -79,7 +79,7 @@ func (api *API) UpdateUserAgentRule(ctx context.Context, zoneID string, id strin response := &UserAgentRuleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -98,7 +98,7 @@ func (api *API) DeleteUserAgentRule(ctx context.Context, zoneID string, id strin response := &UserAgentRuleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -117,7 +117,7 @@ func (api *API) UserAgentRule(ctx context.Context, zoneID string, id string) (*U response := &UserAgentRuleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -144,7 +144,7 @@ func (api *API) ListUserAgentRules(ctx context.Context, zoneID string, page int) response := &UserAgentRuleListResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil diff --git a/user_test.go b/user_test.go index 021d747f96b..661c9843f64 100644 --- a/user_test.go +++ b/user_test.go @@ -7,8 +7,9 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "io/ioutil" + + "github.com/stretchr/testify/assert" ) func TestUser_UserDetails(t *testing.T) { diff --git a/waf.go b/waf.go index 596ef37f279..7e81c64889e 100644 --- a/waf.go +++ b/waf.go @@ -7,8 +7,6 @@ import ( "net/http" "net/url" "strconv" - - "github.com/pkg/errors" ) // WAFPackage represents a WAF package configuration. @@ -128,7 +126,7 @@ func (api *API) ListWAFPackages(ctx context.Context, zoneID string) ([]WAFPackag var p WAFPackagesResponse err = json.Unmarshal(res, &p) if err != nil { - return []WAFPackage{}, errors.Wrap(err, errUnmarshalError) + return []WAFPackage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !p.Success { @@ -161,7 +159,7 @@ func (api *API) WAFPackage(ctx context.Context, zoneID, packageID string) (WAFPa var r WAFPackageResponse err = json.Unmarshal(res, &r) if err != nil { - return WAFPackage{}, errors.Wrap(err, errUnmarshalError) + return WAFPackage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -180,7 +178,7 @@ func (api *API) UpdateWAFPackage(ctx context.Context, zoneID, packageID string, var r WAFPackageResponse err = json.Unmarshal(res, &r) if err != nil { - return WAFPackage{}, errors.Wrap(err, errUnmarshalError) + return WAFPackage{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -211,7 +209,7 @@ func (api *API) ListWAFGroups(ctx context.Context, zoneID, packageID string) ([] var r WAFGroupsResponse err = json.Unmarshal(res, &r) if err != nil { - return []WAFGroup{}, errors.Wrap(err, errUnmarshalError) + return []WAFGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !r.Success { @@ -243,7 +241,7 @@ func (api *API) WAFGroup(ctx context.Context, zoneID, packageID, groupID string) var r WAFGroupResponse err = json.Unmarshal(res, &r) if err != nil { - return WAFGroup{}, errors.Wrap(err, errUnmarshalError) + return WAFGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -263,7 +261,7 @@ func (api *API) UpdateWAFGroup(ctx context.Context, zoneID, packageID, groupID, var r WAFGroupResponse err = json.Unmarshal(res, &r) if err != nil { - return WAFGroup{}, errors.Wrap(err, errUnmarshalError) + return WAFGroup{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -294,7 +292,7 @@ func (api *API) ListWAFRules(ctx context.Context, zoneID, packageID string) ([]W var r WAFRulesResponse err = json.Unmarshal(res, &r) if err != nil { - return []WAFRule{}, errors.Wrap(err, errUnmarshalError) + return []WAFRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !r.Success { @@ -327,7 +325,7 @@ func (api *API) WAFRule(ctx context.Context, zoneID, packageID, ruleID string) ( var r WAFRuleResponse err = json.Unmarshal(res, &r) if err != nil { - return WAFRule{}, errors.Wrap(err, errUnmarshalError) + return WAFRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -347,7 +345,7 @@ func (api *API) UpdateWAFRule(ctx context.Context, zoneID, packageID, ruleID, mo var r WAFRuleResponse err = json.Unmarshal(res, &r) if err != nil { - return WAFRule{}, errors.Wrap(err, errUnmarshalError) + return WAFRule{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } diff --git a/waf_overrides.go b/waf_overrides.go index d061425c25f..76c0774f349 100644 --- a/waf_overrides.go +++ b/waf_overrides.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // WAFOverridesResponse represents the response form the WAF overrides endpoint. @@ -52,7 +50,7 @@ func (api *API) ListWAFOverrides(ctx context.Context, zoneID string) ([]WAFOverr var r WAFOverridesResponse err = json.Unmarshal(res, &r) if err != nil { - return []WAFOverride{}, errors.Wrap(err, errUnmarshalError) + return []WAFOverride{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !r.Success { @@ -79,7 +77,7 @@ func (api *API) WAFOverride(ctx context.Context, zoneID, overrideID string) (WAF var r WAFOverrideResponse err = json.Unmarshal(res, &r) if err != nil { - return WAFOverride{}, errors.Wrap(err, errUnmarshalError) + return WAFOverride{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -96,7 +94,7 @@ func (api *API) CreateWAFOverride(ctx context.Context, zoneID string, override W } var r WAFOverrideResponse if err := json.Unmarshal(res, &r); err != nil { - return WAFOverride{}, errors.Wrap(err, errUnmarshalError) + return WAFOverride{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -115,7 +113,7 @@ func (api *API) UpdateWAFOverride(ctx context.Context, zoneID, overrideID string var r WAFOverrideResponse err = json.Unmarshal(res, &r) if err != nil { - return WAFOverride{}, errors.Wrap(err, errUnmarshalError) + return WAFOverride{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -133,7 +131,7 @@ func (api *API) DeleteWAFOverride(ctx context.Context, zoneID, overrideID string var r WAFOverrideResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } diff --git a/waiting_room.go b/waiting_room.go index 9b4b5e31292..e3e400e69b6 100644 --- a/waiting_room.go +++ b/waiting_room.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // WaitingRoom describes a WaitingRoom object. @@ -120,7 +118,7 @@ func (api *API) CreateWaitingRoom(ctx context.Context, zoneID string, waitingRoo var r WaitingRoomDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return &r.Result, nil } @@ -137,7 +135,7 @@ func (api *API) ListWaitingRooms(ctx context.Context, zoneID string) ([]WaitingR var r WaitingRoomsResponse err = json.Unmarshal(res, &r) if err != nil { - return []WaitingRoom{}, errors.Wrap(err, errUnmarshalError) + return []WaitingRoom{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -154,7 +152,7 @@ func (api *API) WaitingRoom(ctx context.Context, zoneID, waitingRoomID string) ( var r WaitingRoomDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return WaitingRoom{}, errors.Wrap(err, errUnmarshalError) + return WaitingRoom{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -172,7 +170,7 @@ func (api *API) ChangeWaitingRoom(ctx context.Context, zoneID, waitingRoomID str var r WaitingRoomDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return WaitingRoom{}, errors.Wrap(err, errUnmarshalError) + return WaitingRoom{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -190,7 +188,7 @@ func (api *API) UpdateWaitingRoom(ctx context.Context, zoneID string, waitingRoo var r WaitingRoomDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return WaitingRoom{}, errors.Wrap(err, errUnmarshalError) + return WaitingRoom{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -207,7 +205,7 @@ func (api *API) DeleteWaitingRoom(ctx context.Context, zoneID, waitingRoomID str var r WaitingRoomDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } @@ -224,7 +222,7 @@ func (api *API) WaitingRoomStatus(ctx context.Context, zoneID, waitingRoomID str var r WaitingRoomStatusResponse err = json.Unmarshal(res, &r) if err != nil { - return WaitingRoomStatus{}, errors.Wrap(err, errUnmarshalError) + return WaitingRoomStatus{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -243,7 +241,7 @@ func (api *API) WaitingRoomPagePreview(ctx context.Context, zoneID, customHTML s var r WaitingRoomPagePreviewResponse err = json.Unmarshal(res, &r) if err != nil { - return WaitingRoomPagePreviewURL{}, errors.Wrap(err, errUnmarshalError) + return WaitingRoomPagePreviewURL{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -260,7 +258,7 @@ func (api *API) CreateWaitingRoomEvent(ctx context.Context, zoneID string, waiti var r WaitingRoomEventDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return &r.Result, nil } @@ -277,7 +275,7 @@ func (api *API) ListWaitingRoomEvents(ctx context.Context, zoneID string, waitin var r WaitingRoomEventsResponse err = json.Unmarshal(res, &r) if err != nil { - return []WaitingRoomEvent{}, errors.Wrap(err, errUnmarshalError) + return []WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -294,7 +292,7 @@ func (api *API) WaitingRoomEvent(ctx context.Context, zoneID string, waitingRoom var r WaitingRoomEventDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return WaitingRoomEvent{}, errors.Wrap(err, errUnmarshalError) + return WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -312,7 +310,7 @@ func (api *API) WaitingRoomEventPreview(ctx context.Context, zoneID string, wait var r WaitingRoomEventDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return WaitingRoomEvent{}, errors.Wrap(err, errUnmarshalError) + return WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -330,7 +328,7 @@ func (api *API) ChangeWaitingRoomEvent(ctx context.Context, zoneID, waitingRoomI var r WaitingRoomEventDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return WaitingRoomEvent{}, errors.Wrap(err, errUnmarshalError) + return WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -348,7 +346,7 @@ func (api *API) UpdateWaitingRoomEvent(ctx context.Context, zoneID string, waiti var r WaitingRoomEventDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return WaitingRoomEvent{}, errors.Wrap(err, errUnmarshalError) + return WaitingRoomEvent{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -365,7 +363,7 @@ func (api *API) DeleteWaitingRoomEvent(ctx context.Context, zoneID string, waiti var r WaitingRoomEventDetailResponse err = json.Unmarshal(res, &r) if err != nil { - return errors.Wrap(err, errUnmarshalError) + return fmt.Errorf("%s: %w", errUnmarshalError, err) } return nil } diff --git a/workers.go b/workers.go index 342251185e7..a1f812b25f8 100644 --- a/workers.go +++ b/workers.go @@ -13,7 +13,7 @@ import ( "net/textproto" "time" - "github.com/pkg/errors" + "errors" ) // WorkerRequestParams provides parameters for worker requests for both enterprise and standard requests. @@ -182,7 +182,7 @@ func (b WorkerKvNamespaceBinding) Type() WorkerBindingType { func (b WorkerKvNamespaceBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { if b.NamespaceID == "" { - return nil, nil, errors.Errorf(`NamespaceID for binding "%s" cannot be empty`, bindingName) + return nil, nil, fmt.Errorf(`NamespaceID for binding "%s" cannot be empty`, bindingName) } return workerBindingMeta{ @@ -207,7 +207,7 @@ func (b WorkerDurableObjectBinding) Type() WorkerBindingType { func (b WorkerDurableObjectBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { if b.ClassName == "" { - return nil, nil, errors.Errorf(`ClassName for binding "%s" cannot be empty`, bindingName) + return nil, nil, fmt.Errorf(`ClassName for binding "%s" cannot be empty`, bindingName) } return workerBindingMeta{ @@ -266,7 +266,7 @@ func (b WorkerPlainTextBinding) Type() WorkerBindingType { func (b WorkerPlainTextBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { if b.Text == "" { - return nil, nil, errors.Errorf(`Text for binding "%s" cannot be empty`, bindingName) + return nil, nil, fmt.Errorf(`Text for binding "%s" cannot be empty`, bindingName) } return workerBindingMeta{ @@ -290,7 +290,7 @@ func (b WorkerSecretTextBinding) Type() WorkerBindingType { func (b WorkerSecretTextBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { if b.Text == "" { - return nil, nil, errors.Errorf(`Text for binding "%s" cannot be empty`, bindingName) + return nil, nil, fmt.Errorf(`Text for binding "%s" cannot be empty`, bindingName) } return workerBindingMeta{ @@ -311,7 +311,7 @@ func (b WorkerServiceBinding) Type() WorkerBindingType { func (b WorkerServiceBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { if b.Service == "" { - return nil, nil, errors.Errorf(`Service for binding "%s" cannot be empty`, bindingName) + return nil, nil, fmt.Errorf(`Service for binding "%s" cannot be empty`, bindingName) } meta := workerBindingMeta{ @@ -339,7 +339,7 @@ func (b WorkerR2BucketBinding) Type() WorkerBindingType { func (b WorkerR2BucketBinding) serialize(bindingName string) (workerBindingMeta, workerBindingBodyWriter, error) { if b.BucketName == "" { - return nil, nil, errors.Errorf(`BucketName for binding "%s" cannot be empty`, bindingName) + return nil, nil, fmt.Errorf(`BucketName for binding "%s" cannot be empty`, bindingName) } return workerBindingMeta{ @@ -373,7 +373,7 @@ func (api *API) DeleteWorker(ctx context.Context, requestParams *WorkerRequestPa } err = json.Unmarshal(res, &r) if err != nil { - return r, errors.Wrap(err, errUnmarshalError) + return r, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -394,7 +394,7 @@ func (api *API) deleteWorkerWithName(ctx context.Context, scriptName string) (Wo } err = json.Unmarshal(res, &r) if err != nil { - return r, errors.Wrap(err, errUnmarshalError) + return r, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -457,7 +457,7 @@ func (api *API) ListWorkerBindings(ctx context.Context, requestParams *WorkerReq } err = json.Unmarshal(res, &jsonRes) if err != nil { - return r, errors.Wrap(err, errUnmarshalError) + return r, fmt.Errorf("%s: %w", errUnmarshalError, err) } r = WorkerBindingListResponse{ @@ -467,11 +467,11 @@ func (api *API) ListWorkerBindings(ctx context.Context, requestParams *WorkerReq for _, jsonBinding := range jsonRes.Bindings { name, ok := jsonBinding["name"].(string) if !ok { - return r, errors.Errorf("Binding missing name %v", jsonBinding) + return r, fmt.Errorf("Binding missing name %v", jsonBinding) } bType, ok := jsonBinding["type"].(string) if !ok { - return r, errors.Errorf("Binding missing type %v", jsonBinding) + return r, fmt.Errorf("Binding missing type %v", jsonBinding) } bindingListItem := WorkerBindingListItem{ Name: name, @@ -584,7 +584,7 @@ func (api *API) ListWorkerScripts(ctx context.Context) (WorkerListResponse, erro var r WorkerListResponse err = json.Unmarshal(res, &r) if err != nil { - return WorkerListResponse{}, errors.Wrap(err, errUnmarshalError) + return WorkerListResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -624,7 +624,7 @@ func (api *API) uploadWorkerForZone(ctx context.Context, zoneID, contentType str } err = json.Unmarshal(res, &r) if err != nil { - return r, errors.Wrap(err, errUnmarshalError) + return r, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -643,7 +643,7 @@ func (api *API) uploadWorkerWithName(ctx context.Context, scriptName, contentTyp } err = json.Unmarshal(res, &r) if err != nil { - return r, errors.Wrap(err, errUnmarshalError) + return r, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -736,7 +736,7 @@ func (api *API) CreateWorkerRoute(ctx context.Context, zoneID string, route Work var r WorkerRouteResponse err = json.Unmarshal(res, &r) if err != nil { - return WorkerRouteResponse{}, errors.Wrap(err, errUnmarshalError) + return WorkerRouteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -753,7 +753,7 @@ func (api *API) DeleteWorkerRoute(ctx context.Context, zoneID string, routeID st var r WorkerRouteResponse err = json.Unmarshal(res, &r) if err != nil { - return WorkerRouteResponse{}, errors.Wrap(err, errUnmarshalError) + return WorkerRouteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -783,7 +783,7 @@ func (api *API) ListWorkerRoutes(ctx context.Context, zoneID string) (WorkerRout var r WorkerRoutesResponse err = json.Unmarshal(res, &r) if err != nil { - return WorkerRoutesResponse{}, errors.Wrap(err, errUnmarshalError) + return WorkerRoutesResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } for i := range r.Routes { route := &r.Routes[i] @@ -809,7 +809,7 @@ func (api *API) GetWorkerRoute(ctx context.Context, zoneID string, routeID strin var r WorkerRouteResponse err = json.Unmarshal(res, &r) if err != nil { - return WorkerRouteResponse{}, errors.Wrap(err, errUnmarshalError) + return WorkerRouteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -830,7 +830,7 @@ func (api *API) UpdateWorkerRoute(ctx context.Context, zoneID string, routeID st var r WorkerRouteResponse err = json.Unmarshal(res, &r) if err != nil { - return WorkerRouteResponse{}, errors.Wrap(err, errUnmarshalError) + return WorkerRouteResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } diff --git a/workers_cron_triggers.go b/workers_cron_triggers.go index 57e672acf61..8938862aef4 100644 --- a/workers_cron_triggers.go +++ b/workers_cron_triggers.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) // WorkerCronTriggerResponse represents the response from the Worker cron trigger @@ -42,7 +40,7 @@ func (api *API) ListWorkerCronTriggers(ctx context.Context, accountID, scriptNam result := WorkerCronTriggerResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []WorkerCronTrigger{}, errors.Wrap(err, errUnmarshalError) + return []WorkerCronTrigger{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.Schedules, err @@ -60,7 +58,7 @@ func (api *API) UpdateWorkerCronTriggers(ctx context.Context, accountID, scriptN result := WorkerCronTriggerResponse{} if err := json.Unmarshal(res, &result); err != nil { - return []WorkerCronTrigger{}, errors.Wrap(err, errUnmarshalError) + return []WorkerCronTrigger{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result.Result.Schedules, err diff --git a/workers_kv.go b/workers_kv.go index 7f75b6ab832..14ca55a4233 100644 --- a/workers_kv.go +++ b/workers_kv.go @@ -8,7 +8,7 @@ import ( "net/url" "strconv" - "github.com/pkg/errors" + "errors" ) // WorkersKVNamespaceRequest provides parameters for creating and updating storage namespaces. @@ -85,7 +85,7 @@ func (api *API) CreateWorkersKVNamespace(ctx context.Context, req *WorkersKVName result := WorkersKVNamespaceResponse{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -111,7 +111,7 @@ func (api *API) ListWorkersKVNamespaces(ctx context.Context) ([]WorkersKVNamespa var p ListWorkersKVNamespacesResponse if err := json.Unmarshal(res, &p); err != nil { - return []WorkersKVNamespace{}, errors.Wrap(err, errUnmarshalError) + return []WorkersKVNamespace{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !p.Success { @@ -141,7 +141,7 @@ func (api *API) DeleteWorkersKVNamespace(ctx context.Context, namespaceID string result := Response{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -159,7 +159,7 @@ func (api *API) UpdateWorkersKVNamespace(ctx context.Context, namespaceID string result := Response{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -180,7 +180,7 @@ func (api *API) WriteWorkersKV(ctx context.Context, namespaceID, key string, val result := Response{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -200,7 +200,7 @@ func (api *API) WriteWorkersKVBulk(ctx context.Context, namespaceID string, kvs result := Response{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -232,7 +232,7 @@ func (api API) DeleteWorkersKV(ctx context.Context, namespaceID, key string) (Re result := Response{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err } @@ -251,7 +251,7 @@ func (api *API) DeleteWorkersKVBulk(ctx context.Context, namespaceID string, key result := Response{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -269,7 +269,7 @@ func (api API) ListWorkersKVs(ctx context.Context, namespaceID string) (ListStor result := ListStorageKeysResponse{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err } @@ -301,7 +301,7 @@ func (api API) ListWorkersKVsWithOptions(ctx context.Context, namespaceID string result := ListStorageKeysResponse{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err } diff --git a/workers_secrets.go b/workers_secrets.go index 2b4127bebb2..09d8ba337e9 100644 --- a/workers_secrets.go +++ b/workers_secrets.go @@ -5,8 +5,6 @@ import ( "encoding/json" "fmt" "net/http" - - "github.com/pkg/errors" ) // WorkersPutSecretRequest provides parameters for creating and updating secrets. @@ -45,7 +43,7 @@ func (api *API) SetWorkersSecret(ctx context.Context, script string, req *Worker result := WorkersPutSecretResponse{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -62,7 +60,7 @@ func (api *API) DeleteWorkersSecret(ctx context.Context, script, secretName stri result := Response{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err @@ -79,7 +77,7 @@ func (api *API) ListWorkersSecrets(ctx context.Context, script string) (WorkersL result := WorkersListSecretsResponse{} if err := json.Unmarshal(res, &result); err != nil { - return result, errors.Wrap(err, errUnmarshalError) + return result, fmt.Errorf("%s: %w", errUnmarshalError, err) } return result, err diff --git a/zone.go b/zone.go index c009d8a08ae..56d7da12838 100644 --- a/zone.go +++ b/zone.go @@ -10,7 +10,8 @@ import ( "sync" "time" - "github.com/pkg/errors" + "errors" + "golang.org/x/net/idna" ) @@ -331,7 +332,7 @@ func (api *API) CreateZone(ctx context.Context, name string, jumpstart bool, acc var r ZoneResponse err = json.Unmarshal(res, &r) if err != nil { - return Zone{}, errors.Wrap(err, errUnmarshalError) + return Zone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -347,7 +348,7 @@ func (api *API) ZoneActivationCheck(ctx context.Context, zoneID string) (Respons var r Response err = json.Unmarshal(res, &r) if err != nil { - return Response{}, errors.Wrap(err, errUnmarshalError) + return Response{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -371,7 +372,7 @@ func (api *API) ListZones(ctx context.Context, z ...string) ([]Zone, error) { } err = json.Unmarshal(res, &r) if err != nil { - return []Zone{}, errors.Wrap(err, errUnmarshalError) + return []Zone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } if !r.Success { // TODO: Provide an actual error message instead of always returning nil @@ -450,7 +451,7 @@ func (api *API) ListZonesContext(ctx context.Context, opts ...ReqOption) (r Zone } err = json.Unmarshal(res, &r) if err != nil { - return ZonesResponse{}, errors.Wrap(err, errUnmarshalError) + return ZonesResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } // avoid overhead in most common cases where the total #zones <= 50 @@ -513,7 +514,7 @@ func (api *API) ZoneDetails(ctx context.Context, zoneID string) (Zone, error) { var r ZoneResponse err = json.Unmarshal(res, &r) if err != nil { - return Zone{}, errors.Wrap(err, errUnmarshalError) + return Zone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -618,7 +619,7 @@ func (api *API) EditZone(ctx context.Context, zoneID string, zoneOpts ZoneOption var r ZoneResponse err = json.Unmarshal(res, &r) if err != nil { - return Zone{}, errors.Wrap(err, errUnmarshalError) + return Zone{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -639,7 +640,7 @@ func (api *API) PurgeEverything(ctx context.Context, zoneID string) (PurgeCacheR var r PurgeCacheResponse err = json.Unmarshal(res, &r) if err != nil { - return PurgeCacheResponse{}, errors.Wrap(err, errUnmarshalError) + return PurgeCacheResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -663,7 +664,7 @@ func (api *API) PurgeCacheContext(ctx context.Context, zoneID string, pcr PurgeC var r PurgeCacheResponse err = json.Unmarshal(res, &r) if err != nil { - return PurgeCacheResponse{}, errors.Wrap(err, errUnmarshalError) + return PurgeCacheResponse{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r, nil } @@ -679,7 +680,7 @@ func (api *API) DeleteZone(ctx context.Context, zoneID string) (ZoneID, error) { var r ZoneIDResponse err = json.Unmarshal(res, &r) if err != nil { - return ZoneID{}, errors.Wrap(err, errUnmarshalError) + return ZoneID{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -696,7 +697,7 @@ func (api *API) AvailableZoneRatePlans(ctx context.Context, zoneID string) ([]Zo var r AvailableZoneRatePlansResponse err = json.Unmarshal(res, &r) if err != nil { - return []ZoneRatePlan{}, errors.Wrap(err, errUnmarshalError) + return []ZoneRatePlan{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -713,7 +714,7 @@ func (api *API) AvailableZonePlans(ctx context.Context, zoneID string) ([]ZonePl var r AvailableZonePlansResponse err = json.Unmarshal(res, &r) if err != nil { - return []ZonePlan{}, errors.Wrap(err, errUnmarshalError) + return []ZonePlan{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -745,7 +746,7 @@ func (api *API) ZoneAnalyticsDashboard(ctx context.Context, zoneID string, optio var r zoneAnalyticsDataResponse err = json.Unmarshal(res, &r) if err != nil { - return ZoneAnalyticsData{}, errors.Wrap(err, errUnmarshalError) + return ZoneAnalyticsData{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -762,7 +763,7 @@ func (api *API) ZoneAnalyticsByColocation(ctx context.Context, zoneID string, op var r zoneAnalyticsColocationResponse err = json.Unmarshal(res, &r) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -780,7 +781,7 @@ func (api *API) ZoneSettings(ctx context.Context, zoneID string) (*ZoneSettingRe response := &ZoneSettingResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -801,7 +802,7 @@ func (api *API) UpdateZoneSettings(ctx context.Context, zoneID string, settings response := &ZoneSettingResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -819,7 +820,7 @@ func (api *API) ZoneSSLSettings(ctx context.Context, zoneID string) (ZoneSSLSett var r ZoneSSLSettingResponse err = json.Unmarshal(res, &r) if err != nil { - return ZoneSSLSetting{}, errors.Wrap(err, errUnmarshalError) + return ZoneSSLSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -836,7 +837,7 @@ func (api *API) UpdateZoneSSLSettings(ctx context.Context, zoneID string, sslVal var r ZoneSSLSettingResponse err = json.Unmarshal(res, &r) if err != nil { - return ZoneSSLSetting{}, errors.Wrap(err, errUnmarshalError) + return ZoneSSLSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -854,7 +855,7 @@ func (api *API) FallbackOrigin(ctx context.Context, zoneID string) (FallbackOrig var r FallbackOriginResponse err = json.Unmarshal(res, &r) if err != nil { - return FallbackOrigin{}, errors.Wrap(err, errUnmarshalError) + return FallbackOrigin{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil @@ -873,7 +874,7 @@ func (api *API) UpdateFallbackOrigin(ctx context.Context, zoneID string, fbo Fal response := &FallbackOriginResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -909,7 +910,7 @@ func (api *API) ZoneSingleSetting(ctx context.Context, zoneID, settingName strin var r ZoneSettingSingleResponse err = json.Unmarshal(res, &r) if err != nil { - return ZoneSetting{}, errors.Wrap(err, errUnmarshalError) + return ZoneSetting{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -927,7 +928,7 @@ func (api *API) UpdateZoneSingleSetting(ctx context.Context, zoneID, settingName response := &ZoneSettingSingleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return nil, errors.Wrap(err, errUnmarshalError) + return nil, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response, nil @@ -976,7 +977,7 @@ func (api *API) ZoneDNSSECSetting(ctx context.Context, zoneID string) (ZoneDNSSE response := ZoneDNSSECResponse{} err = json.Unmarshal(res, &response) if err != nil { - return ZoneDNSSEC{}, errors.Wrap(err, errUnmarshalError) + return ZoneDNSSEC{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil @@ -999,7 +1000,7 @@ func (api *API) DeleteZoneDNSSEC(ctx context.Context, zoneID string) (string, er response := ZoneDNSSECDeleteResponse{} err = json.Unmarshal(res, &response) if err != nil { - return "", errors.Wrap(err, errUnmarshalError) + return "", fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil } @@ -1020,7 +1021,7 @@ func (api *API) UpdateZoneDNSSEC(ctx context.Context, zoneID string, options Zon response := ZoneDNSSECResponse{} err = json.Unmarshal(res, &response) if err != nil { - return ZoneDNSSEC{}, errors.Wrap(err, errUnmarshalError) + return ZoneDNSSEC{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil } diff --git a/zone_cache_variants.go b/zone_cache_variants.go index c4f70385767..f7a18d5ca28 100644 --- a/zone_cache_variants.go +++ b/zone_cache_variants.go @@ -6,8 +6,6 @@ import ( "fmt" "net/http" "time" - - "github.com/pkg/errors" ) type ZoneCacheVariantsValues struct { @@ -50,7 +48,7 @@ func (api *API) ZoneCacheVariants(ctx context.Context, zoneID string) (ZoneCache var r zoneCacheVariantsSingleResponse err = json.Unmarshal(res, &r) if err != nil { - return ZoneCacheVariants{}, errors.Wrap(err, errUnmarshalError) + return ZoneCacheVariants{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return r.Result, nil } @@ -70,7 +68,7 @@ func (api *API) UpdateZoneCacheVariants(ctx context.Context, zoneID string, vari response := &zoneCacheVariantsSingleResponse{} err = json.Unmarshal(res, &response) if err != nil { - return ZoneCacheVariants{}, errors.Wrap(err, errUnmarshalError) + return ZoneCacheVariants{}, fmt.Errorf("%s: %w", errUnmarshalError, err) } return response.Result, nil