1
- use ic_base_types:: { CanisterIdError , NumBytes , PrincipalIdBlobParseError } ;
1
+ use ic_base_types:: { NumBytes , PrincipalIdBlobParseError } ;
2
2
use ic_error_types:: UserError ;
3
3
use ic_types:: { methods:: WasmMethod , CanisterId , CountBytes , Cycles , NumInstructions } ;
4
4
use ic_wasm_types:: { WasmEngineError , WasmInstrumentationError , WasmValidationError } ;
@@ -98,19 +98,8 @@ pub enum HypervisorError {
98
98
/// An attempt was made to grow the canister's memory above its memory
99
99
/// allocation.
100
100
OutOfMemory ,
101
- /// An attempt to perform an operation that isn't allowed when the canister
102
- /// is stopped.
103
- CanisterStopped ,
104
- /// An attempt was made to use more cycles than was available in a call
105
- /// context.
106
- InsufficientCyclesInCall {
107
- available : Cycles ,
108
- requested : Cycles ,
109
- } ,
110
101
/// The principal ID specified by the canister is invalid.
111
102
InvalidPrincipalId ( PrincipalIdBlobParseError ) ,
112
- /// The canister ID specified by the canister is invalid.
113
- InvalidCanisterId ( CanisterIdError ) ,
114
103
/// The canister rejected the message.
115
104
MessageRejected ,
116
105
/// An attempt was made to add more cycles to an outgoing call than
@@ -235,7 +224,10 @@ impl HypervisorError {
235
224
) ,
236
225
Self :: InstructionLimitExceeded => UserError :: new (
237
226
E :: CanisterInstructionLimitExceeded ,
238
- format ! ( "Canister {} exceeded the instruction limit for single message execution." , canister_id) ,
227
+ format ! (
228
+ "Canister {} exceeded the instruction limit for single message execution." ,
229
+ canister_id
230
+ ) ,
239
231
) ,
240
232
Self :: InvalidWasm ( err) => UserError :: new (
241
233
E :: CanisterInvalidWasm ,
@@ -268,37 +260,15 @@ impl HypervisorError {
268
260
) ,
269
261
Self :: WasmReservedPages => UserError :: new (
270
262
E :: CanisterOutOfMemory ,
271
- format ! (
272
- "Canister {} ran out of available Wasm memory." ,
273
- canister_id
274
- ) ,
275
- ) ,
276
- Self :: CanisterStopped => UserError :: new (
277
- E :: CanisterStopped ,
278
- format ! ( "Canister {} is stopped" , canister_id, ) ,
279
- ) ,
280
- Self :: InsufficientCyclesInCall {
281
- available,
282
- requested,
283
- } => UserError :: new (
284
- E :: InsufficientCyclesInCall ,
285
- format ! (
286
- "Canister {} attempted to keep {} cycles from a call when only {} was available" ,
287
- canister_id, requested, available
288
- ) ,
263
+ format ! ( "Canister {} ran out of available Wasm memory." , canister_id) ,
289
264
) ,
290
265
Self :: InvalidPrincipalId ( _) => UserError :: new (
291
266
E :: CanisterTrapped ,
292
267
format ! ( "Canister {} provided invalid principal id" , canister_id) ,
293
268
) ,
294
- Self :: InvalidCanisterId ( _) => UserError :: new (
295
- E :: CanisterTrapped ,
296
- format ! ( "Canister {} provided invalid canister id" , canister_id) ,
297
- ) ,
298
- Self :: InsufficientCyclesBalance ( err) => UserError :: new (
299
- E :: CanisterOutOfCycles ,
300
- err. to_string ( ) ,
301
- ) ,
269
+ Self :: InsufficientCyclesBalance ( err) => {
270
+ UserError :: new ( E :: CanisterOutOfCycles , err. to_string ( ) )
271
+ }
302
272
Self :: Cleanup {
303
273
callback_err,
304
274
cleanup_err,
@@ -308,67 +278,97 @@ impl HypervisorError {
308
278
309
279
UserError :: new (
310
280
callback_user_error. code ( ) , // Use the same error code as the original callback error.
311
- format ! ( "{}\n \n call_on_cleanup also failed:\n \n {}" ,
281
+ format ! (
282
+ "{}\n \n call_on_cleanup also failed:\n \n {}" ,
312
283
callback_user_error. description( ) ,
313
284
cleanup_user_error. description( )
314
- )
285
+ ) ,
315
286
)
316
287
}
317
288
Self :: WasmEngineError ( err) => UserError :: new (
318
289
E :: CanisterWasmEngineError ,
319
290
format ! (
320
- "Canister {} encountered a Wasm engine error: {}" , canister_id, err
291
+ "Canister {} encountered a Wasm engine error: {}" ,
292
+ canister_id, err
321
293
) ,
322
294
) ,
323
295
Self :: Aborted => {
324
296
unreachable ! ( "Aborted execution should not be visible to the user." ) ;
325
- } ,
326
- Self :: SliceOverrun { instructions, limit} => UserError :: new (
297
+ }
298
+ Self :: SliceOverrun {
299
+ instructions,
300
+ limit,
301
+ } => UserError :: new (
327
302
E :: CanisterInstructionLimitExceeded ,
328
- format ! ( "Canister {} attempted to perform \
303
+ format ! (
304
+ "Canister {} attempted to perform \
329
305
a large memory operation that used {} instructions and \
330
- exceeded the slice limit {}.", canister_id, instructions, limit) ,
306
+ exceeded the slice limit {}.",
307
+ canister_id, instructions, limit
308
+ ) ,
331
309
) ,
332
310
Self :: MemoryAccessLimitExceeded ( s) => UserError :: new (
333
311
E :: CanisterMemoryAccessLimitExceeded ,
334
- format ! ( "Canister exceeded memory access limits: {}" , s)
335
-
312
+ format ! ( "Canister exceeded memory access limits: {}" , s) ,
336
313
) ,
337
- Self :: InsufficientCyclesInMemoryGrow { bytes, available, threshold, reveal_top_up } => {
338
- let msg = if reveal_top_up {
339
- format ! ( " At least {} additional cycles are required." , threshold - available)
340
- } else {
341
- "" . to_string ( )
342
- } ;
343
- UserError :: new (
344
- E :: InsufficientCyclesInMemoryGrow ,
345
- format ! (
346
- "Canister cannot grow memory by {} bytes due to insufficient cycles.{}" ,
347
- bytes, msg
314
+ Self :: InsufficientCyclesInMemoryGrow {
315
+ bytes,
316
+ available,
317
+ threshold,
318
+ reveal_top_up,
319
+ } => {
320
+ let msg = if reveal_top_up {
321
+ format ! (
322
+ " At least {} additional cycles are required." ,
323
+ threshold - available
324
+ )
325
+ } else {
326
+ "" . to_string ( )
327
+ } ;
328
+ UserError :: new (
329
+ E :: InsufficientCyclesInMemoryGrow ,
330
+ format ! (
331
+ "Canister cannot grow memory by {} bytes due to insufficient cycles.{}" ,
332
+ bytes, msg
333
+ ) ,
348
334
)
349
- )
350
- } ,
351
- Self :: ReservedCyclesLimitExceededInMemoryGrow { bytes, requested, limit } => UserError :: new (
352
- E :: ReservedCyclesLimitExceededInMemoryGrow ,
335
+ }
336
+ Self :: ReservedCyclesLimitExceededInMemoryGrow {
337
+ bytes,
338
+ requested,
339
+ limit,
340
+ } => {
341
+ UserError :: new (
342
+ E :: ReservedCyclesLimitExceededInMemoryGrow ,
353
343
format ! (
354
344
"Canister cannot grow memory by {} bytes due to its reserved cycles limit. \
355
345
The current limit ({}) would be exceeded by {}.",
356
346
bytes, limit, requested - limit,
357
347
) ,
358
- ) ,
359
- Self :: InsufficientCyclesInMessageMemoryGrow { bytes, available, threshold, reveal_top_up } => {
360
- let msg = if reveal_top_up {
361
- format ! ( " At least {} additional cycles are required." , threshold - available)
362
- } else {
363
- "" . to_string ( )
364
- } ;
365
- UserError :: new (
366
- E :: InsufficientCyclesInMessageMemoryGrow ,
367
- format ! (
348
+ )
349
+ }
350
+ Self :: InsufficientCyclesInMessageMemoryGrow {
351
+ bytes,
352
+ available,
353
+ threshold,
354
+ reveal_top_up,
355
+ } => {
356
+ let msg = if reveal_top_up {
357
+ format ! (
358
+ " At least {} additional cycles are required." ,
359
+ threshold - available
360
+ )
361
+ } else {
362
+ "" . to_string ( )
363
+ } ;
364
+ UserError :: new (
365
+ E :: InsufficientCyclesInMessageMemoryGrow ,
366
+ format ! (
368
367
"Canister cannot grow message memory by {} bytes due to insufficient cycles.{}" ,
369
368
bytes, msg,
369
+ ) ,
370
370
)
371
- ) } ,
371
+ }
372
372
}
373
373
}
374
374
@@ -386,10 +386,7 @@ impl HypervisorError {
386
386
HypervisorError :: CalledTrap ( _) => "CalledTrap" ,
387
387
HypervisorError :: WasmModuleNotFound => "WasmModuleNotFound" ,
388
388
HypervisorError :: OutOfMemory => "OutOfMemory" ,
389
- HypervisorError :: CanisterStopped => "CanisterStopped" ,
390
- HypervisorError :: InsufficientCyclesInCall { .. } => "InsufficientCyclesInCall" ,
391
389
HypervisorError :: InvalidPrincipalId ( _) => "InvalidPrincipalId" ,
392
- HypervisorError :: InvalidCanisterId ( _) => "InvalidCanisterId" ,
393
390
HypervisorError :: MessageRejected => "MessageRejected" ,
394
391
HypervisorError :: InsufficientCyclesBalance { .. } => "InsufficientCyclesBalance" ,
395
392
HypervisorError :: Cleanup { .. } => "Cleanup" ,
0 commit comments