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

return nil instead of empty map #13

Merged
merged 2 commits into from
Dec 21, 2022
Merged

return nil instead of empty map #13

merged 2 commits into from
Dec 21, 2022

Conversation

jhsinger-klotho
Copy link
Contributor

• Does any part of it require special attention?
• Does it relate to or fix any issue?

fixes the bug

Standard checks

  • Unit tests: Any special considerations?
  • Docs: Do we need to update any docs, internal or public?
  • Backwards compatibility: Will this break existing apps? If so, what would be the extra work required to keep them working?

@github-actions
Copy link

Package Line Rate Health
github.com/klothoplatform/klotho/pkg/analytics 2%
github.com/klothoplatform/klotho/pkg/annotation 24%
github.com/klothoplatform/klotho/pkg/core 21%
github.com/klothoplatform/klotho/pkg/env_var 82%
github.com/klothoplatform/klotho/pkg/exec_unit 41%
github.com/klothoplatform/klotho/pkg/infra/kubernetes 56%
github.com/klothoplatform/klotho/pkg/infra/kubernetes/helm 52%
github.com/klothoplatform/klotho/pkg/input 63%
github.com/klothoplatform/klotho/pkg/lang 37%
github.com/klothoplatform/klotho/pkg/lang/dockerfile 0%
github.com/klothoplatform/klotho/pkg/lang/golang 9%
github.com/klothoplatform/klotho/pkg/lang/javascript 46%
github.com/klothoplatform/klotho/pkg/lang/python 60%
github.com/klothoplatform/klotho/pkg/lang/yaml 0%
github.com/klothoplatform/klotho/pkg/logging 7%
github.com/klothoplatform/klotho/pkg/multierr 95%
github.com/klothoplatform/klotho/pkg/provider/aws 54%
github.com/klothoplatform/klotho/pkg/runtime 75%
github.com/klothoplatform/klotho/pkg/static_unit 22%
github.com/klothoplatform/klotho/pkg/validation 70%
Summary 41% (3472 / 8437)

@jhsinger-klotho jhsinger-klotho merged commit 25449d6 into main Dec 21, 2022
@jhsinger-klotho jhsinger-klotho deleted the nil_directives branch December 21, 2022 22:20
@@ -87,7 +87,7 @@ func (d Directives) Int(key string) (int, bool) {
func (d Directives) Object(key string) Directives {
v, ok := d[key]
if !ok {
return make(Directives)
return nil
}
m, ok := v.(map[string]interface{})
if !ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following line should also be nil, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it exists but theres nothing in the map, then we should likely keep it? I pushed this already but can make changes if we need

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other question is does anything outside of env vars use this today?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if !ok on the type assertion would mean that e.g. environment_variable = 10 - that it's not a table. IMO it should be treated the same as if it weren't set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that maybe we would want to error and say that its set to an incorrect type even, should i add a card for this? I dont think weve really touched the logic of directives too much. Were unblocked for now but youre right we may want to add more to this

keyType, pResult := p.determinePersistType(f, annot)
if pResult == nil {
if annot.Capability.Directives.Object(core.EnvironmentVariableDirective) != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if annot.Capability.Directives.Object(core.EnvironmentVariableDirective) != nil {
if len(annot.Capability.Directives.Object(core.EnvironmentVariableDirective)) == 0 {

This will work for both nil and empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesnt let you do len on that object

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah you'd have to len(map[string]interface{}(..)) maybe worth adding a method to Directive at some point (receivers can be nil).

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

Successfully merging this pull request may close these issues.

3 participants