Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check err != nil after !d.IsNewResource() && tfresource.NotFound() #38512

Merged
merged 7 commits into from
Jul 24, 2024
3 changes: 3 additions & 0 deletions .changelog/#####.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_timestreamwrite_table: Fix `runtime error: invalid memory address or nil pointer dereference` panic when reading a non-existent table
```
31 changes: 31 additions & 0 deletions .ci/semgrep/errors/error-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,34 @@
- pattern-not-inside: |
tfresource.RetryWhen(...)
severity: ERROR

- id: isnewresource-notfound-without-err-checks
languages: [go]
message: When checking for !d.IsNewResource() && tfresource.NotFound() errors, typically other error conditions should be checked.
patterns:
- pattern: |
if !d.IsNewResource() && tfresource.NotFound($ERR) { ... }
- pattern-not-inside: |
if !d.IsNewResource() && tfresource.NotFound($ERR) { ... }
if $ERR != nil { ... }
# e.g. internal/service/dms/s3_endpoint.go
- pattern-not-inside: |
if !d.IsNewResource() && tfresource.NotFound($ERR) { ... }
if $ERR == nil && ... {
...
err = ...
...
}
if $ERR != nil { ... }
# e.g. internal/service/quicksight/analysis.go
- pattern-not-inside: |
if !d.IsNewResource() && tfresource.NotFound($ERR) { ... }
if !d.IsNewResource() && ... { ... }
if $ERR != nil { ... }
# e.g. internal/service/sagemaker/app.go
- pattern-not-inside: |
if err != nil {
if !d.IsNewResource() && tfresource.NotFound($ERR) { ... }
return ...
}
severity: ERROR

Check failure on line 90 in .ci/semgrep/errors/error-checks.yml

View workflow job for this annotation

GitHub Actions / yamllint

90:20 [new-line-at-end-of-file] no new line character at the end of file
4 changes: 4 additions & 0 deletions internal/service/chime/voice_connector_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ func resourceVoiceConnectorLoggingRead(ctx context.Context, d *schema.ResourceDa
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Chime Voice Connector logging configuration (%s): %s", d.Id(), err)
}

d.Set("enable_media_metric_logs", resp.EnableMediaMetricLogs)
d.Set("enable_sip_logs", resp.EnableSIPLogs)
d.Set("voice_connector_id", d.Id())
Expand Down
4 changes: 4 additions & 0 deletions internal/service/chimesdkvoice/sip_media_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func resourceSipMediaApplicationRead(ctx context.Context, d *schema.ResourceData
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Chime Sip Media Application (%s): %s", d.Id(), err)
}

d.Set(names.AttrARN, resp.SipMediaApplicationArn)
d.Set("aws_region", resp.AwsRegion)
d.Set(names.AttrName, resp.Name)
Expand Down
4 changes: 4 additions & 0 deletions internal/service/chimesdkvoice/sip_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func resourceSipRuleRead(ctx context.Context, d *schema.ResourceData, meta inter
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading ChimeSKVoice Sip Rule (%s): %s", d.Id(), err)
}

d.Set(names.AttrName, resp.Name)
d.Set("disabled", resp.Disabled)
d.Set("trigger_type", resp.TriggerType)
Expand Down
4 changes: 4 additions & 0 deletions internal/service/timestreamwrite/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ func resourceTableRead(ctx context.Context, d *schema.ResourceData, meta interfa
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Timestream Table (%s): %s", d.Id(), err)
}

d.Set(names.AttrARN, table.Arn)
d.Set(names.AttrDatabaseName, table.DatabaseName)
if err := d.Set("magnetic_store_write_properties", flattenMagneticStoreWriteProperties(table.MagneticStoreWriteProperties)); err != nil {
Expand Down
Loading