diff --git a/crates/torii/client/src/client/error.rs b/crates/torii/client/src/client/error.rs index 9f9b831939..1efc06c429 100644 --- a/crates/torii/client/src/client/error.rs +++ b/crates/torii/client/src/client/error.rs @@ -1,5 +1,6 @@ use dojo_world::contracts::model::ModelError; use starknet::core::utils::{CairoShortStringToFeltError, ParseCairoShortStringError}; +use torii_grpc::types::schema::SchemaError; #[derive(Debug, thiserror::Error)] pub enum Error { @@ -22,6 +23,8 @@ pub enum Error { Model(#[from] ModelError), #[error("Unsupported query")] UnsupportedQuery, + #[error(transparent)] + Schema(#[from] SchemaError), } #[derive(Debug, thiserror::Error)] diff --git a/crates/torii/grpc/src/client.rs b/crates/torii/grpc/src/client.rs index b71f767a84..4a11e04777 100644 --- a/crates/torii/grpc/src/client.rs +++ b/crates/torii/grpc/src/client.rs @@ -3,7 +3,7 @@ use std::num::ParseIntError; use futures_util::stream::MapOk; use futures_util::{Stream, StreamExt, TryStreamExt}; -use starknet::core::types::{FromByteSliceError, FromStrError, StateUpdate}; +use starknet::core::types::{FromStrError, StateUpdate}; use starknet_crypto::FieldElement; use crate::proto::world::{ @@ -11,27 +11,22 @@ use crate::proto::world::{ SubscribeEntitiesRequest, SubscribeEntityResponse, SubscribeModelsRequest, SubscribeModelsResponse, }; -use crate::types::schema::Entity; +use crate::types::schema::{self, Entity, SchemaError}; use crate::types::{KeysClause, Query}; #[derive(Debug, thiserror::Error)] pub enum Error { #[error(transparent)] Grpc(tonic::Status), - #[error("Missing expected data")] - MissingExpectedData, - #[error("Unsupported type")] - UnsupportedType, #[error(transparent)] ParseStr(FromStrError), #[error(transparent)] - SliceError(FromByteSliceError), - #[error(transparent)] ParseInt(ParseIntError), - #[cfg(not(target_arch = "wasm32"))] #[error(transparent)] Transport(tonic::transport::Error), + #[error(transparent)] + Schema(#[from] schema::SchemaError), } /// A lightweight wrapper around the grpc client. @@ -71,7 +66,9 @@ impl WorldClient { .world_metadata(MetadataRequest {}) .await .map_err(Error::Grpc) - .and_then(|res| res.into_inner().metadata.ok_or(Error::MissingExpectedData)) + .and_then(|res| { + res.into_inner().metadata.ok_or(Error::Schema(SchemaError::MissingExpectedData)) + }) .and_then(|metadata| metadata.try_into().map_err(Error::ParseStr)) } diff --git a/crates/torii/grpc/src/types/schema.rs b/crates/torii/grpc/src/types/schema.rs index 894ea4e85b..a02aa330db 100644 --- a/crates/torii/grpc/src/types/schema.rs +++ b/crates/torii/grpc/src/types/schema.rs @@ -2,11 +2,21 @@ use crypto_bigint::{Encoding, U256}; use dojo_types::primitive::Primitive; use dojo_types::schema::{Enum, EnumOption, Member, Struct, Ty}; use serde::{Deserialize, Serialize}; +use starknet::core::types::FromByteSliceError; use starknet_crypto::FieldElement; -use crate::client::Error as ClientError; use crate::proto::{self}; +#[derive(Debug, thiserror::Error)] +pub enum SchemaError { + #[error("Missing expected data")] + MissingExpectedData, + #[error("Unsupported type")] + UnsupportedType, + #[error(transparent)] + SliceError(#[from] FromByteSliceError), +} + #[derive(Debug, Serialize, Deserialize, PartialEq, Hash, Eq, Clone)] pub struct Entity { pub hashed_keys: FieldElement, @@ -20,11 +30,10 @@ pub struct Model { } impl TryFrom for Entity { - type Error = ClientError; + type Error = SchemaError; fn try_from(entity: proto::types::Entity) -> Result { Ok(Self { - hashed_keys: FieldElement::from_byte_slice_be(&entity.hashed_keys) - .map_err(ClientError::SliceError)?, + hashed_keys: FieldElement::from_byte_slice_be(&entity.hashed_keys)?, models: entity .models .into_iter() @@ -35,7 +44,7 @@ impl TryFrom for Entity { } impl TryFrom for Model { - type Error = ClientError; + type Error = SchemaError; fn try_from(model: proto::types::Model) -> Result { Ok(Self { name: model.name, @@ -49,7 +58,7 @@ impl TryFrom for Model { } impl TryFrom for proto::types::Ty { - type Error = ClientError; + type Error = SchemaError; fn try_from(ty: Ty) -> Result { let ty_type = match ty { Ty::Primitive(primitive) => { @@ -65,18 +74,18 @@ impl TryFrom for proto::types::Ty { } impl TryFrom for Member { - type Error = ClientError; + type Error = SchemaError; fn try_from(member: proto::types::Member) -> Result { Ok(Member { name: member.name, - ty: member.ty.ok_or(ClientError::MissingExpectedData)?.try_into()?, + ty: member.ty.ok_or(SchemaError::MissingExpectedData)?.try_into()?, key: member.key, }) } } impl TryFrom for proto::types::Member { - type Error = ClientError; + type Error = SchemaError; fn try_from(member: Member) -> Result { Ok(proto::types::Member { name: member.name, @@ -119,7 +128,7 @@ impl From for proto::types::Enum { } impl TryFrom for Struct { - type Error = ClientError; + type Error = SchemaError; fn try_from(r#struct: proto::types::Struct) -> Result { Ok(Struct { name: r#struct.name, @@ -133,7 +142,7 @@ impl TryFrom for Struct { } impl TryFrom for proto::types::Struct { - type Error = ClientError; + type Error = SchemaError; fn try_from(r#struct: Struct) -> Result { Ok(proto::types::Struct { name: r#struct.name, @@ -147,7 +156,7 @@ impl TryFrom for proto::types::Struct { } impl TryFrom for proto::types::Model { - type Error = ClientError; + type Error = SchemaError; fn try_from(r#struct: Struct) -> Result { let r#struct: proto::types::Struct = r#struct.try_into()?; @@ -167,14 +176,14 @@ impl From for proto::types::Model { // warning. #[allow(deprecated)] impl TryFrom for Primitive { - type Error = ClientError; + type Error = SchemaError; fn try_from(primitive: proto::types::Primitive) -> Result { let primitive_type = primitive.r#type; let value_type = primitive .value - .ok_or(ClientError::MissingExpectedData)? + .ok_or(SchemaError::MissingExpectedData)? .value_type - .ok_or(ClientError::MissingExpectedData)?; + .ok_or(SchemaError::MissingExpectedData)?; let primitive = match &value_type { proto::types::value::ValueType::BoolValue(bool) => Primitive::Bool(Some(*bool)), @@ -185,7 +194,7 @@ impl TryFrom for Primitive { Some(proto::types::PrimitiveType::U32) => Primitive::U32(Some(*int as u32)), Some(proto::types::PrimitiveType::U64) => Primitive::U64(Some(*int)), Some(proto::types::PrimitiveType::Usize) => Primitive::USize(Some(*int as u32)), - _ => return Err(ClientError::UnsupportedType), + _ => return Err(SchemaError::UnsupportedType), } } proto::types::value::ValueType::ByteValue(bytes) => { @@ -196,17 +205,17 @@ impl TryFrom for Primitive { | Some(proto::types::PrimitiveType::ContractAddress) => { Primitive::Felt252(Some( FieldElement::from_byte_slice_be(bytes) - .map_err(ClientError::SliceError)?, + .map_err(SchemaError::SliceError)?, )) } Some(proto::types::PrimitiveType::U256) => { Primitive::U256(Some(U256::from_be_slice(bytes))) } - _ => return Err(ClientError::UnsupportedType), + _ => return Err(SchemaError::UnsupportedType), } } _ => { - return Err(ClientError::UnsupportedType); + return Err(SchemaError::UnsupportedType); } }; @@ -215,7 +224,7 @@ impl TryFrom for Primitive { } impl TryFrom for proto::types::Primitive { - type Error = ClientError; + type Error = SchemaError; fn try_from(primitive: Primitive) -> Result { use proto::types::value::ValueType; @@ -252,9 +261,9 @@ impl TryFrom for proto::types::Primitive { } impl TryFrom for Ty { - type Error = ClientError; + type Error = SchemaError; fn try_from(ty: proto::types::Ty) -> Result { - match ty.ty_type.ok_or(ClientError::MissingExpectedData)? { + match ty.ty_type.ok_or(SchemaError::MissingExpectedData)? { proto::types::ty::TyType::Primitive(primitive) => { Ok(Ty::Primitive(primitive.try_into()?)) } diff --git a/dojoup/dojoup b/dojoup/dojoup index 6674df605a..6ded3265e8 100755 --- a/dojoup/dojoup +++ b/dojoup/dojoup @@ -209,13 +209,11 @@ EOF ensure git checkout "$DOJOUP_COMMIT" fi - # Build the repo and install the binaries locally to the .dojo bin directory. - # --root appends /bin to the directory it is given, so we pass DOJO_DIR. - # We should specify all the binaries that need to be built. - ensure cargo install --path ./bin/sozo --locked --force --root "$DOJO_DIR" - ensure cargo install --path ./bin/katana --locked --force --root "$DOJO_DIR" - ensure cargo install --path ./bin/dojo-language-server --locked --force --root "$DOJO_DIR" - # TODO: Torii is failing when installing.. + for bin in "${BINS[@]}"; do + # Build the repo and install the binaries locally to the .dojo bin directory. + # --root appends /bin to the directory it is given, so we pass DOJO_DIR. + ensure cargo install --path ./bin/$bin $bin --locked --force --root "$DOJO_DIR" + done say "done" welcome_msg