Skip to content

Commit 5eda0c8

Browse files
adambratschikayeberestovskyy
authored andcommitted
chore(RUN): Remove unused HypervisorErrors
1 parent e7ce6f4 commit 5eda0c8

File tree

4 files changed

+81
-111
lines changed

4 files changed

+81
-111
lines changed

rs/interfaces/src/execution_environment/errors.rs

Lines changed: 74 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use ic_base_types::{CanisterIdError, NumBytes, PrincipalIdBlobParseError};
1+
use ic_base_types::{NumBytes, PrincipalIdBlobParseError};
22
use ic_error_types::UserError;
33
use ic_types::{methods::WasmMethod, CanisterId, CountBytes, Cycles, NumInstructions};
44
use ic_wasm_types::{WasmEngineError, WasmInstrumentationError, WasmValidationError};
@@ -98,19 +98,8 @@ pub enum HypervisorError {
9898
/// An attempt was made to grow the canister's memory above its memory
9999
/// allocation.
100100
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-
},
110101
/// The principal ID specified by the canister is invalid.
111102
InvalidPrincipalId(PrincipalIdBlobParseError),
112-
/// The canister ID specified by the canister is invalid.
113-
InvalidCanisterId(CanisterIdError),
114103
/// The canister rejected the message.
115104
MessageRejected,
116105
/// An attempt was made to add more cycles to an outgoing call than
@@ -235,7 +224,10 @@ impl HypervisorError {
235224
),
236225
Self::InstructionLimitExceeded => UserError::new(
237226
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+
),
239231
),
240232
Self::InvalidWasm(err) => UserError::new(
241233
E::CanisterInvalidWasm,
@@ -268,37 +260,15 @@ impl HypervisorError {
268260
),
269261
Self::WasmReservedPages => UserError::new(
270262
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),
289264
),
290265
Self::InvalidPrincipalId(_) => UserError::new(
291266
E::CanisterTrapped,
292267
format!("Canister {} provided invalid principal id", canister_id),
293268
),
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+
}
302272
Self::Cleanup {
303273
callback_err,
304274
cleanup_err,
@@ -308,67 +278,97 @@ impl HypervisorError {
308278

309279
UserError::new(
310280
callback_user_error.code(), // Use the same error code as the original callback error.
311-
format!("{}\n\ncall_on_cleanup also failed:\n\n{}",
281+
format!(
282+
"{}\n\ncall_on_cleanup also failed:\n\n{}",
312283
callback_user_error.description(),
313284
cleanup_user_error.description()
314-
)
285+
),
315286
)
316287
}
317288
Self::WasmEngineError(err) => UserError::new(
318289
E::CanisterWasmEngineError,
319290
format!(
320-
"Canister {} encountered a Wasm engine error: {}", canister_id, err
291+
"Canister {} encountered a Wasm engine error: {}",
292+
canister_id, err
321293
),
322294
),
323295
Self::Aborted => {
324296
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(
327302
E::CanisterInstructionLimitExceeded,
328-
format!("Canister {} attempted to perform \
303+
format!(
304+
"Canister {} attempted to perform \
329305
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+
),
331309
),
332310
Self::MemoryAccessLimitExceeded(s) => UserError::new(
333311
E::CanisterMemoryAccessLimitExceeded,
334-
format!("Canister exceeded memory access limits: {}", s)
335-
312+
format!("Canister exceeded memory access limits: {}", s),
336313
),
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+
),
348334
)
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,
353343
format!(
354344
"Canister cannot grow memory by {} bytes due to its reserved cycles limit. \
355345
The current limit ({}) would be exceeded by {}.",
356346
bytes, limit, requested - limit,
357347
),
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!(
368367
"Canister cannot grow message memory by {} bytes due to insufficient cycles.{}",
369368
bytes, msg,
369+
),
370370
)
371-
)},
371+
}
372372
}
373373
}
374374

@@ -386,10 +386,7 @@ impl HypervisorError {
386386
HypervisorError::CalledTrap(_) => "CalledTrap",
387387
HypervisorError::WasmModuleNotFound => "WasmModuleNotFound",
388388
HypervisorError::OutOfMemory => "OutOfMemory",
389-
HypervisorError::CanisterStopped => "CanisterStopped",
390-
HypervisorError::InsufficientCyclesInCall { .. } => "InsufficientCyclesInCall",
391389
HypervisorError::InvalidPrincipalId(_) => "InvalidPrincipalId",
392-
HypervisorError::InvalidCanisterId(_) => "InvalidCanisterId",
393390
HypervisorError::MessageRejected => "MessageRejected",
394391
HypervisorError::InsufficientCyclesBalance { .. } => "InsufficientCyclesBalance",
395392
HypervisorError::Cleanup { .. } => "Cleanup",

rs/replicated_state/src/canister_state/system_state/call_context_manager.rs

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,12 @@ impl CallContext {
8282
/// Updates the available cycles in the `CallContext` based on how much
8383
/// cycles the canister requested to keep.
8484
///
85-
/// Returns a `CallContextError::InsufficientCyclesInCall` if `cycles` is
86-
/// more than what's available in the call context.
87-
pub fn withdraw_cycles(&mut self, cycles: Cycles) -> Result<(), CallContextError> {
85+
/// Returns an error if `cycles` is more than what's available in the call
86+
/// context.
87+
#[allow(clippy::result_unit_err)]
88+
pub fn withdraw_cycles(&mut self, cycles: Cycles) -> Result<(), ()> {
8889
if self.available_cycles < cycles {
89-
return Err(CallContextError::InsufficientCyclesInCall {
90-
available: self.available_cycles,
91-
requested: cycles,
92-
});
90+
return Err(());
9391
}
9492
self.available_cycles -= cycles;
9593
Ok(())
@@ -173,28 +171,6 @@ impl TryFrom<pb::CallContext> for CallContext {
173171
}
174172
}
175173

176-
#[derive(Clone, Debug, PartialEq, Eq)]
177-
pub enum CallContextError {
178-
InsufficientCyclesInCall {
179-
available: Cycles,
180-
requested: Cycles,
181-
},
182-
}
183-
184-
impl From<CallContextError> for HypervisorError {
185-
fn from(val: CallContextError) -> Self {
186-
match val {
187-
CallContextError::InsufficientCyclesInCall {
188-
available,
189-
requested,
190-
} => HypervisorError::InsufficientCyclesInCall {
191-
available,
192-
requested,
193-
},
194-
}
195-
}
196-
}
197-
198174
/// The action the caller of `CallContext.on_canister_result` should take.
199175
#[derive(Clone, Debug, PartialEq, Eq)]
200176
pub enum CallContextAction {

rs/replicated_state/src/canister_state/system_state/call_context_manager/tests.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,7 @@ fn withdraw_cycles_fails_when_not_enough_available_cycles() {
278278
ccm.call_context_mut(cc_id)
279279
.unwrap()
280280
.withdraw_cycles(Cycles::new(40)),
281-
Err(CallContextError::InsufficientCyclesInCall {
282-
available: Cycles::new(30),
283-
requested: Cycles::new(40),
284-
})
281+
Err(())
285282
);
286283
}
287284

rs/system_api/src/sandbox_safe_system_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl SystemStateChanges {
314314
.ok_or_else(|| {
315315
Self::error("Canister accepted cycles from invalid call context")
316316
})?;
317-
call_context.withdraw_cycles(*amount_taken).map_err(|_| {
317+
call_context.withdraw_cycles(*amount_taken).map_err(|()| {
318318
Self::error("Canister accepted more cycles than available from call context")
319319
})?;
320320
if (*amount_taken).get() > LOG_CANISTER_OPERATION_CYCLES_THRESHOLD {

0 commit comments

Comments
 (0)