Skip to content

Commit 99763bb

Browse files
committed
Clean up of ReplayError messages
1 parent ffe22ff commit 99763bb

File tree

3 files changed

+52
-41
lines changed

3 files changed

+52
-41
lines changed

crates/wasmtime/src/runtime/component/func/options.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,9 @@ impl<'a, T: 'static> LowerContext<'a, T> {
635635
RREvent::ComponentLowerFlatReturn(e) => {
636636
#[cfg(feature = "rr-validate")]
637637
if run_validate {
638-
_lower_stack.pop().ok_or(ReplayError::InvalidOrdering)?;
638+
_lower_stack
639+
.pop()
640+
.ok_or(ReplayError::InvalidEventPosition)?;
639641
}
640642
lowering_error = e.0.ret().map_err(Into::into).err();
641643
}
@@ -644,7 +646,7 @@ impl<'a, T: 'static> LowerContext<'a, T> {
644646
if run_validate {
645647
_lower_store_stack
646648
.pop()
647-
.ok_or(ReplayError::InvalidOrdering)?;
649+
.ok_or(ReplayError::InvalidEventPosition)?;
648650
}
649651
lowering_error = e.0.ret().map_err(Into::into).err();
650652
}

crates/wasmtime/src/runtime/rr/core.rs

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::prelude::*;
33
use core::fmt;
44
use events::EventError;
55
use serde::{Deserialize, Serialize};
6+
use wasmtime_environ::EntityIndex;
67
// Use component events internally even without feature flags enabled
78
// so that [`RREvent`] has a well-defined serialization format, but export
89
// it for other modules only when enabled
@@ -198,12 +199,14 @@ pub enum ReplayError {
198199
EmptyBuffer,
199200
FailedValidation,
200201
IncorrectEventVariant,
201-
InvalidOrdering,
202+
InvalidEventPosition,
202203
FailedRead(IOError),
203204
EventError(Box<dyn EventError>),
204-
MissingComponentOrModule,
205-
MissingComponentOrModuleInstance,
206-
IncorrectCoreFuncIndex,
205+
MissingComponent([u8; 32]),
206+
MissingModule([u8; 32]),
207+
MissingComponentInstance(u32),
208+
MissingModuleInstance(u32),
209+
InvalidCoreFuncIndex(EntityIndex),
207210
}
208211

