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

[Internal] Panic if the provided path is invalid #4309

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/providers/pluginfw/tfschema/customizable_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (s *CustomizableSchema) ConvertToAttribute(path ...string) *CustomizableSch
}

// navigateSchemaWithCallback navigates through schema attributes and executes callback on the target, panics if path does not exist or invalid.
func navigateSchemaWithCallback(s *BaseSchemaBuilder, cb func(BaseSchemaBuilder) BaseSchemaBuilder, path ...string) (BaseSchemaBuilder, error) {
func navigateSchemaWithCallback(s *BaseSchemaBuilder, cb func(BaseSchemaBuilder) BaseSchemaBuilder, path ...string) {
currentScm := s
for i, p := range path {
m := attributeToNestedBlockObject(currentScm)
Expand All @@ -241,22 +241,22 @@ func navigateSchemaWithCallback(s *BaseSchemaBuilder, cb func(BaseSchemaBuilder)
if i == len(path)-1 {
newV := cb(v).(AttributeBuilder)
mAttr[p] = newV
return mAttr[p], nil
return
}
castedV := v.(BaseSchemaBuilder)
currentScm = &castedV
} else if v, ok := mBlock[p]; ok {
if i == len(path)-1 {
newV := cb(v).(BlockBuilder)
mBlock[p] = newV
return mBlock[p], nil
return
}
castedV := v.(BaseSchemaBuilder)
currentScm = &castedV
} else {
return nil, fmt.Errorf("missing key %s", p)
panic(fmt.Errorf("missing key %s", p))
}

}
return nil, fmt.Errorf("path %v is incomplete", path)
panic(fmt.Errorf("path %v is incomplete", path))
}
Loading