mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
doctor read no VM's state, so a vm.json that devvm can't read, or one with a section its package can't read, showed only when a command on that VM failed. doctor now reads every VM's state (ReadStates) and runs the check every command makes of the VM it finds for a folder on it (checkState, every section's reader), and warns of each VM it can't read, naming it, or its folder when the file can't be read, and why, which names the file (vm_state_broken). It only reads, and --json lists the warnings with the rest. The task also named "the files vm.json names that devvm reads at launch". None in a VM's folder stops a launch from older state: its own policy file is read by the proxy, which keeps its last rules, and doctor already checks its lines; home.tar.gz is read only while a remake hasn't finished; run/ is written again at each start. So only vm.json and its sections are checked. A value that reads but that a launch refuses, such as a size that isn't a number, isn't checked, and the docs say so. Tests: doctor.txtar (a vm.json that isn't JSON, a section that doesn't read, and one that's fine), fixture_v010.txtar (every 0.1.0 VM reads, and no file changes), fixture_v010_housekeeping.txtar. Co-Authored-By: Claude Opus 5.5 <[email protected]>
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package vm
|
|
|
|
import (
|
|
"github.com/devvmhq/devvm/internal/msg"
|
|
"github.com/devvmhq/devvm/internal/paths"
|
|
)
|
|
|
|
// StateProblems are devvm doctor's warnings for the VMs whose state devvm can't read: one for
|
|
// each VM whose vm.json can't be read, or has a section that its package can't read, as every
|
|
// command checks it as it finds the folder's VM (checkState), naming the VM and why, which names
|
|
// the file. A value that reads but that a launch refuses, such as a size, isn't checked. It only
|
|
// reads. A VM whose folder has no state, or anything else in the VMs' folder, is
|
|
// state.VMFolderProblems'.
|
|
func StateProblems(d paths.Dirs) []msg.M {
|
|
inv, err := ReadStates(d)
|
|
if err != nil {
|
|
return nil // the VMs' folder itself, which state.VMFolderProblems warns of
|
|
}
|
|
var ms []msg.M
|
|
for _, k := range inv.VMs {
|
|
name := k.Hash
|
|
if k.Name != "" {
|
|
name = k.Name.String()
|
|
}
|
|
err := k.Err
|
|
if err == nil {
|
|
err = checkState(k.State)
|
|
}
|
|
if err != nil {
|
|
ms = append(ms, msg.VMStateBroken(name, err.Error()).Because(err))
|
|
}
|
|
}
|
|
return ms
|
|
}
|