Skip to content

Commit acead37

Browse files
authored
Enable gocritic offBy1 and fix import warning slicing (codex) (#3713)
## Changes - enable the gocritic offBy1 check in golangci-lint so we catch missing Index() bounds handling - guard the Terraform import warning truncation against missing "Warning:" blocks to avoid slice panics ------ https://chatgpt.com/s/cd_68df8308cdf081918babe8e111fb5dce
1 parent 2bddd05 commit acead37

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ linters:
3131
disable-all: true
3232
enabled-checks:
3333
- ruleguard
34+
- offBy1
3435
settings:
3536
ruleguard:
3637
failOn: all

bundle/deploy/terraform/import.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ func (m *importResource) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagn
7171

7272
if changed && !m.opts.AutoApprove {
7373
output := buf.String()
74-
// Remove output starting from Warning until end of output
75-
output = output[:strings.Index(output, "Warning:")]
74+
// Remove output starting from Warning until end of output, if present.
75+
if idx := strings.Index(output, "Warning:"); idx != -1 {
76+
output = output[:idx]
77+
}
7678
cmdio.LogString(ctx, output)
7779

7880
if !cmdio.IsPromptSupported(ctx) {

0 commit comments

Comments
 (0)