Skip to content

Commit 5c82255

Browse files
committed
Update smarterr
2 parents d3d07c2 + 2297250 commit 5c82255

File tree

346 files changed

+1792
-1438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

346 files changed

+1792
-1438
lines changed

.ci/semgrep/smarterr/enforce.yml

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
rules:
2+
- id: go-no-smerr-enrichappend-deprecated
3+
languages: [go]
4+
message: Use smerr.AddEnrich instead of deprecated smerr.EnrichAppend.
5+
severity: ERROR
6+
pattern: smerr.EnrichAppend($CTX, $DIAGS, $FUNC)
7+
fix: smerr.AddEnrich($CTX, $DIAGS, $FUNC)
8+
paths:
9+
include:
10+
- "/internal/service/appsync/"
11+
- "/internal/service/cloudwatch/"
12+
- "/internal/service/invoicing/"
13+
214
- id: go-no-sdkdiag-appendfromerr
315
languages: [go]
416
message: Use smerr.Append(ctx, diags, err) instead of sdkdiag.AppendFromErr.
@@ -7,6 +19,7 @@ rules:
719
fix: smerr.Append(ctx, $DIAGS, $ERR)
820
paths:
921
include:
22+
- "/internal/service/appsync/"
1023
- "/internal/service/cloudwatch/"
1124
- "/internal/service/invoicing/"
1225

@@ -19,6 +32,7 @@ rules:
1932
- pattern: sdkdiag.AppendErrorf($DIAGS, $FMT, $ERR)
2033
paths:
2134
include:
35+
- "/internal/service/appsync/"
2236
- "/internal/service/cloudwatch/"
2337
- "/internal/service/invoicing/"
2438

@@ -29,6 +43,7 @@ rules:
2943
pattern: create.AppendDiagError($DIAGS, ...)
3044
paths:
3145
include:
46+
- "/internal/service/appsync/"
3247
- "/internal/service/cloudwatch/"
3348
- "/internal/service/invoicing/"
3449

@@ -43,6 +58,7 @@ rules:
4358
- pattern-not-inside: smerr.AddError(...)
4459
paths:
4560
include:
61+
- "/internal/service/appsync/"
4662
- "/internal/service/cloudwatch/"
4763
- "/internal/service/invoicing/"
4864

@@ -53,6 +69,7 @@ rules:
5369
pattern: create.AddError(&$RESP.Diagnostics, ...)
5470
paths:
5571
include:
72+
- "/internal/service/appsync/"
5673
- "/internal/service/cloudwatch/"
5774
- "/internal/service/invoicing/"
5875

@@ -65,6 +82,7 @@ rules:
6582
- pattern-not-inside: smerr.AddError(...)
6683
paths:
6784
include:
85+
- "/internal/service/appsync/"
6886
- "/internal/service/cloudwatch/"
6987
- "/internal/service/invoicing/"
7088

@@ -75,6 +93,7 @@ rules:
7593
pattern: diag.AppendErrorf(...)
7694
paths:
7795
include:
96+
- "/internal/service/appsync/"
7897
- "/internal/service/cloudwatch/"
7998
- "/internal/service/invoicing/"
8099

@@ -85,19 +104,21 @@ rules:
85104
pattern: diag.AppendFromErr(...)
86105
paths:
87106
include:
107+
- "/internal/service/appsync/"
88108
- "/internal/service/cloudwatch/"
89109
- "/internal/service/invoicing/"
90110

91111
- id: go-no-direct-diag-append
92112
languages: [go]
93-
message: Use smerr.EnrichAppend() or smerr.AddOne() instead of resp.Diagnostics.Append (migrate to smarterr/smerr).
113+
message: Use smerr.EnrichAppend() or smerr.EnrichAppendDiagnostic() instead of resp.Diagnostics.Append (migrate to smarterr/smerr).
94114
severity: ERROR
95115
patterns:
96116
- pattern: $RESP.Diagnostics.Append(...)
97117
- pattern-not-inside: smerr.EnrichAppend(...)
98-
- pattern-not-inside: smerr.AddOne(...)
118+
- pattern-not-inside: smerr.EnrichAppendDiagnostic(...)
99119
paths:
100120
include:
121+
- "/internal/service/appsync/"
101122
- "/internal/service/cloudwatch/"
102123
- "/internal/service/invoicing/"
103124

