Skip to content

Conversation

@betegon
Copy link
Member

@betegon betegon commented Jan 30, 2026

closes #91

Summary

Adds sentry upgrade command so users can update the CLI without remembering how they installed it.

sentry upgrade              # Update to latest
sentry upgrade 0.5.0        # Update to specific version
sentry upgrade --check      # Check for updates without installing
sentry upgrade --method npm # Force using npm

Changes

  • src/lib/upgrade.ts - Detection logic and upgrade execution
  • src/commands/upgrade.ts - Command definition with --check and --method flags
  • src/lib/errors.ts - UpgradeError class for error handling
  • src/app.ts - Register command with update alias

The command auto-detects how the CLI was installed by checking:

  1. Executable path for ~/.sentry/bin (curl install)
  2. Package manager global lists (npm, pnpm, bun, yarn)

curl installs fetch the latest version from GitHub releases; package manager installs check the npm registry.

Test plan

  • bun test test/lib/upgrade.test.ts test/commands/upgrade.test.ts - all 17 tests pass
  • Manual: sentry upgrade --check --method npm shows version info

Closes #91

🤖 Generated with Claude Code

Adds `sentry upgrade` command to update the CLI to the latest or a specific version.

- Auto-detects installation method (curl, npm, pnpm, bun, yarn)
- Fetches latest version from GitHub releases or npm registry
- Supports --check flag for dry-run mode
- Supports --method flag to override auto-detection
- Includes `update` alias

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Jan 30, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (upgrade) Add self-update command by betegon in #132

Bug Fixes 🐛

  • (telemetry) Capture command errors to Sentry by betegon in #145

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link

github-actions bot commented Jan 30, 2026

Codecov Results 📊

❌ Patch coverage is 36.19%. Project has 2008 uncovered lines.
❌ Project coverage is 68.08%. Comparing base (base) to head (head).

Files with missing lines (26)
File Patch % Lines
human.ts 31.87% ⚠️ 682 Missing
resolve-target.ts 20.82% ⚠️ 251 Missing
oauth.ts 25.10% ⚠️ 194 Missing
upgrade.ts 33.33% ⚠️ 166 Missing
api-client.ts 71.60% ⚠️ 146 Missing
resolver.ts 3.23% ⚠️ 120 Missing
errors.ts 5.94% ⚠️ 95 Missing
migration.ts 47.44% ⚠️ 82 Missing
upgrade.ts 38.78% ⚠️ 60 Missing
api.ts 89.80% ⚠️ 47 Missing
seer.ts 75.54% ⚠️ 45 Missing
seer.ts 79.87% ⚠️ 30 Missing
preload.ts 39.02% ⚠️ 25 Missing
detector.ts 87.79% ⚠️ 16 Missing
schema.ts 64.10% ⚠️ 14 Missing
auth.ts 94.78% ⚠️ 7 Missing
utils.ts 97.59% ⚠️ 4 Missing
index.ts 95.06% ⚠️ 4 Missing
colors.ts 91.84% ⚠️ 4 Missing
telemetry.ts 97.16% ⚠️ 4 Missing
env-file.ts 97.17% ⚠️ 3 Missing
sentry-urls.ts 82.35% ⚠️ 3 Missing
alias.ts 98.56% ⚠️ 2 Missing
project-aliases.ts 97.40% ⚠️ 2 Missing
java.ts 97.22% ⚠️ 1 Missing
parser.ts 98.63% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    69.98%    68.08%     -1.9%
==========================================
  Files           51        53        +2
  Lines         5926      6290      +364
  Branches         0         0         —
==========================================
+ Hits          4147      4282      +135
- Misses        1779      2008      +229
- Partials         0         0         —

Generated by Codecov Action

@betegon betegon marked this pull request as ready for review January 30, 2026 21:36
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove SeerError class that was accidentally added
- Add proper error handling for curl failures in executeUpgradeCurl
  to prevent false success when curl fails but bash exits 0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@betegon
Copy link
Member Author

betegon commented Jan 30, 2026

Addressed the PR review comments:

