Skip to content

Commit

Permalink
TyUser::new to return Starlark::Error
Browse files Browse the repository at this point in the history
Summary: Change TyUser::new function to return `starlark::Error` instead of `anyhow::Error`. I categorized the errors as `Native` which I'm not confident on if that's correct, but it's getting categorized to that by default if it ever gets converted to a `starlark::Error` anyways so it's behavior preserving.

Reviewed By: JakobDegen

Differential Revision: D67865719

fbshipit-source-id: 362b161307c8d581261f7d1dfdaf53f2d03f3da0
  • Loading branch information
Will-MingLun-Li authored and facebook-github-bot committed Jan 9, 2025
1 parent 50c5da7 commit 247dcb9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions starlark/src/typing/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl TyUser {
base: TyStarlarkValue,
id: TypeInstanceId,
params: TyUserParams,
) -> anyhow::Result<TyUser> {
) -> crate::Result<TyUser> {
let TyUserParams {
supertypes,
matcher,
Expand All @@ -153,13 +153,19 @@ impl TyUser {
_non_exhaustive: (),
} = params;
if callable.is_some() && !base.is_callable() {
return Err(TyUserError::CallableNotCallable(name).into());
return Err(crate::Error::new_native(TyUserError::CallableNotCallable(
name,
)));
}
if index.is_some() && !base.is_indexable() {
return Err(TyUserError::IndexableNotIndexable(name).into());
return Err(crate::Error::new_native(
TyUserError::IndexableNotIndexable(name),
));
}
if iter_item.is_some() && base.iter_item().is_err() {
return Err(TyUserError::IterableNotIterable(name).into());
return Err(crate::Error::new_native(TyUserError::IterableNotIterable(
name,
)));
}
Ok(TyUser {
name,
Expand Down Expand Up @@ -403,7 +409,7 @@ mod tests {

#[starlark_module]
fn globals(globals: &mut GlobalsBuilder) {
fn fruit(name: String) -> anyhow::Result<FruitCallable> {
fn fruit(name: String) -> starlark::Result<FruitCallable> {
let ty_fruit = Ty::custom(TyUser::new(
name.clone(),
TyStarlarkValue::new::<Fruit>(),
Expand Down

0 comments on commit 247dcb9

Please sign in to comment.