Skip to content

Commit

Permalink
Fix error messages (lune-org#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwreey committed Nov 8, 2024
1 parent 9bca7b8 commit 4b2277f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions crates/lune-std-ffi/src/c/struct_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/lune-std-ffi/src/data/box_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)));
Expand Down
8 changes: 4 additions & 4 deletions crates/lune-std-ffi/src/data/ref_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
));
}

Expand All @@ -99,15 +99,15 @@ 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
.check_boundary(offset)
.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
))
})?;
Expand Down
7 changes: 1 addition & 6 deletions crates/lune-std-ffi/src/ffi/libffi_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand Down
2 changes: 1 addition & 1 deletion crates/lune-std-ffi/src/ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}

Expand Down

0 comments on commit 4b2277f

Please sign in to comment.