@@ -143,6 +143,9 @@ class UTMScriptingVirtualMachineImpl: NSObject {
143
143
@objc func suspend( _ command: NSScriptCommand ) {
144
144
let shouldSaveState = command. evaluatedArguments ? [ " saveFlag " ] as? Bool ?? false
145
145
withScriptCommand ( command) { [ self ] in
146
+ guard vm. state == . vmStarted else {
147
+ throw ScriptingError . notRunning
148
+ }
146
149
try await vm. vmPause ( save: shouldSaveState)
147
150
}
148
151
}
@@ -155,6 +158,9 @@ class UTMScriptingVirtualMachineImpl: NSObject {
155
158
stopMethod = . force
156
159
}
157
160
withScriptCommand ( command) { [ self ] in
161
+ guard vm. state == . vmStarted || stopMethod == . kill else {
162
+ throw ScriptingError . notRunning
163
+ }
158
164
switch stopMethod {
159
165
case . force:
160
166
try await vm. vmStop ( force: false )
@@ -171,11 +177,13 @@ extension UTMScriptingVirtualMachineImpl {
171
177
enum ScriptingError : Error , LocalizedError {
172
178
case operationNotAvailable
173
179
case operationNotSupported
180
+ case notRunning
174
181
175
182
var errorDescription : String ? {
176
183
switch self {
177
184
case . operationNotAvailable: return NSLocalizedString ( " Operation not available. " , comment: " UTMScriptingVirtualMachineImpl " )
178
185
case . operationNotSupported: return NSLocalizedString ( " Operation not supported by the backend. " , comment: " UTMScriptingVirtualMachineImpl " )
186
+ case . notRunning: return NSLocalizedString ( " The virtual machine is not running. " , comment: " UTMScriptingVirtualMachineImpl " )
179
187
}
180
188
}
181
189
}
0 commit comments