MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / last_error

Function last_error

wasm-pdk/src/lib.rs:145–161  ·  view source on GitHub ↗

Drain the host's stashed error after a 1-returning `edge_op`; never returns `None`.

()

Source from the content-addressed store, hash-verified

143
144/// Drain the host's stashed error after a 1-returning `edge_op`; never returns `None`.
145pub fn last_error() -> Error {
146 let mut kind: u32 = 2;
147 let mut buf = alloc::vec![0u8; 256];
148 loop {
149 let r = unsafe {
150 edge_take_error(&mut kind as *mut u32, buf.as_mut_ptr(), buf.len() as u32)
151 };
152 if r >= 0 {
153 buf.truncate(r as usize);
154 let msg = String::from_utf8_lossy(&buf).into_owned();
155 return Error::from_kind(kind, msg);
156 }
157 if r == -1 { return Error::Runtime(String::from("native error: no message")); }
158 // Negative = -needed; resize and retry.
159 buf.resize((-r) as usize, 0);
160 }
161}
162
163/* Handle (RAII) */
164

Callers 12

callMethod · 0.85
get_attrMethod · 0.85
get_itemMethod · 0.85
set_itemMethod · 0.85
lenMethod · 0.85
set_attrMethod · 0.85
new_dictMethod · 0.85
new_listMethod · 0.85
new_compositeMethod · 0.85
type_ofMethod · 0.85
iterMethod · 0.85
iter_nextMethod · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected