Skip to content

Commit bc865df

Browse files
authored
fixes panic when api returns nil (#50)
`kernel browsers list` panics when there are no browsers to list! Fixed and added a unit test for it 😄 I also didn't like that prod release is 4 commands so I vibed a script to do it **Previously** ``` panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1025be884] goroutine 1 [running]: github.com/onkernel/cli/cmd.BrowsersCmd.List({{0x1029b10c8, 0x140000d2300}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, ...}, ...) /Users/tanmaysardesai/github.com/onkernel/cli/cmd/browsers.go:222 +0x164 github.com/onkernel/cli/cmd.runBrowsersList(0x102e4a560, {0x10263262a?, 0x4?, 0x102632536?}) /Users/tanmaysardesai/github.com/onkernel/cli/cmd/browsers.go:2128 +0x2ec github.com/spf13/cobra.(*Command).execute(0x102e4a560, {0x102e80cc0, 0x0, 0x0}) /Users/tanmaysardesai/go/pkg/mod/github.com/spf13/[email protected]/command.go:1015 +0x7d4 github.com/spf13/cobra.(*Command).ExecuteC(0x102e4ece0) /Users/tanmaysardesai/go/pkg/mod/github.com/spf13/[email protected]/command.go:1148 +0x350 github.com/spf13/cobra.(*Command).Execute(...) /Users/tanmaysardesai/go/pkg/mod/github.com/spf13/[email protected]/command.go:1071 github.com/spf13/cobra.(*Command).ExecuteContext(...) /Users/tanmaysardesai/go/pkg/mod/github.com/spf13/[email protected]/command.go:1064 github.com/charmbracelet/fang.Execute({0x1029ae0f8, 0x102e80cc0}, 0x102e4ece0, {0x14000223e98, 0x2, 0x2?}) /Users/tanmaysardesai/go/pkg/mod/github.com/charmbracelet/[email protected]/fang.go:151 +0x320 github.com/onkernel/cli/cmd.Execute({{0x10285b4f8, 0x6}, {0x10285bce0, 0x28}, {0x10285bb50, 0x14}, {0x10285ba98, 0x8}}) /Users/tanmaysardesai/github.com/onkernel/cli/cmd/root.go:164 +0x2e8 main.main() /Users/tanmaysardesai/github.com/onkernel/cli/cmd/kernel/main.go:17 +0x78 ``` **now** ``` INFO No running browsers found ``` <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Prevents a panic in `kernel browsers list` when the API returns no page, adds a unit test, and introduces a `scripts/release.sh` with updated release docs. > > - **CLI (browsers list)** > - Safely handle `nil` page from SDK in `cmd/browsers.go` and treat as empty results. > - JSON output now prints `[]` when no items (`len(browsers)==0`). > - Shows "No running browsers found" when empty instead of panicking. > - **Tests** > - Add `TestBrowsersList_PrintsEmptyMessagePageIsNil` in `cmd/browsers_test.go`. > - **Release** > - Add `scripts/release.sh` to tag, push, and run `make release` with basic version validation. > - Update `DEVELOPMENT.md` to use `git describe --abbrev=0` and `./scripts/release.sh <version> [description]` for releases. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit fe327db. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 1b043a5 commit bc865df

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

DEVELOPMENT.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ You should see one error about there not being a git tag, and that's fine.
7878
To actually release, run:
7979

8080
```bash
81-
# use `git tag -l | grep cli` to find the latest version and what you want to bump it to
82-
export VERSION=0.1.1
83-
git tag -a v$VERSION -m "Bugfixes"
84-
git push origin v$VERSION
85-
make release
81+
# use `git describe --abbrev=0` to find the latest version and then bump it following https://semver.org/
82+
./scripts/release.sh <version> [description]
8683
```

cmd/browsers.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,13 @@ func (b BrowsersCmd) List(ctx context.Context, in BrowsersListInput) error {
219219
return util.CleanedUpSdkError{Err: err}
220220
}
221221

222-
browsers := page.Items
222+
var browsers []kernel.BrowserListResponse
223+
if page != nil {
224+
browsers = page.Items
225+
}
223226

224227
if in.Output == "json" {
225-
if browsers == nil {
228+
if len(browsers) == 0 {
226229
fmt.Println("[]")
227230
return nil
228231
}

cmd/browsers_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ func TestBrowsersList_PrintsEmptyMessage(t *testing.T) {
120120
assert.Contains(t, out, "No running browsers found")
121121
}
122122

123+
func TestBrowsersList_PrintsEmptyMessagePageIsNil(t *testing.T) {
124+
setupStdoutCapture(t)
125+
126+
fake := &FakeBrowsersService{
127+
ListFunc: func(ctx context.Context, query kernel.BrowserListParams, opts ...option.RequestOption) (*pagination.OffsetPagination[kernel.BrowserListResponse], error) {
128+
return nil, nil
129+
},
130+
}
131+
b := BrowsersCmd{browsers: fake}
132+
_ = b.List(context.Background(), BrowsersListInput{})
133+
134+
out := outBuf.String()
135+
assert.Contains(t, out, "No running browsers found")
136+
}
137+
123138
func TestBrowsersList_PrintsTableWithRows(t *testing.T) {
124139
setupStdoutCapture(t)
125140

scripts/release.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [ -z "$1" ]; then
6+
echo "Error: VERSION is required"
7+
echo "Usage: $0 <VERSION> [DESCRIPTION]"
8+
exit 1
9+
fi
10+
11+
VERSION=$1
12+
if [[ ! "$VERSION" =~ ^[0-9.]+$ ]]; then
13+
echo "Error: VERSION must contain only numbers and periods"
14+
echo "Usage: $0 <VERSION> [DESCRIPTION]"
15+
exit 1
16+
fi
17+
DESCRIPTION=${2:-"Version $VERSION"}
18+
19+
git tag -a v$VERSION -m "$DESCRIPTION"
20+
git push origin v$VERSION
21+
make release

0 commit comments

Comments
 (0)