Skip to content

Commit

Permalink
Updates semgrep rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Jul 20, 2023
1 parent 8a0a52b commit da0da0d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 2 additions & 3 deletions .ci/semgrep/pluginsdk/diags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ rules:
languages: [go]
message: Prefer `sdkdiag.AppendFromErr` to `diag.FromErr`
paths:
include:
- internal/conns
- internal/provider
exclude:
- internal/service
patterns:
- pattern: diag.FromErr($ERR)
severity: WARNING
Expand Down
13 changes: 8 additions & 5 deletions internal/acctest/vcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/provider"
"gopkg.in/dnaeon/go-vcr.v3/cassette"
"gopkg.in/dnaeon/go-vcr.v3/recorder"
Expand Down Expand Up @@ -133,6 +134,8 @@ func vcrEnabledProtoV5ProviderFactories(t *testing.T, input map[string]func() (t
// VCR requires a single HTTP client to handle all interactions.
func vcrProviderConfigureContextFunc(provider *schema.Provider, configureContextFunc schema.ConfigureContextFunc, testName string) schema.ConfigureContextFunc {
return func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
var diags diag.Diagnostics

providerMetas.Lock()
meta, ok := providerMetas[testName]
defer providerMetas.Unlock()
Expand All @@ -144,7 +147,7 @@ func vcrProviderConfigureContextFunc(provider *schema.Provider, configureContext
vcrMode, err := vcrMode()

if err != nil {
return nil, diag.FromErr(err)
return nil, sdkdiag.AppendFromErr(diags, err)
}

// Cribbed from aws-sdk-go-base.
Expand All @@ -168,7 +171,7 @@ func vcrProviderConfigureContextFunc(provider *schema.Provider, configureContext
})

if err != nil {
return nil, diag.FromErr(err)
return nil, sdkdiag.AppendFromErr(diags, err)
}

// Remove sensitive HTTP headers.
Expand Down Expand Up @@ -263,8 +266,8 @@ func vcrProviderConfigureContextFunc(provider *schema.Provider, configureContext
meta.SetHTTPClient(httpClient)
provider.SetMeta(meta)

if v, diags := configureContextFunc(ctx, d); diags.HasError() {
return nil, diags
if v, ds := configureContextFunc(ctx, d); ds.HasError() {
return nil, append(diags, ds...)
} else {
meta = v.(*conns.AWSClient)
}
Expand All @@ -282,7 +285,7 @@ func vcrProviderConfigureContextFunc(provider *schema.Provider, configureContext

providerMetas[testName] = meta

return meta, nil
return meta, diags
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/errs/sdkdiag/append.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func AppendFromErr(diags diag.Diagnostics, err error) diag.Diagnostics {
if err == nil {
return diags
}
return append(diags, diag.FromErr(err)...)
return append(diags, diag.FromErr(err)...) // nosemgrep:ci.semgrep.pluginsdk.avoid-diag_FromErr
}

func WrapDiagsf(orig diag.Diagnostics, format string, a ...any) diag.Diagnostics {
Expand Down

0 comments on commit da0da0d

Please sign in to comment.