Skip to content

Commit 10c6fc2

Browse files
gatesna10y
authored andcommitted
Do not do eager formatting of error strings
Signed-off-by: Nicholas Gates <[email protected]>
1 parent c565fe4 commit 10c6fc2

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

vortex-array/src/arrays/list/array.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::sync::Arc;
55

66
use num_traits::AsPrimitive;
77
use vortex_dtype::{DType, NativePType, match_each_integer_ptype, match_each_native_ptype};
8-
use vortex_error::{VortexExpect, VortexResult, vortex_bail, vortex_ensure};
8+
use vortex_error::{VortexExpect, VortexResult, vortex_bail, vortex_ensure, vortex_err};
99

1010
use crate::arrays::{ListVTable, PrimitiveVTable};
1111
use crate::compute::{min_max, sub_scalar};
@@ -191,13 +191,13 @@ impl ListArray {
191191

192192
vortex_ensure!(
193193
max_offset
194-
<= P::try_from(elements.len()).vortex_expect(&format!(
195-
"Offsets type {} must be able to fit elements length {}",
196-
<P as NativePType>::PTYPE,
197-
elements.len()
198-
)),
199-
"Max offset {max_offset} is beyond the length of the elements array {}",
200-
elements.len()
194+
<= P::try_from(elements.len())
195+
.map_err(|e| vortex_err!(
196+
"Offsets type {} must be able to fit elements length {}",
197+
<P as NativePType>::PTYPE,
198+
elements.len()
199+
))
200+
.vortex_expect("Offsets type must fit elements length")
201201
);
202202
})
203203
} else {

vortex-array/src/patches.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ impl PatchesMetadata {
8585
#[inline]
8686
pub fn chunk_offsets_dtype(&self) -> Option<DType> {
8787
self.chunk_offsets_ptype
88-
.map(|t| PType::try_from(t).vortex_expect(&format!("invalid i32 value {t} for PType")))
88+
.map(|t| {
89+
PType::try_from(t)
90+
.map_err(|e| vortex_err!("invalid i32 value {t} for PType: {}", e))
91+
.vortex_expect("invalid i32 value for PType")
92+
})
8993
.map(|ptype| DType::Primitive(ptype, NonNullable))
9094
}
9195

vortex-session/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::ops::{Deref, DerefMut};
1010
use std::sync::Arc;
1111

1212
use dashmap::{DashMap, Entry};
13-
use vortex_error::{VortexExpect, vortex_panic};
13+
use vortex_error::{VortexExpect, vortex_err, vortex_panic};
1414

1515
/// A Vortex session encapsulates the set of extensible arrays, layouts, compute functions, dtypes,
1616
/// etc. that are available for use in a given context.
@@ -77,10 +77,10 @@ impl SessionExt for VortexSession {
7777
Ref(self
7878
.0
7979
.get(&TypeId::of::<V>())
80-
.vortex_expect(&format!(
81-
"Session has not been initialized with {}",
82-
type_name::<V>()
83-
))
80+
.ok_or_else(|| {
81+
vortex_err!("Session has not been initialized with {}", type_name::<V>())
82+
})
83+
.vortex_expect("Unitialized session variable")?
8484
.map(|v| {
8585
(**v)
8686
.as_any()
@@ -96,10 +96,10 @@ impl SessionExt for VortexSession {
9696
RefMut(
9797
self.0
9898
.get_mut(&TypeId::of::<V>())
99-
.vortex_expect(&format!(
100-
"Session has not been initialized with {}",
101-
type_name::<V>()
102-
))
99+
.ok_or_else(|| {
100+
vortex_err!("Session has not been initialized with {}", type_name::<V>())
101+
})
102+
.vortex_expect("Unitialized session variable")?
103103
.map(|v| {
104104
(**v)
105105
.as_any_mut()

0 commit comments

Comments
 (0)