@@ -112,8 +133,45 @@ rules:
112133
return nil, smarterr.NewError(...)
113134
paths:
114135
include:
136+
- "/internal/service/appsync/"
137+
- "/internal/service/cloudwatch/"
138+
- "/internal/service/invoicing/"
139+
140+
- id: go-no-bare-return-value-err
141+
languages: [go]
142+
message: Return errors wrapped with smarterr.NewError (migrate to smarterr).
143+
severity: ERROR
144+
patterns:
145+
- pattern: |
146+
return $VALUE, $ERR
147+
- pattern-not: |
148+
return $VALUE, nil
149+
- pattern-not-inside: |
150+
return $VALUE, smarterr.NewError(...)
151+
paths:
152+
include:
153+
- "/internal/service/appsync/"
154+
- "/internal/service/cloudwatch/"
155+
- "/internal/service/invoicing/"
156+
exclude:
157+
- "*_test.go"
158+
159+
- id: go-no-tfresource-notfound
160+
languages: [go]
161+
message: Use intretry.NotFound instead of tfresource.NotFound (migrate to smarterr).
162+
severity: ERROR
163+
patterns:
164+
- pattern: |
165+
tfresource.NotFound($ERR)
166+
- pattern-not-inside: |
167+
intretry.NotFound(...)
168+
paths:
169+
include:
170+
- "/internal/service/appsync/"
115171
- "/internal/service/cloudwatch/"
116172
- "/internal/service/invoicing/"
173+
exclude:
174+
- "*_test.go"
117175

118176
- id: go-no-bare-assertsinglevalueresult
119177
languages: [go]
@@ -125,8 +183,78 @@ rules:
125183
- pattern-not-inside: smarterr.Assert(tfresource.AssertSingleValueResult(...))
126184
paths:
127185
include:
186+
- "/internal/service/appsync/"
187+
- "/internal/service/cloudwatch/"
188+
- "/internal/service/invoicing/"
189+
190+
- id: go-no-fmt-errorf-return
191+
languages: [go]
192+
message: Use smarterr.NewError(err) instead of fmt.Errorf in helper functions (migrate to smarterr).
193+
severity: ERROR
194+
patterns:
195+
- pattern: |
196+
return fmt.Errorf($MSG, ..., $ERR)
197+
- pattern-not-inside: smarterr.NewError(...)
198+
paths:
199+
include:
200+
- "/internal/service/appsync/"
201+
- "/internal/service/cloudwatch/"
202+
- "/internal/service/invoicing/"
203+
exclude:
204+
- "*_test.go"
205+
206+
- id: go-no-staterefreshfunc-bare-error
207+
languages: [go]
208+
message: Use smarterr.NewError(err) instead of bare err in StateRefreshFunc returns (migrate to smarterr).
209+
severity: ERROR
210+
patterns:
211+
- pattern: |
212+
return nil, "", $ERR
213+
- pattern-not: |
214+
return nil, "", smarterr.NewError(...)
215+
- pattern-not: |
216+
return nil, "", nil
217+
paths:
218+
include:
219+
- "/internal/service/appsync/"
220+
- "/internal/service/cloudwatch/"
221+
- "/internal/service/invoicing/"
222+
exclude:
223+
- "*_test.go"
224+
225+
- id: go-no-unexpected-format-fmt-errorf
226+
languages: [go]
227+
message: Use smarterr.NewError(fmt.Errorf(...)) instead of bare fmt.Errorf with "unexpected format" (migrate to smarterr).
228+
severity: ERROR
229+
patterns:
230+
- pattern: |
231+
return ..., fmt.Errorf("...unexpected format...", ...)
232+
- pattern-not: |
233+
return ..., smarterr.NewError(fmt.Errorf("...unexpected format...", ...))
234+
paths:
235+
include:
236+
- "/internal/service/appsync/"
237+
- "/internal/service/cloudwatch/"
238+
- "/internal/service/invoicing/"
239+
exclude:
240+
- "*_test.go"
241+
242+
- id: go-no-stdlib-append-diagnostics
243+
languages: [go]
244+
message: Use smerr.EnrichAppend(ctx, &diags, ...) instead of standard library append with diagnostics (migrate to smarterr).
245+
severity: ERROR
246+
patterns:
247+
- pattern: |
248+
return append($DIAGS, ...)
249+
- pattern-not: |
250+
smerr.EnrichAppend(...)
251+
paths:
252+
include:
253+
- "/internal/service/appsync/"
128254
- "/internal/service/cloudwatch/"
129255
- "/internal/service/invoicing/"
256+
exclude:
257+
- "*_test.go"
130258

131259
- id: go-no-bare-empty-result-error
132260
languages: [go]
@@ -138,5 +266,6 @@ rules:
138266
- pattern-not-inside: smarterr.NewError(tfresource.NewEmptyResultError(...))
139267
paths:
140268
include:
269+
- "/internal/service/appsync/"
141270
- "/internal/service/cloudwatch/"
142271
- "/internal/service/invoicing/"

.github/workflows/smarterr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
path: ~/go/pkg/mod
4343
key: ${{ runner.os }}-go-pkg-mod-${{ hashFiles('go.sum') }}
4444
# long-running test
45-
- uses: YakDriver/check-smarterr-config@6c840c1f0df56a8b550b159c7496770c28c75e51 # v0.3.0
45+
- uses: YakDriver/check-smarterr-config@v0.4.0
4646
name: Check smarterr config
4747
with:
4848
base-dir: './internal'

0 commit comments

Comments
 (0)