Skip to content

Commit

Permalink
fix panic when get with table output for resource w/o expected output (
Browse files Browse the repository at this point in the history
…#168)

`flytectl get task/workflow/launchplan -o table` panics if resource has no expected output.
We encountered `FormatVariableDescriptions at pkg/printer/printer.go:173` to panic when using
the get commands on a resource without expected output.
This happened with both explicit table output as well as default.

Replicated on lastest master, workflow demo-1.no-output has no expected output:

```
$ go run ./main.go get launchplans -p demo-1 -d production --latest demo-1.no-output

panic: assignment to entry in nil map

goroutine 1 [running]:
github.com/flyteorg/flytectl/pkg/printer.FormatVariableDescriptions(0x0)
	/workspace/flyteorg/flytectl/pkg/printer/printer.go:202 +0x307
github.com/flyteorg/flytectl/cmd/get.LaunchplanToTableProtoMessages({0xc000a30938, 0x1, 0x7ffeefbff977})
	/workspace/flyteorg/flytectl/cmd/get/launch_plan.go:136 +0xee
github.com/flyteorg/flytectl/cmd/get.getLaunchPlanFunc({0x2dfbf98, 0xc0000580b8}, {0xc0002fb8c0, 0x1, 0x11519b4}, {{0x2e55850, 0xc000a30120}, {0x2e472c0, 0xc0009a3110}, {0x2ddff60, ...}, ...})
	/workspace/flyteorg/flytectl/cmd/get/launch_plan.go:158 +0x307
github.com/flyteorg/flytectl/cmd/core.generateCommandFunc.func1(0xc000481680, {0xc0002fb8c0, 0x1, 0x6})
	/workspace/flyteorg/flytectl/cmd/core/cmd.go:69 +0x47d
github.com/spf13/cobra.(*Command).execute(0xc000481680, {0xc0002fb860, 0x6, 0x6})
	/workspace/go/pkg/mod/github.com/spf13/[email protected]/command.go:852 +0x60e
github.com/spf13/cobra.(*Command).ExecuteC(0xc000480000)
	/workspace/go/pkg/mod/github.com/spf13/[email protected]/command.go:960 +0x3ad
github.com/spf13/cobra.(*Command).Execute(...)
	/workspace/go/pkg/mod/github.com/spf13/[email protected]/command.go:897
github.com/flyteorg/flytectl/cmd.ExecuteCmd()
	/workspace/flyteorg/flytectl/cmd/root.go:135 +0x1e
main.main()
	/workspace/flyteorg/flytectl/main.go:12 +0x1d
exit status 2
```

Simple fix:
nil checks exists for container but not on the map itself prior to calling, and nil input causes the panic.
Added nil check on map parameter prior to calling in all places found.

Signed-off-by: Viktor Gerdin <[email protected]>
  • Loading branch information
vglocus authored Aug 31, 2021
1 parent 1cf79c1 commit 70c47ed
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion flytectl/cmd/get/launch_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func LaunchplanToTableProtoMessages(l []*admin.LaunchPlan) []proto.Message {
if m.Closure.ExpectedInputs != nil {
printer.FormatParameterDescriptions(m.Closure.ExpectedInputs.Parameters)
}
if m.Closure.ExpectedOutputs != nil {
if m.Closure.ExpectedOutputs != nil && m.Closure.ExpectedOutputs.Variables != nil {
printer.FormatVariableDescriptions(m.Closure.ExpectedOutputs.Variables)
}
}
Expand Down
4 changes: 2 additions & 2 deletions flytectl/cmd/get/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ func TaskToTableProtoMessages(l []*admin.Task) []proto.Message {
if m.Closure != nil && m.Closure.CompiledTask != nil {
if m.Closure.CompiledTask.Template != nil {
if m.Closure.CompiledTask.Template.Interface != nil {
if m.Closure.CompiledTask.Template.Interface.Inputs != nil {
if m.Closure.CompiledTask.Template.Interface.Inputs != nil && m.Closure.CompiledTask.Template.Interface.Inputs.Variables != nil {
printer.FormatVariableDescriptions(m.Closure.CompiledTask.Template.Interface.Inputs.Variables)
}
if m.Closure.CompiledTask.Template.Interface.Outputs != nil {
if m.Closure.CompiledTask.Template.Interface.Outputs != nil && m.Closure.CompiledTask.Template.Interface.Outputs.Variables != nil {
printer.FormatVariableDescriptions(m.Closure.CompiledTask.Template.Interface.Outputs.Variables)
}
}
Expand Down
4 changes: 2 additions & 2 deletions flytectl/cmd/get/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ func WorkflowToTableProtoMessages(l []*admin.Workflow) []proto.Message {
if m.Closure.CompiledWorkflow.Primary != nil {
if m.Closure.CompiledWorkflow.Primary.Template != nil {
if m.Closure.CompiledWorkflow.Primary.Template.Interface != nil {
if m.Closure.CompiledWorkflow.Primary.Template.Interface.Inputs != nil {
if m.Closure.CompiledWorkflow.Primary.Template.Interface.Inputs != nil && m.Closure.CompiledWorkflow.Primary.Template.Interface.Inputs.Variables != nil {
printer.FormatVariableDescriptions(m.Closure.CompiledWorkflow.Primary.Template.Interface.Inputs.Variables)
}
if m.Closure.CompiledWorkflow.Primary.Template.Interface.Outputs != nil {
if m.Closure.CompiledWorkflow.Primary.Template.Interface.Outputs != nil && m.Closure.CompiledWorkflow.Primary.Template.Interface.Outputs.Variables != nil {
printer.FormatVariableDescriptions(m.Closure.CompiledWorkflow.Primary.Template.Interface.Outputs.Variables)
}
}
Expand Down

0 comments on commit 70c47ed

Please sign in to comment.