[Enhancement]: Add semgrep rule for missing err
checks following a NotFound
checkΒ #30069
Open
Description
Description
To avoid unintentionally allowing errors and nil
SDK output values to pass through CRUD handlers, we should add a semgrep rule ensuring an if err != nil
check is always present following a "NotFound" error check. For example, the following missing error check caused the crash from #30068:
outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (interface{}, error) {
return FindRepositoryByName(ctx, conn, d.Id())
}, d.IsNewResource())
if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] ECR Repository (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
}
repository := outputRaw.(*ecr.Repository)
References
Would you like to implement a fix?
None