Fixed Issues

  1. SeerError class is unused dead code - ✅ Fixed. Removed the unused SeerError class and SeerErrorReason type from errors.ts.

  2. Curl failure causes silent false success in upgrade - ✅ Fixed. Added proper error handling for curl's exit code in executeUpgradeCurl. Now when curl fails, the error is properly detected and reported.

Invalid Issues (verified through testing)

  1. Bun package detection uses invalid command - ❌ Invalid claim. Testing shows bun list -g sentry works correctly and returns installed packages. The output includes sentry@<version> as expected.

  2. Bun upgrade uses wrong install command syntax - ❌ Invalid claim. bun install -g <package>@<version> is valid syntax. The -g, --global flag is documented in bun install --help.

  3. process.execPath check for curl installations - ❌ Invalid claim. This CLI is compiled using Bun.build({ compile: true }), which creates standalone executables. In Bun-compiled binaries, process.execPath correctly points to the binary itself, not to an external runtime. Verified by creating a test compiled binary.

Commit: abb0be4

betegon and others added 2 commits January 30, 2026 23:19
- Normalize user-provided versions by stripping 'v' prefix
- Show correct upgrade command in check-only mode when version specified
- Add versionExists() to validate user-specified versions before upgrade

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move regex to top-level constant (use existing VERSION_PREFIX_REGEX)
- Remove useless else clause in versionExists

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Previously, `issue view 15` would fail with a 404 because numeric-only
inputs like "15" were not recognized as potential short suffixes. The
detection required at least one letter (isShortId check).

Now, any short alphanumeric input (≤4 chars) is first tried as a short
suffix when project context is available. If resolution fails due to
missing context or 404, it falls through to other resolution methods.
Auth errors and server errors are properly propagated.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
betegon and others added 5 commits January 30, 2026 23:48
Adds `sentry upgrade` command to update the CLI to the latest or a specific version.

- Auto-detects installation method (curl, npm, pnpm, bun, yarn)
- Fetches latest version from GitHub releases or npm registry
- Supports --check flag for dry-run mode
- Supports --method flag to override auto-detection
- Includes `update` alias

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove SeerError class that was accidentally added
- Add proper error handling for curl failures in executeUpgradeCurl
  to prevent false success when curl fails but bash exits 0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Normalize user-provided versions by stripping 'v' prefix
- Show correct upgrade command in check-only mode when version specified
- Add versionExists() to validate user-specified versions before upgrade

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move regex to top-level constant (use existing VERSION_PREFIX_REGEX)
- Remove useless else clause in versionExists

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@BYK BYK force-pushed the feat/upgrade-command branch from daed4de to 7129168 Compare January 30, 2026 23:48
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

- src/commands/issue/utils.ts: Accept main's improved shouldFallthrough
  logic that properly handles explicit --org/--project flags (PR #138)
- src/lib/errors.ts: Keep both UpgradeError (upgrade feature) and
  SeerError (from PR #130) as they serve different purposes
…essages

Network failures (DNS, timeout, no internet) now throw UpgradeError
instead of raw TypeError, giving users clean error messages like:
  'Error: Failed to connect to GitHub: fetch failed'
instead of:
  'Unexpected error: TypeError: fetch failed' with stack trace

- Add try-catch around fetch() in fetchLatestFromGitHub()
- Add try-catch around fetch() in fetchLatestFromNpm()
- Add try-catch around fetch() in versionExists()
- Add tests for network failure scenarios
upgrade.ts:
- Add URL constants (GITHUB_RELEASES_URL, NPM_REGISTRY_URL, INSTALL_SCRIPT_URL)
- Add GITHUB_HEADERS constant to avoid repetition
- Add fetchWithUpgradeError() helper to centralize network error handling
- Refactor fetchLatestFromGitHub, fetchLatestFromNpm, versionExists to use helper

oauth.ts:
- Use fetchWithConnectionError consistently in pollForToken (was using raw fetch)
@betegon betegon merged commit 8235308 into main Jan 31, 2026
24 checks passed
@betegon betegon deleted the feat/upgrade-command branch January 31, 2026 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants