Skip to content

[Bug] Panic in version checker corrupts JSON output after successful API calls #358

@ValentinSattinger

Description

@ValentinSattinger

What is the problem?

The Twitch CLI panics after successfully outputting JSON from API calls. The panic occurs in the version checker and corrupts the output, making it impossible to parse programmatically with tools like jq.

Operating System

macOS 15.6 (Darwin 24.6.0), CLI Version: twitch-cli/1.1.24

Architecture Version (x86, x64, arm, etc)

ARM64

Steps to reproduce

  1. Run any API command that returns JSON:
    twitch api get "extensions/transactions?extension_id=<extension-id>&first=2"
  2. Observe that valid JSON is output first, followed by a panic:

goroutine 1 [running]:
github.com/twitchdev/twitch-cli/internal/util.areWeRunningLatestVersion()
	/go/src/github.com/twitchdev/twitch-cli/internal/util/version_checker.go:121 +0x48c

Expected Behavior:
CLI should output clean JSON without panicking, or the version check should be separate from command execution.
Actual Behavior:
Every command (including twitch version) panics after execution, mixing panic output with valid JSON/output.

Impact:

  • Cannot pipe CLI output to jq or other JSON parsers
  • Scripts that rely on parsing CLI output fail
  • Even twitch version command panics with exit code 2

Workaround:
Filter out panic lines before parsing:
twitch api get "..." 2>&1 | awk '/^panic:/ {exit} /^goroutine/ {exit} {print}' | jq

Relevant log output

{
  "data": [
    {
      "broadcaster_id": "REDACTED",
      "product_data": {
        "cost": {
          "amount": 300,
          "type": "bits"
        }
      }
    }
  ],
  "pagination": {
    "cursor": "..."
  }
}
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/twitchdev/twitch-cli/internal/util.areWeRunningLatestVersion()
	/go/src/github.com/twitchdev/twitch-cli/internal/util/version_checker.go:121 +0x48c
github.com/twitchdev/twitch-cli/internal/util.CheckForUpdatesAndPrintNotice()
	/go/src/github.com/twitchdev/twitch-cli/internal/util/version_checker.go:46 +0x120

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions