Skip to content

fix(cli): prevent crash when displaying incomplete test workflow executions#6942

Open
zucchinidev wants to merge 1 commit intokubeshop:mainfrom
zucchinidev:fix/cli-nil-workflow-panic
Open

fix(cli): prevent crash when displaying incomplete test workflow executions#6942
zucchinidev wants to merge 1 commit intokubeshop:mainfrom
zucchinidev:fix/cli-nil-workflow-panic

Conversation

@zucchinidev
Copy link
Copy Markdown

Pull request description

When API connectivity issues cause incomplete execution data to be received, the CLI would crash with an unhelpful nil pointer error, preventing users from diagnosing the underlying problem.

This change ensures graceful degradation by detecting missing workflow references and displaying a clear error message with actionable guidance about common causes such as API endpoint misconfiguration.

Users can now view available execution details even when workflow metadata is incomplete, significantly improving the troubleshooting experience.

Closes #6891

Checklist (choose whats happened)

  • breaking change! (describe)
  • tested locally
  • tested on cluster
  • added new dependencies
  • updated the docs
  • added a test

Breaking changes

  • None

Changes

File: cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go

  • Added nil check for execution.Workflow before accessing its fields
  • Display clear error message when workflow metadata is missing
  • Provide actionable hint about common causes (HTTP vs HTTPS misconfiguration)
  • Continue rendering available execution details for troubleshooting

File: cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj_test.go (new)

  • TestPrintPrettyOutput_NilWorkflow - Verifies no panic with nil workflow reference
  • TestPrintPrettyOutput_NilWorkflowWithInitError - Tests edge case with initialization errors
  • TestPrintPrettyOutput_ValidWorkflow - Regression test ensuring normal flow still works

Fixes

Issue #6891 - CLI panic when displaying test workflow executions with incomplete data

Root Cause

testworkflowexecution_obj.go accessed execution.Workflow.Name without checking if execution.Workflow was nil, causing a panic when the API returned incomplete data.

Testing Performed

  1. Unit Tests:
  === RUN   TestPrintPrettyOutput_NilWorkflow
  --- PASS: TestPrintPrettyOutput_NilWorkflow (0.00s)
  === RUN   TestPrintPrettyOutput_NilWorkflowWithInitError
  --- PASS: TestPrintPrettyOutput_NilWorkflowWithInitError (0.00s)
  === RUN   TestPrintPrettyOutput_ValidWorkflow
  --- PASS: TestPrintPrettyOutput_ValidWorkflow (0.00s)
  PASS
  1. Integration Testing (Kind Cluster):
  • Installed TestWorkflow CRDs in Kubernetes cluster
  • Created TestWorkflow via CLI: testkube create testworkflow -f panic-demo-workflow.yaml
  • Executed workflow to generate real execution: testkube run testworkflow panic-demo
  • Verified execution retrieval works with valid workflow reference
  • Simulated incomplete data by setting workflow: null in MongoDB
  • Confirmed fix handles corrupted data gracefully

Before (Panic - Buggy Code)

Scenario: Execution with workflow: null in database

  $ ./bin/app/testkube get testworkflowexecution 695c386f1b9db186b2aa8b38 --client direct

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

  goroutine 1 [running]:
  github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer.printPrettyOutput(...)
      .../testworkflowexecution_obj.go:53 +0x48
  github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer.TestWorkflowExecutionRenderer(...)
      .../testworkflowexecution_obj.go:47 +0xac
  ...

User Impact: CLI crashes, no execution details shown, no guidance on how to fix.

After (Graceful Error - With Fix)

Scenario 1: Valid execution with workflow reference

$ ./bin/app/testkube get testworkflowexecution 695c386f1b9db186b2aa8b38 --client direct

  Test Workflow Execution:
  Name:                 panic-demo
  Execution ID:         695c386f1b9db186b2aa8b38
  Execution name:       panic-demo-1
  Execution namespace:
  Execution number:     1
  Requested at:         2026-01-05 22:17:19.454 +0000 UTC
  Disabled webhooks:    false
  Status:               running
  Queued at:            2026-01-05 22:17:21 +0000 UTC
  Started at:           2026-01-05 22:17:21 +0000 UTC

✅ Normal operation - works perfectly

Scenario 2: Execution with workflow: null (corrupted data)

