Conversation
|
Run: https://github.com/elastic/terraform-provider-elasticstack/actions/runs/23486141485 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| for actionName, action := range p { | ||
| if a := action.([]any); len(a) > 0 { |
There was a problem hiding this comment.
🟢 Low ilm/expand.go:58
The type assertion action.([]any) on line 59 panics at runtime if action has any other type, such as nil or a different concrete type. This happens before the len(a) > 0 check, so malformed input causes a crash rather than a handled error. Consider using the two-return form a, ok := action.([]any) and skipping the action if !ok, or returning a diagnostic error.
- if a := action.([]any); len(a) > 0 {🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file internal/elasticsearch/index/ilm/expand.go around lines 58-59:
The type assertion `action.([]any)` on line 59 panics at runtime if `action` has any other type, such as `nil` or a different concrete type. This happens before the `len(a) > 0` check, so malformed input causes a crash rather than a handled error. Consider using the two-return form `a, ok := action.([]any)` and skipping the action if `!ok`, or returning a diagnostic error.
Evidence trail:
internal/elasticsearch/index/ilm/expand.go lines 48-59 (REVIEWED_COMMIT) - shows `expandPhase(p map[string]any, ...)` and line 59 `if a := action.([]any); len(a) > 0 {`
internal/elasticsearch/index/ilm/model_expand.go lines 83-127 (REVIEWED_COMMIT) - `attrValueToExpandRaw` returns `string`, `int64`, `bool`, or `[]any` depending on type
internal/elasticsearch/index/ilm/model_expand.go lines 49-51 (REVIEWED_COMMIT) - `applyAllocateJSONDefaults` uses defensive comma-ok form: `allocList, ok := allocRaw.([]any); if !ok || len(allocList) == 0 { return }`
| if v, ok := action.(map[string]any)[setting]; ok && v != nil { | ||
| options := ilmActionSettingOptions[setting] | ||
|
|
||
| if options.minVersion != nil && options.minVersion.GreaterThan(serverVersion) { |
There was a problem hiding this comment.
🟢 Low ilm/expand.go:138
When serverVersion is nil, the call to options.minVersion.GreaterThan(serverVersion) at line 138 panics with a nil pointer dereference. This can occur when the Elasticsearch server version cannot be determined. Consider adding a nil check before the version comparison, or handling the nil serverVersion case explicitly.
- if options.minVersion != nil && options.minVersion.GreaterThan(serverVersion) {
+ if options.minVersion != nil && serverVersion != nil && options.minVersion.GreaterThan(serverVersion) {🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file internal/elasticsearch/index/ilm/expand.go around line 138:
When `serverVersion` is `nil`, the call to `options.minVersion.GreaterThan(serverVersion)` at line 138 panics with a nil pointer dereference. This can occur when the Elasticsearch server version cannot be determined. Consider adding a nil check before the version comparison, or handling the nil `serverVersion` case explicitly.
Evidence trail:
internal/elasticsearch/index/ilm/expand.go:138 (REVIEWED_COMMIT) - shows code `if options.minVersion != nil && options.minVersion.GreaterThan(serverVersion)` which only checks `options.minVersion` for nil, not `serverVersion`. github.com/hashicorp/go-version version.go:110-118 shows `Compare` method immediately calls `other.String()` without nil check. github.com/hashicorp/go-version version.go:286-288 shows `GreaterThan` simply returns `v.Compare(o) > 0` with no nil handling. Compare with `Equal` method (lines 279-284) which does have nil handling: `if v == nil || o == nil { return v == o }`.
Related to #482
Note
Migrate
elasticstack_elasticsearch_index_lifecycleresource to the Plugin Frameworkhot.0.rollover.*) withSingleNestedBlockobject-shaped attributes (e.g.hot.rollover.*) across all ILM phases and actions in the new schema.go.PutIlm,GetIlm, andDeleteIlmin index.go from SDK diagnostics to framework-stylefwdiags.Diagnostics.TestAccResourceILMFromSDK) verifying state compatibility between the legacy SDK provider (0.14.3) and the new framework-based provider.hot.0.*will break.Macroscope summarized 1712951.