Skip to content

Commit

Permalink
fix: print debug logs when lima disk command fails
Browse files Browse the repository at this point in the history
Signed-off-by: Hsing-Yu (David) Chen <[email protected]>
  • Loading branch information
davidhsingyuchen committed Mar 7, 2023
1 parent 674b379 commit 82cc0ce
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: %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: %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 82cc0ce

Please sign in to comment.