Skip to content

Commit

Permalink
Panic if the provided path is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
mgyucht committed Dec 11, 2024
1 parent b1f0847 commit ed7b0ec
Showing 1 changed file with 5 additions and 5 deletions.
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))
}

0 comments on commit ed7b0ec

Please sign in to comment.