Skip to content

Commit

Permalink
fix: print debug logs when lima disk command fails (runfinch#270)
Browse files Browse the repository at this point in the history
## Before

```sh
➜  finch git:(main) ✗ ./_output/bin/finch vm init
FATA[0000] exit status 1
```

## After

```sh
➜  finch git:(disk-combined-output) ✗ ./_output/bin/finch vm init
FATA[0000] failed to create disk, debug logs:
time="2023-03-07T13:35:02-08:00" level=fatal msg="disk \"finch\" already exists (\"/Users/davidhyc/dev/runfinch/finch/_output/lima/data/_disks/finch\")"
```

## Notes

The concept behind this PR is from:
https://github.com/runfinch/finch/blob/674b3794fe5f5902c264d5327024fb92e147e60f/cmd/finch/virtual_machine_init.go#L97-L101

## License Acceptance

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

Signed-off-by: Hsing-Yu (David) Chen <[email protected]>
  • Loading branch information
davidhsingyuchen authored Mar 7, 2023
1 parent 674b379 commit 78a3f50
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions pkg/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ func (m *userDataDiskManager) limaDiskExists() bool {

func (m *userDataDiskManager) createLimaDisk() error {
cmd := m.lcc.CreateWithoutStdio("disk", "create", diskName, "--size", diskSize)
return cmd.Run()
if logs, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to create disk, debug logs:\n%s", logs)
}
return nil
}

func (m *userDataDiskManager) attachPersistentDiskToLimaDisk() error {
Expand Down Expand Up @@ -165,5 +168,8 @@ func (m *userDataDiskManager) limaDiskIsLocked() bool {

func (m *userDataDiskManager) unlockLimaDisk() error {
cmd := m.lcc.CreateWithoutStdio("disk", "unlock", diskName)
return cmd.Run()
if logs, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to unlock disk, debug logs:\n%s", logs)
}
return nil
}
6 changes: 3 additions & 3 deletions pkg/disk/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestUserDataDiskManager_InitializeUserDataDisk(t *testing.T) {
cmd.EXPECT().Output().Return([]byte(""), nil)

lcc.EXPECT().CreateWithoutStdio(mockCreateArgs).Return(cmd)
cmd.EXPECT().Run().Return(nil)
cmd.EXPECT().CombinedOutput().Return(nil, nil)

dfs.EXPECT().Stat(finch.UserDataDiskPath(homeDir)).Return(nil, fs.ErrNotExist)
dfs.EXPECT().Stat(path.Dir(finch.UserDataDiskPath(homeDir))).Return(nil, nil)
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestUserDataDiskManager_InitializeUserDataDisk(t *testing.T) {
cmd.EXPECT().Output().Return([]byte(""), nil)

lcc.EXPECT().CreateWithoutStdio(mockCreateArgs).Return(cmd)
cmd.EXPECT().Run().Return(nil)
cmd.EXPECT().CombinedOutput().Return(nil, nil)

dfs.EXPECT().Stat(finch.UserDataDiskPath(homeDir)).Return(nil, nil)

Expand All @@ -130,7 +130,7 @@ func TestUserDataDiskManager_InitializeUserDataDisk(t *testing.T) {

dfs.EXPECT().Stat(lockPath).Return(nil, nil)
lcc.EXPECT().CreateWithoutStdio(mockUnlockArgs).Return(cmd)
cmd.EXPECT().Run().Return(nil)
cmd.EXPECT().CombinedOutput().Return(nil, nil)
},
},
}
Expand Down

0 comments on commit 78a3f50

Please sign in to comment.