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

[ISSUE] Gracefully handle incorrect aliases in CustomizableSchema #4129

Open
alexott opened this issue Oct 20, 2024 · 0 comments
Open

[ISSUE] Gracefully handle incorrect aliases in CustomizableSchema #4129

alexott opened this issue Oct 20, 2024 · 0 comments

Comments

@alexott
Copy link
Contributor

alexott commented Oct 20, 2024

I had a code that needs an alias and at some point I was need to change struct name from queryStruct to QueryStruct, but I forgot to update Aliases, so after renaming it stay the same

func (QueryStruct) Aliases() map[string]map[string]string {
	return map[string]map[string]string{
		"sql.queryStruct": queryAliasMap,
	}
}

And it leads to the crash in StructToSchema, like this:

github.com/databricks/terraform-provider-databricks/common.MustSchemaPath(...)
	/Users/.../terraform-provider-databricks/common/reflect_resource.go:232
github.com/databricks/terraform-provider-databricks/common.(*CustomizableSchema).SchemaPath(0x14000310600, {0x14000113ea0, 0x2, 0x2})
	/Users/.../terraform-provider-databricks/common/customizable_schema.go:62 +0x10c
github.com/databricks/terraform-provider-databricks/sql.QueryStruct.CustomizeSchema({{0x0, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, ...}, ...}}, ...)
	/Users/.../terraform-provider-databricks/sql/resource_query.go:45 +0x460
github.com/databricks/terraform-provider-databricks/common.resourceProviderStructToSchemaInternal({0x1046fbe98, 0x140005ab040}, {{0x103ef1d20, 0x0, 0x0}, {0x103ef1d20, 0x0, 0x0}})
	/Users/.../terraform-provider-databricks/common/reflect_resource.go:155 +0x560
github.com/databricks/terraform-provider-databricks/common.resourceProviderStructToSchema({0x1046fbe98, 0x140005ab040}, {{0x103ef1d20, 0x0, 0x0}, {0x103ef1d20, 0x0, 0x0}})
	/Users/.../terraform-provider-databricks/common/reflect_resource.go:132 +0x48
github.com/databricks/terraform-provider-databricks/common.StructToSchema({0x103328040?, 0x140005ab040?}, 0x0)
	/Users/.../terraform-provider-databricks/common/reflect_resource.go:252 +0x94
github.com/databricks/terraform-provider-databricks/sql.ResourceQuery()
	/Users/.../terraform-provider-databricks/sql/resource_query.go:95 +0x74
github.com/databricks/terraform-provider-databricks/internal/providers/sdkv2.DatabricksProvider()
	/Users/.../terraform-provider-databricks/internal/providers/sdkv2/sdkv2.go:192 +0x788c
github.com/databricks/terraform-provider-databricks/internal/providers.GetProviderServer({0x1034caf40, 0x103ef1d20}, {0x0, 0x0, 0x140003afed8?})
	/Users/.../terraform-provider-databricks/internal/providers/providers.go:63 +0x9c
main.main()
	/Users/.../terraform-provider-databricks/main.go:41 +0x268

We need to gracefully handle such cases:

  • throw an error (or panic) with a message that a struct with a given name doesn't exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant