Skip to content

Commit 27772e4

Browse files
committed
wsl2: add debug prints
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 01c49be commit 27772e4

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

pkg/store/instance_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func GetWslStatus(instName string) (string, error) {
5151
"--verbose",
5252
})
5353
if err != nil {
54-
return "", fmt.Errorf("failed to run `wsl --list --verbose`, err: %w", err)
54+
return "", fmt.Errorf("failed to run `wsl --list --verbose`, err: %w (out=%q)", err, string(out))
5555
}
5656

5757
if len(out) == 0 {
@@ -94,7 +94,7 @@ func getWslSSHAddress(instName string) (string, error) {
9494
cmd := exec.Command("wsl.exe", "-d", distroName, "bash", "-c", `hostname -I | cut -d ' ' -f1`)
9595
out, err := cmd.CombinedOutput()
9696
if err != nil {
97-
return "", fmt.Errorf("failed to get hostname for instance %s, err: %w", instName, err)
97+
return "", fmt.Errorf("failed to get hostname for instance %s, err: %w (out=%q)", instName, err, string(out))
9898
}
9999

100100
return strings.TrimSpace(string(out)), nil

pkg/wsl2/vm_windows.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ import (
2020

2121
// startVM calls WSL to start a VM.
2222
func startVM(ctx context.Context, distroName string) error {
23-
_, err := executil.RunUTF16leCommand([]string{
23+
out, err := executil.RunUTF16leCommand([]string{
2424
"wsl.exe",
2525
"--distribution",
2626
distroName,
2727
}, executil.WithContext(&ctx))
2828
if err != nil {
29-
return err
29+
return fmt.Errorf("failed to run `wsl.exe --distribution %s`: %w (out=%q)",
30+
distroName, err, string(out))
3031
}
3132
return nil
3233
}
@@ -35,28 +36,30 @@ func startVM(ctx context.Context, distroName string) error {
3536
func initVM(ctx context.Context, instanceDir, distroName string) error {
3637
baseDisk := filepath.Join(instanceDir, filenames.BaseDisk)
3738
logrus.Infof("Importing distro from %q to %q", baseDisk, instanceDir)
38-
_, err := executil.RunUTF16leCommand([]string{
39+
out, err := executil.RunUTF16leCommand([]string{
3940
"wsl.exe",
4041
"--import",
4142
distroName,
4243
instanceDir,
4344
baseDisk,
4445
}, executil.WithContext(&ctx))
4546
if err != nil {
46-
return err
47+
return fmt.Errorf("failed to run `wsl.exe --import %s %s %s`: %w (out=%q)",
48+
distroName, instanceDir, baseDisk, err, string(out))
4749
}
4850
return nil
4951
}
5052

5153
// stopVM calls WSL to stop a running VM.
5254
func stopVM(ctx context.Context, distroName string) error {
53-
_, err := executil.RunUTF16leCommand([]string{
55+
out, err := executil.RunUTF16leCommand([]string{
5456
"wsl.exe",
5557
"--terminate",
5658
distroName,
5759
}, executil.WithContext(&ctx))
5860
if err != nil {
59-
return err
61+
return fmt.Errorf("failed to run `wsl.exe --terminate %s`: %w (out=%q)",
62+
distroName, err, string(out))
6063
}
6164
return nil
6265
}
@@ -86,10 +89,10 @@ func provisionVM(ctx context.Context, instanceDir, instanceName, distroName stri
8689
"-c",
8790
outString,
8891
)
89-
if _, err := cmd.CombinedOutput(); err != nil {
92+
if out, err := cmd.CombinedOutput(); err != nil {
9093
*errCh <- fmt.Errorf(
91-
"error running wslCommand that executes boot.sh: %w, "+
92-
"check /var/log/lima-init.log for more details", err)
94+
"error running wslCommand that executes boot.sh (%v): %w, "+
95+
"check /var/log/lima-init.log for more details (out=%q)", cmd.Args, err, string(out))
9396
}
9497

9598
for {
@@ -130,13 +133,14 @@ func keepAlive(ctx context.Context, distroName string, errCh *chan error) {
130133
// unregisterVM calls WSL to unregister a VM.
131134
func unregisterVM(ctx context.Context, distroName string) error {
132135
logrus.Info("Unregistering WSL2 VM")
133-
_, err := executil.RunUTF16leCommand([]string{
136+
out, err := executil.RunUTF16leCommand([]string{
134137
"wsl.exe",
135138
"--unregister",
136139
distroName,
137140
}, executil.WithContext(&ctx))
138141
if err != nil {
139-
return err
142+
return fmt.Errorf("failed to run `wsl.exe --unregister %s`: %w (out=%q)",
143+
distroName, err, string(out))
140144
}
141145
return nil
142146
}

0 commit comments

Comments
 (0)