Fix error messages (#243)

This commit is contained in:
qwreey 2024-11-08 06:31:06 +00:00
parent 9bca7b80f5
commit 4b2277fec3
No known key found for this signature in database
GPG key ID: D28DB79297A214BD
5 changed files with 9 additions and 14 deletions

View file

@ -20,12 +20,12 @@ fn get_field_table<'lua>(
userdata: &LuaAnyUserData<'lua>,
) -> LuaResult<LuaTable<'lua>> {
let value = association::get(lua, CSTRUCT_INNER, userdata)?
.ok_or_else(|| LuaError::external("Failed to get inner field table. not found"))?;
.ok_or_else(|| LuaError::external("Failed to retrieve inner field table: not found"))?;
if let LuaValue::Table(table) = value {
Ok(table)
} else {
Err(LuaError::external(
"Failed to get inner field table. not a table",
"Failed to retrieve inner field: not a table",
))
}
}

View file

@ -86,7 +86,7 @@ impl BoxData {
if let Some(t) = offset {
if !bounds.check_boundary(t) {
return Err(LuaError::external(format!(
"Offset is out of bounds. box.size: {}. offset got {}",
"Offset out of bounds (box.size: {}, got {})",
target.size(),
t
)));

View file

@ -69,12 +69,12 @@ impl RefData {
pub unsafe fn deref(&self) -> LuaResult<Self> {
if !u8_test(self.flags, RefFlag::Dereferenceable.value()) {
return Err(LuaError::external("This pointer is not dereferenceable."));
return Err(LuaError::external("Reference is not dereferenceable"));
}
if !self.boundary.check_sized(0, size_of::<usize>()) {
return Err(LuaError::external(
"Offset is out of bounds. Dereferencing pointer requires size of usize",
"Offset out of bounds",
));
}
@ -99,7 +99,7 @@ impl RefData {
pub unsafe fn offset(&self, offset: isize) -> LuaResult<Self> {
u8_test(self.flags, RefFlag::Offsetable.value())
.then_some(())
.ok_or_else(|| LuaError::external("This pointer is not offsetable."))?;
.ok_or_else(|| LuaError::external("Reference is not offsetable"))?;
// Check boundary, if exceed, return error
self.boundary
@ -107,7 +107,7 @@ impl RefData {
.then_some(())
.ok_or_else(|| {
LuaError::external(format!(
"Offset is out of bounds. high: {}, low: {}. offset got {}",
"Offset out of bounds (high: {}, low: {}, got {})",
self.boundary.above, self.boundary.below, offset
))
})?;

View file

@ -17,12 +17,7 @@ pub fn get_ensured_size(ffi_type: *mut raw::ffi_type) -> LuaResult<usize> {
)
};
if result != raw::ffi_status_FFI_OK {
return Err(LuaError::external(format!(
"ffi_prep_cif failed. expected result {}, got {}",
FFI_STATUS_NAMES[0], FFI_STATUS_NAMES[result as usize]
)));
}
ffi_status_assert(result)?;
unsafe { Ok((*ffi_type).size) }
}

View file

@ -53,7 +53,7 @@ pub trait FfiConvert {
_offset: isize,
_data_handle: &Ref<dyn FfiData>,
) -> LuaResult<String> {
Err(LuaError::external("stringify not implemented"))
Err(LuaError::external("Stringify method not implemented"))
}
}