209212
impl fmt::Display for ReplayError {
@@ -213,10 +216,13 @@ impl fmt::Display for ReplayError {
213216
write!(f, "replay buffer is empty")
214217
}
215218
Self::FailedValidation => {
216-
write!(f, "replay event validation failed")
219+
write!(
220+
f,
221+
"failed validation check during replay; see wasmtime log for error"
222+
)
217223
}
218224
Self::IncorrectEventVariant => {
219-
write!(f, "event method invoked on incorrect variant")
225+
write!(f, "event type mismatch during replay")
220226
}
221227
Self::EventError(e) => {
222228
write!(f, "{:?}", e)
@@ -225,17 +231,37 @@ impl fmt::Display for ReplayError {
225231
write!(f, "{}", e)?;
226232
f.write_str("Note: Ensure sufficient `deserialization-buffer-size` in replay settings if you included `validation-metadata` during recording")
227233
}
228-
Self::InvalidOrdering => {
234+
Self::InvalidEventPosition => {
229235
write!(f, "event occured at an invalid position in the trace")
230236
}
231-
Self::MissingComponentOrModule => {
232-
write!(f, "missing component or module for replay")
237+
Self::MissingComponent(checksum) => {
238+
write!(
239+
f,
240+
"missing component binary with checksum 0x{} during replay",
241+
checksum
242+
.iter()
243+
.map(|b| format!("{:02x}", b))
244+
.collect::<String>()
245+
)
233246
}
234-
Self::MissingComponentOrModuleInstance => {
235-
write!(f, "missing component or module instance for replay")
247+
Self::MissingModule(checksum) => {
248+
write!(
249+
f,
250+
"missing module binary with checksum {:02x?} during replay",
251+
checksum
252+
.iter()
253+
.map(|b| format!("{:02x}", b))
254+
.collect::<String>()
255+
)
236256
}
237-
Self::IncorrectCoreFuncIndex => {
238-
write!(f, "incorrect core function index encountered during replay")
257+
Self::MissingComponentInstance(id) => {
258+
write!(f, "missing component instance ID {:?} during replay", id)
259+
}
260+
Self::MissingModuleInstance(id) => {
261+
write!(f, "missing module instance ID {:?} during replay", id)
262+
}
263+
Self::InvalidCoreFuncIndex(index) => {
264+
write!(f, "replay core func ({:?}) during replay is invalid", index)
239265
}
240266
}
241267
}
@@ -306,9 +332,6 @@ pub trait Replayer: Iterator<Item = Result<RREvent, ReplayError>> {
306332
/// Get the settings (embedded within the trace) during recording
307333
fn trace_settings(&self) -> &RecordSettings;
308334

309-
///// Peek at the next event without consuming it
310-
//fn peek(&mut self) -> Option<Result<&RREvent, ReplayError>>;
311-
312335
// Provided Methods
313336

314337
/// Get the next functional replay event (skips past all non-marker events)
@@ -458,8 +481,6 @@ pub struct ReplayBuffer {
458481
deser_buffer: Vec<u8>,
459482
/// Whether buffer has been completely read
460483
eof_encountered: bool,
461-
/// Peeked event for lookahead
462-
peeked: Option<RREvent>,
463484
}
464485

465486
impl Iterator for ReplayBuffer {
@@ -469,9 +490,6 @@ impl Iterator for ReplayBuffer {
469490
if self.eof_encountered {
470491
return None;
471492
}
472-
if self.peeked.is_some() {
473-
return self.peeked.take().map(Ok);
474-
}
475493
let ret = 'event_loop: loop {
476494
let result = io::from_replay_reader(&mut self.reader, &mut self.deser_buffer);
477495
match result {
@@ -499,17 +517,17 @@ impl Drop for ReplayBuffer {
499517
let mut remaining_events = 0;
500518
log::info!("Replay buffer is being dropped; checking for remaining replay events...");
501519
// Cannot use count() in iterator because IO error may loop indefinitely
502-
while let Some(event) = self.next() {
503-
event.unwrap();
520+
while let Some(e) = self.next() {
521+
e.unwrap();
504522
remaining_events += 1;
505523
}
506524
if remaining_events > 0 {
507525
log::warn!(
508-
"{} events were remaining in the replay buffer. This is likely the result of an erroneous/incomplete execution",
526+
"{} events were not used in the replay buffer. This is likely the result of an erroneous/incomplete execution",
509527
remaining_events
510528
);
511529
} else {
512-
log::info!("All replay events were successfully processed.");
530+
log::debug!("All replay events were successfully processed.");
513531
}
514532
}
515533
}
@@ -546,7 +564,6 @@ impl Replayer for ReplayBuffer {
546564
trace_settings,
547565
deser_buffer,
548566
eof_encountered: false,
549-
peeked: None,
550567
})
551568
}
552569

@@ -559,14 +576,6 @@ impl Replayer for ReplayBuffer {
559576
fn trace_settings(&self) -> &RecordSettings {
560577
&self.trace_settings
561578
}
562-
563-
//#[inline]
564-
//fn peek(&mut self) -> Option<Result<&RREvent, ReplayError>> {
565-
// if self.peeked.is_none() {
566-
// self.peeked = self.next();
567-
// }
568-
// self.peeked.as_ref().map(|r| Ok(r))
569-
//}
570579
}
571580

572581
#[cfg(test)]

crates/wasmtime/src/runtime/rr/replay_driver.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<'a> ReplayInstance<'a> {
120120
let component = self
121121
.components
122122
.get(&event.0)
123-
.ok_or(ReplayError::MissingComponentOrModule)?;
123+
.ok_or(ReplayError::MissingComponent(event.0))?;
124124

125125
let instance = self
126126
.component_linker
@@ -151,7 +151,7 @@ impl<'a> ReplayInstance<'a> {
151151
let instance = self
152152
.component_instances
153153
.get_mut(&key)
154-
.ok_or(ReplayError::MissingComponentOrModuleInstance)?;
154+
.ok_or(ReplayError::MissingComponentInstance(key.1.as_u32()))?;
155155

156156
// Replay lowering steps and obtain raw value arguments to raw function call
157157
let func = component::Func::from_lifted_func(*instance, event.func_idx);
@@ -202,7 +202,7 @@ impl<'a> ReplayInstance<'a> {
202202
let module = self
203203
.modules
204204
.get(&event.0)
205-
.ok_or(ReplayError::MissingComponentOrModule)?;
205+
.ok_or(ReplayError::MissingModule(event.0))?;
206206

207207
let instance = self
208208
.module_linker
@@ -224,14 +224,14 @@ impl<'a> ReplayInstance<'a> {
224224
let instance = self
225225
.module_instances
226226
.get_mut(&key)
227-
.ok_or(ReplayError::MissingComponentOrModule)?;
227+
.ok_or(ReplayError::MissingModuleInstance(key.1.as_u32()))?;
228228

229229
let entity = EntityIndex::from(event.origin.index);
230230
let mut store = self.store.as_context_mut();
231231
let func = instance
232232
._get_export(store.0, entity)
233233
.into_func()
234-
.ok_or(ReplayError::IncorrectCoreFuncIndex)?;
234+
.ok_or(ReplayError::InvalidCoreFuncIndex(entity))?;
235235

236236
let params_ty = func.ty(&store).params().collect::<Vec<ValType>>();
237237

0 commit comments

Comments
 (0)