Skip to content

CLI Panic with Unhelpful Error When API Returns Incomplete Execution Object #6891

@narsdk

Description

@narsdk

Environment:

Testkube CLI version: 2.3.0

Testkube Helm Chart version: 2.1.236

Kubernetes version: 1.32 on AWS EKS

Description:

When the Testkube API returns an incomplete TestWorkflowExecution object (e.g., due to connection issues, wrong endpoint protocol, or API errors), the CLI crashes with an unhelpful segmentation fault instead of a user-friendly error message.

Steps to Reproduce:

Configure Testkube CLI to use HTTP endpoint instead of HTTPS (or any scenario where API returns incomplete data, this one worked in my case)

Run: testkube run tw test-name --watch

CLI panics with segmentation fault

Actual Output:

Test Workflow Execution:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1e0e14e]

goroutine 1 [running]:
github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer.printPrettyOutput(, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, 0x0, 0x0, {0x0, ...}, ...})
/home/runner/work/testkube/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go:53 +0x4e
github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer.PrintTestWorkflowExecution(, {_, _}, {{0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, 0x0, ...})
/home/runner/work/testkube/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go:26 +0x265
github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows.processExecutions(0xc000b86f08, {0xc00089ef20, 0x1, 0x0?}, {0x31bd728, 0xc00032d0e0}, 0x1, {0x1, {0x0, 0x0}, ...}, ...)
/home/runner/work/testkube/testkube/cmd/kubectl-testkube/commands/testworkflows/run.go:432 +0x1a7
github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows.NewRunTestWorkflowCmd.runTestWorkflow.func1(0xc000b86f08, {0xc000075780, 0x1, 0x4})
/home/runner/work/testkube/testkube/cmd/kubectl-testkube/commands/testworkflows/run.go:217 +0x6be
github.com/spf13/cobra.(*Command).execute(0xc000b86f08, {0xc000075740, 0x4, 0x4})
/home/runner/go/pkg/mod/github.com/spf13/mailto:mailto:cobra@v1.8.1/command.go:989 +0xb1b
github.com/spf13/cobra.(*Command).ExecuteC(0x49513c0)
/home/runner/go/pkg/mod/github.com/spf13/mailto:mailto:cobra@v1.8.1/command.go:1117 +0x44f
github.com/spf13/cobra.(*Command).Execute(...)
/home/runner/go/pkg/mod/github.com/spf13/mailto:mailto:cobra@v1.8.1/command.go:1041
github.com/spf13/cobra.(*Command).ExecuteContext(...)
/home/runner/go/pkg/mod/github.com/spf13/mailto:mailto:cobra@v1.8.1/command.go:1034
github.com/kubeshop/testkube/cmd/kubectl-testkube/commands.Execute()
/home/runner/work/testkube/testkube/cmd/kubectl-testkube/commands/root.go:234 +0x576
main.main()
/home/runner/work/testkube/testkube/cmd/kubectl-testkube/main.go:24 +0xf

Expected Behavior:

CLI should display a user-friendly error message such as:

Error: Failed to execute test workflow 'test-name'
Reason: API returned incomplete execution data (Workflow field is missing)
Hint: Check your API endpoint configuration and ensure the API server is accessible

Root Cause:

In testworkflowexecution_obj.go:53, the code directly accesses execution.Workflow.Name without checking if execution.Workflow is nil:

func printPrettyOutput(ui *ui.UI, execution testkube.TestWorkflowExecution) {
    ui.Info("Test Workflow Execution:")
    ui.Warn("Name:                ", execution.Workflow.Name)  // Line 53 - PANIC if Workflow is nil

Suggested Fix: (AI generated - not tested)

Add nil checks before accessing nested fields:

func printPrettyOutput(ui *ui.UI, execution testkube.TestWorkflowExecution) {
    ui.Info("Test Workflow Execution:")
    
    if execution.Workflow == nil {
        ui.Err(errors.New("incomplete execution data received from API - Workflow field is missing"))
        ui.Warn("Hint: Check your API endpoint configuration (HTTP vs HTTPS) and API server accessibility")
        return
    }
    
    ui.Warn("Name:                ", execution.Workflow.Name)
    // ... rest of the code
}

Impact:

Users waste time debugging cryptic segmentation faults

The actual issue (API connectivity/configuration) is hidden

Poor user experience for a common misconfiguration scenario

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions