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
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/annotation/directive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 3 additions & 4 deletions pkg/lang/javascript/plugin_persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,11 @@ func (p *persister) handleFile(f *core.SourceFile, unit *core.ExecutionUnit) ([]
continue
}

if annot.Capability.Directives.Object(core.EnvironmentVariableDirective) != nil {
continue
}

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).

continue
}
log.Warn("Could not determine persist type")
continue
}
Expand Down
7 changes: 3 additions & 4 deletions pkg/lang/python/plugin_persist.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,11 @@ func (p *persister) handleFile(f *core.SourceFile, unit *core.ExecutionUnit) ([]
continue
}

if annot.Capability.Directives.Object(core.EnvironmentVariableDirective) != nil {
continue
}

keyType, pResult := p.determinePersistType(f, annot)
if pResult == nil {
if annot.Capability.Directives.Object(core.EnvironmentVariableDirective) != nil {
continue
}
log.Warn("Could not determine persist type")
continue
}
Expand Down