Browse Source

Improve error messages

tags/v0.3.2-rc2
Philipp Oppermann 2 years ago
parent
commit
e5a037afea
Failed to extract signature
3 changed files with 15 additions and 14 deletions
  1. +11
    -10
      libraries/arrow-convert/src/from_impls.rs
  2. +3
    -3
      libraries/extensions/ros2-bridge/python/src/typed/serialize/array.rs
  3. +1
    -1
      libraries/extensions/ros2-bridge/python/src/typed/serialize/sequence.rs

+ 11
- 10
libraries/arrow-convert/src/from_impls.rs View File

@@ -39,7 +39,7 @@ impl TryFrom<&ArrowData> for u8 {
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::UInt8Type>()
.context("not a primitive array")?;
.context("not a primitive UInt8Type array")?;
extract_single_primitive(array)
}
}
@@ -48,7 +48,7 @@ impl TryFrom<&ArrowData> for u16 {
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::UInt16Type>()
.context("not a primitive array")?;
.context("not a primitive UInt16Type array")?;
extract_single_primitive(array)
}
}
@@ -57,7 +57,7 @@ impl TryFrom<&ArrowData> for u32 {
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::UInt32Type>()
.context("not a primitive array")?;
.context("not a primitive UInt32Type array")?;
extract_single_primitive(array)
}
}
@@ -66,7 +66,7 @@ impl TryFrom<&ArrowData> for u64 {
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::UInt64Type>()
.context("not a primitive array")?;
.context("not a primitive UInt64Type array")?;
extract_single_primitive(array)
}
}
@@ -75,7 +75,7 @@ impl TryFrom<&ArrowData> for i8 {
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::Int8Type>()
.context("not a primitive array")?;
.context("not a primitive Int8Type array")?;
extract_single_primitive(array)
}
}
@@ -84,7 +84,7 @@ impl TryFrom<&ArrowData> for i16 {
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::Int16Type>()
.context("not a primitive array")?;
.context("not a primitive Int16Type array")?;
extract_single_primitive(array)
}
}
@@ -93,7 +93,7 @@ impl TryFrom<&ArrowData> for i32 {
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::Int32Type>()
.context("not a primitive array")?;
.context("not a primitive Int32Type array")?;
extract_single_primitive(array)
}
}
@@ -102,7 +102,7 @@ impl TryFrom<&ArrowData> for i64 {
fn try_from(value: &ArrowData) -> Result<Self, Self::Error> {
let array = value
.as_primitive_opt::<arrow::datatypes::Int64Type>()
.context("not a primitive array")?;
.context("not a primitive Int64Type array")?;
extract_single_primitive(array)
}
}
@@ -127,8 +127,9 @@ impl<'a> TryFrom<&'a ArrowData> for &'a str {
impl<'a> TryFrom<&'a ArrowData> for &'a [u8] {
type Error = eyre::Report;
fn try_from(value: &'a ArrowData) -> Result<Self, Self::Error> {
let array: &PrimitiveArray<arrow::datatypes::UInt8Type> =
value.as_primitive_opt().wrap_err("not a primitive array")?;
let array: &PrimitiveArray<arrow::datatypes::UInt8Type> = value
.as_primitive_opt()
.wrap_err("not a primitive UInt8Type array")?;
if array.null_count() != 0 {
eyre::bail!("array has nulls");
}


+ 3
- 3
libraries/extensions/ros2-bridge/python/src/typed/serialize/array.rs View File

@@ -1,4 +1,4 @@
use std::{borrow::Cow, marker::PhantomData, sync::Arc};
use std::{any::type_name, borrow::Cow, marker::PhantomData, sync::Arc};

use arrow::{
array::{Array, ArrayRef, AsArray, OffsetSizeTrait, PrimitiveArray},
@@ -35,7 +35,7 @@ impl serde::Serialize for ArraySerializeWrapper<'_> {
let list = self
.column
.as_list_opt::<i64>()
.ok_or_else(|| error("value is not compatible with expected Array type"))?;
.ok_or_else(|| error("value is not compatible with expected array type"))?;
// should match the length of the outer struct
assert_eq!(list.len(), 1);
list.value(0)
@@ -194,7 +194,7 @@ where
let array: &PrimitiveArray<T> = self
.value
.as_primitive_opt()
.ok_or_else(|| error("not a primitive array"))?;
.ok_or_else(|| error(format!("not a primitive {} array", type_name::<T>())))?;
if array.len() != self.len {
return Err(error(format!(
"expected array with length {}, got length {}",


+ 1
- 1
libraries/extensions/ros2-bridge/python/src/typed/serialize/sequence.rs View File

@@ -186,7 +186,7 @@ where
let array: &PrimitiveArray<T> = self
.value
.as_primitive_opt()
.ok_or_else(|| error("not a primitive array"))?;
.ok_or_else(|| error(format!("not a primitive {} array", type_name::<T>())))?;

let mut seq = serializer.serialize_seq(Some(array.len()))?;



Loading…
Cancel
Save