@@ -144,42 +144,48 @@ func Validate(y *LimaYAML, warn bool) error {
144
144
}
145
145
}
146
146
147
+ var mountErrs []error
147
148
for i , f := range y .Mounts {
148
149
if ! filepath .IsAbs (f .Location ) && ! strings .HasPrefix (f .Location , "~" ) {
149
- return fmt .Errorf ("field `mounts[%d].location` must be an absolute path, got %q" ,
150
- i , f .Location )
150
+ mountErrs = append (mountErrs , fmt .Errorf ("field `mounts[%d].location` must be an absolute path, got %q" , i , f .Location ))
151
151
}
152
152
// f.Location has already been expanded in FillDefaults(), but that function cannot return errors.
153
153
loc , err := localpathutil .Expand (f .Location )
154
154
if err != nil {
155
- return fmt .Errorf ("field `mounts[%d].location` refers to an unexpandable path: %q: %w" , i , f .Location , err )
155
+ mountErrs = append ( mountErrs , fmt .Errorf ("field `mounts[%d].location` refers to an unexpandable path: %q: %w" , i , f .Location , err ) )
156
156
}
157
157
st , err := os .Stat (loc )
158
158
if err != nil {
159
- if ! errors .Is (err , os .ErrNotExist ) {
160
- return fmt .Errorf ("field `mounts[%d].location` refers to an inaccessible path: %q: %w" , i , f .Location , err )
159
+ if errors .Is (err , os .ErrNotExist ) {
160
+ mountErrs = append (mountErrs , fmt .Errorf ("field `mounts[%d].location` refers to non-existent path: %q: %w" , i , f .Location , err ))
161
+ continue
161
162
}
163
+ mountErrs = append (mountErrs , fmt .Errorf ("field `mounts[%d].location` refers to an inaccessible path: %q: %w" , i , f .Location , err ))
162
164
} else if ! st .IsDir () {
163
- return fmt .Errorf ("field `mounts[%d].location` refers to a non-directory path: %q: %w" , i , f .Location , err )
165
+ mountErrs = append ( mountErrs , fmt .Errorf ("field `mounts[%d].location` refers to a non-directory path: %q: %w" , i , f .Location , err ) )
164
166
}
165
167
166
168
switch * f .MountPoint {
167
169
case "/" , "/bin" , "/dev" , "/etc" , "/home" , "/opt" , "/sbin" , "/tmp" , "/usr" , "/var" :
168
- return fmt .Errorf ("field `mounts[%d].mountPoint` must not be a system path such as /etc or /usr" , i )
170
+ mountErrs = append ( mountErrs , fmt .Errorf ("field `mounts[%d].mountPoint` must not be a system path such as /etc or /usr" , i ) )
169
171
// home directory defined in "cidata.iso:/user-data"
170
172
case * y .User .Home :
171
- return fmt .Errorf ("field `mounts[%d].mountPoint` is the reserved internal home directory %q" , i , * y .User .Home )
173
+ mountErrs = append ( mountErrs , fmt .Errorf ("field `mounts[%d].mountPoint` is the reserved internal home directory %q" , i , * y .User .Home ) )
172
174
}
173
175
// There is no tilde-expansion for guest filenames
174
176
if strings .HasPrefix (* f .MountPoint , "~" ) {
175
- return fmt .Errorf ("field `mounts[%d].mountPoint` must not start with \" ~\" " , i )
177
+ mountErrs = append ( mountErrs , fmt .Errorf ("field `mounts[%d].mountPoint` must not start with \" ~\" " , i ) )
176
178
}
177
179
178
180
if _ , err := units .RAMInBytes (* f .NineP .Msize ); err != nil {
179
- return fmt .Errorf ("field `msize` has an invalid value: %w" , err )
181
+ mountErrs = append ( mountErrs , fmt .Errorf ("field `msize` has an invalid value: %w" , err ) )
180
182
}
181
183
}
182
184
185
+ if len (mountErrs ) > 0 {
186
+ return fmt .Errorf ("mounts validation failed:\n %w" , errors .Join (mountErrs ... ))
187
+ }
188
+
183
189
if * y .SSH .LocalPort != 0 {
184
190
if err := validatePort ("ssh.localPort" , * y .SSH .LocalPort ); err != nil {
185
191
return err
0 commit comments