$ ./bin/app/testkube get testworkflowexecution 695c386f1b9db186b2aa8b38 --client direct

  Test Workflow Execution:

  ⨯ incomplete execution data received from API: missing Workflow field 💔
  Hint: check your API endpoint configuration (HTTP vs HTTPS) and API server accessibility
  Execution ID:         695c386f1b9db186b2aa8b38
  Execution name:       panic-demo-1
  Execution namespace:
  Execution number:     1
  Requested at:         2026-01-05 22:17:19.454 +0000 UTC
  Disabled webhooks:    false
  Status:               running
  Queued at:            2026-01-05 22:17:21 +0000 UTC
  Started at:           2026-01-05 22:17:21 +0000 UTC

✅ Graceful error handling - no panic, clear guidance, execution details still visible

User Impact: Users get actionable error message, can still see execution details, and know where to look for the problem

@zucchinidev zucchinidev requested a review from a team as a code owner January 5, 2026 22:55
ui.Warn("Name: ", execution.Workflow.Name)
} else {
ui.NL()
ui.Err(errors.New("incomplete execution data received from API: missing Workflow field"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could/should we output any other fields from the execution object that could be helpful in troubleshooting?

Copy link
Copy Markdown
Author

@zucchinidev zucchinidev Jan 6, 2026

Choose a reason for hiding this comment

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

Hi @olensmar,

Thank you for taking the time to review this PR and for the thoughtful feedback. I really appreciate the guidance.

Great question about additional troubleshooting fields. The current implementation follows a graceful degradation approach: when workflow is nil, we display all available execution metadata that doesn't depend on the workflow reference. Currently this includes:

Currently displayed:

  • Execution identifiers (ID, name, namespace, number)
  • Timing information (scheduledAt, queuedAt, startedAt, finishedAt, duration)
  • Execution status and configuration (status, disableWebhooks, tags)
  • Initialization errors (if present)

Additional fields that could aid troubleshooting:

  1. runnerId - Shows which runner processed this execution
  2. statusAt - When the status last changed (currently we show scheduledAt but not statusAt)
  3. groupId - Helps identify correlated executions in the same batch/group
  4. resolvedWorkflow.name - If workflow is nil but resolvedWorkflow exists, it could show the actual executed workflow

The logic is currently at testworkflowexecution_obj.go:54-82 where we display fields inside the if execution.Id != "" block.

Proposed Enhancement (if valuable)

I'd propose adding these 3 specific fields when workflow is missing, as they directly answer key troubleshooting questions:

  1. runnerId (HIGH value)
  • Why: Identifies which runner had the issue
  • Troubleshooting: "Are all failures from one runner?" → runner-specific config/connectivity problem
  • Use case: Correlate with infrastructure logs for that specific runner
  1. statusAt (HIGH value)
  • Why: Shows when status last changed
  • Troubleshooting: Compare timeline (scheduledAt → statusAt → queuedAt) to determine if workflow was missing from creation or became null later
  • Use case: Correlate with API restart times or network outage windows
  1. groupId (MEDIUM value)
  • Why: If part of a batch, determines scope of problem
  • Troubleshooting: "One execution or entire batch affected?" → different root causes
  • Use case: Identify parallel execution issues vs isolated failures

Implementation location: Display these right after the error/hint (line ~60), making them prominent for troubleshooting:

} else {
    ui.NL()
    ui.Err(errors.New("incomplete execution data received from API: missing Workflow field"))
    ui.Warn("Hint: check your API endpoint configuration (HTTP vs HTTPS) and API server accessibility")
    ui.NL()
    
    // Troubleshooting context
    if execution.RunnerId != "" {
        ui.Warn("Runner ID:           ", execution.RunnerId)
    }
    if !execution.StatusAt.IsZero() {
        ui.Warn("Status changed at:   ", execution.StatusAt.String())
    }
    if execution.GroupId != "" {
        ui.Warn("Group ID:            ", execution.GroupId)
    }
}

This keeps the change minimal (3 fields) while maximizing diagnostic value. Happy to implement this if you think it adds value, or take a different approach based on your experience with these types of issues.

Would you like me to:

  • Proceed with this selective enhancement?
  • Go with a different set of fields?
  • Keep the current implementation as-is (minimal fix)?

Thanks again for the review and guidance!

…utions

When API connectivity issues cause incomplete execution data to be received,
the CLI would crash with an unhelpful nil pointer error, preventing users
from diagnosing the underlying problem.

This change ensures graceful degradation by detecting missing workflow
references and displaying a clear error message with actionable guidance
about common causes such as API endpoint misconfiguration.

Users can now view available execution details even when workflow metadata
is incomplete, significantly improving the troubleshooting experience.

Closes kubeshop#6891
@zucchinidev zucchinidev force-pushed the fix/cli-nil-workflow-panic branch from 685931a to 7f461c0 Compare January 6, 2026 16:57
@zucchinidev zucchinidev requested a review from olensmar January 9, 2026 13:37
@olensmar olensmar added the 👽 external-contribution External contribution label Jan 17, 2026
@vsukhin
Copy link
Copy Markdown
Collaborator

vsukhin commented Feb 20, 2026

@greptile

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Feb 20, 2026

Greptile Summary

This PR fixes a nil pointer panic in the CLI when displaying test workflow executions with incomplete data by adding a nil check for execution.Workflow before accessing its fields.

Key changes:

  • Added defensive nil check in printPrettyOutput() at testworkflowexecution_obj.go:54-60
  • Displays clear error message with actionable troubleshooting hints when workflow metadata is missing
  • Allows users to view available execution details even with incomplete data
  • Added comprehensive test coverage for nil workflow scenarios

Observations:

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - it adds defensive error handling without changing core logic
  • Score reflects solid implementation and comprehensive testing. The fix directly addresses the panic issue with proper nil checking. Minor style improvements suggested in tests (explicit nil assignments), but these don't affect functionality. Other files (abort.go, cancel.go) also access execution.Workflow.Name without nil checks, though they may have different context where workflow is guaranteed to exist.
  • No files require special attention - the changes are straightforward and well-tested

Important Files Changed

Filename Overview
cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go Added nil check for execution.Workflow to prevent panic, displays helpful error message when workflow metadata is missing
cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj_test.go New test file with comprehensive coverage for nil workflow scenarios, minor style improvements possible

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[printPrettyOutput called] --> B{execution.Workflow != nil?}
    B -->|Yes| C[Display workflow name]
    B -->|No| D[Display newline]
    D --> E[Show error: incomplete execution data]
    E --> F[Show hint about API configuration]
    C --> G[Continue with execution details]
    F --> G
    G --> H{execution.Id != empty?}
    H -->|Yes| I[Display execution metadata]
    H -->|No| J[Skip metadata]
    I --> K{Has initialization error?}
    J --> K
    K -->|Yes| L[Display initialization error]
    K -->|No| M[End]
    L --> M
Loading

Last reviewed commit: 7f461c0

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Id: "test-id",
Name: "test-name",
Namespace: "test-namespace",
Workflow: nil,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

explicit nil is unnecessary - omit Workflow field since zero value is already nil

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Id: "test-id",
Name: "test-name",
Namespace: "test-namespace",
Workflow: nil,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

explicit nil is unnecessary - omit Workflow field since zero value is already nil

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Collaborator

@vsukhin vsukhin left a comment

Choose a reason for hiding this comment

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

hey @zucchinidev DId you see this issue, because execution.Workflow can't be nil by design, it's created with this fileld?

@olensmar
Copy link
Copy Markdown
Member

olensmar commented Mar 3, 2026

@zucchinidev please address review comments above - looks great otherwise!

@zucchinidev
Copy link
Copy Markdown
Author

zucchinidev commented Mar 8, 2026

Thanks for the review, @vsukhin @olensmar! You're right that under normal conditions the Workflow field should always be populated. However, two things worth noting:

  1. The field is a *testkube.TestWorkflow pointer, so it is structurally nullable and can be nil when the API returns a partial response, for example due to HTTP vs HTTPS misconfiguration, as reported in CLI Panic with Unhelpful Error When API Returns Incomplete Execution Object #6891.
  2. rerun.go already has a nil guard for the same field, which suggests the team already acknowledges this can happen in practice.

I picked this as a good first issue to contribute to the project; the crash was real and the fix is low-risk, only activating in the error path without changing normal behavior.

@vsukhin
Copy link
Copy Markdown
Collaborator

vsukhin commented Mar 9, 2026

ok, @zucchinidev please address pr feedback then. thank you!

@vsukhin
Copy link
Copy Markdown
Collaborator

vsukhin commented Mar 19, 2026

hey @zucchinidev will you be able to address the feedback or do you need our help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

👽 external-contribution External contribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI Panic with Unhelpful Error When API Returns Incomplete Execution Object

3 participants