diff --git a/packages/cli/src/commands/actor/create.rs b/packages/cli/src/commands/actor/create.rs index a09d0f7c..7eb5b5b2 100644 --- a/packages/cli/src/commands/actor/create.rs +++ b/packages/cli/src/commands/actor/create.rs @@ -231,7 +231,6 @@ impl Opts { build: build_id, build_tags: build_tags.map(|bt| Some(serde_json::json!(bt))), runtime: Box::new(models::ActorCreateActorRuntimeRequest { - arguments: None, environment: env_vars, }), network: Some(Box::new(models::ActorCreateActorNetworkRequest { diff --git a/packages/cli/src/main.rs b/packages/cli/src/main.rs index 351c437d..2e9d082d 100644 --- a/packages/cli/src/main.rs +++ b/packages/cli/src/main.rs @@ -64,10 +64,10 @@ async fn main_async() -> ExitCode { // Don't print anything, already handled } else if let Some(err) = err.downcast_ref::() { // Don't report error since this is a user error - eprintln!("{err}"); + eprintln!("\n{err}"); } else { // This is an internal error, report error - eprintln!("{err}"); + eprintln!("\n{err}"); report_error(err).await; } diff --git a/scripts/sdk/copy.ts b/scripts/sdk/copy.ts index 7a989ddc..a4fa831a 100755 --- a/scripts/sdk/copy.ts +++ b/scripts/sdk/copy.ts @@ -1,4 +1,4 @@ -#!/usr/bin/env -S deno run --allow-read --allow-write --allow-env +#!/usr/bin/env -S deno run -A import { assertExists } from "jsr:@std/assert"; import { emptyDir, copy } from "jsr:@std/fs"; @@ -12,12 +12,27 @@ await emptyDir(rustSdkDir); const eeRepoPath = Deno.env.get("EE_REPO_PATH"); assertExists(eeRepoPath, "EE_REPO_PATH environment variable is not set"); -await copy(join(eeRepoPath, "sdks", "full", "rust"), rustSdkDir, { overwrite: true }); +await copy(join(eeRepoPath, "sdks", "api", "full", "rust"), rustSdkDir, { + overwrite: true, +}); let cargoToml = await Deno.readTextFile(cargoTomlPath); cargoToml = cargoToml.replace( /\[dependencies\.reqwest\]/, - "[dependencies.reqwest]\ndefault-features = false" + "[dependencies.reqwest]\ndefault-features = false", ); await Deno.writeTextFile(cargoTomlPath, cargoToml); +const modRsPath = join(rustSdkDir, "src", "apis", "mod.rs"); +const patchFilePath = "./scripts/sdk/error.patch"; + +const patchProcess = new Deno.Command("patch", { + args: [modRsPath, patchFilePath], + stdout: "inherit", + stderr: "inherit", +}); +const { success } = await patchProcess.output(); +if (!success) { + console.error("Failed to apply patch"); + Deno.exit(1); +} diff --git a/scripts/sdk/error.patch b/scripts/sdk/error.patch new file mode 100644 index 00000000..260c610f --- /dev/null +++ b/scripts/sdk/error.patch @@ -0,0 +1,42 @@ +diff --git a/sdks/rust/src/apis/mod.rs b/sdks/rust/src/apis/mod.rs +index 73ed6261..caa52f60 100644 +--- a/sdks/rust/src/apis/mod.rs ++++ b/sdks/rust/src/apis/mod.rs +@@ -16,16 +16,33 @@ pub enum Error { + ResponseError(ResponseContent), + } + ++#[derive(serde::Deserialize)] ++pub struct RivetErrorBody { ++ pub code: String, ++ pub message: String, ++ pub documentation: Option, ++} ++ + impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let (module, e) = match self { + Error::Reqwest(e) => ("reqwest", e.to_string()), + Error::Serde(e) => ("serde", e.to_string()), + Error::Io(e) => ("IO", e.to_string()), +- Error::ResponseError(e) => ( +- "response", +- format!("status code {}\n{}", e.status, e.content), +- ), ++ Error::ResponseError(e) => { ++ if let Ok(body) = serde_json::from_str::(&e.content) { ++ write!(f, "{}", body.message)?; ++ if let Some(docs) = &body.documentation { ++ write!(f, "\n{docs}")?; ++ } ++ return Ok(()); ++ } ++ ++ ( ++ "response", ++ format!("status code {}\n{}", e.status, e.content), ++ ) ++ } + }; + write!(f, "error in {}: {}", module, e) + } diff --git a/sdks/rust/docs/ActorCreateActorRuntimeRequest.md b/sdks/rust/docs/ActorCreateActorRuntimeRequest.md index 463a6a7e..84b8b389 100644 --- a/sdks/rust/docs/ActorCreateActorRuntimeRequest.md +++ b/sdks/rust/docs/ActorCreateActorRuntimeRequest.md @@ -4,7 +4,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- -**arguments** | Option<**Vec**> | | [optional] **environment** | Option<**::std::collections::HashMap**> | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/sdks/rust/src/apis/mod.rs b/sdks/rust/src/apis/mod.rs index 73ed6261..caa52f60 100644 --- a/sdks/rust/src/apis/mod.rs +++ b/sdks/rust/src/apis/mod.rs @@ -16,16 +16,33 @@ pub enum Error { ResponseError(ResponseContent), } +#[derive(serde::Deserialize)] +pub struct RivetErrorBody { + pub code: String, + pub message: String, + pub documentation: Option, +} + impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let (module, e) = match self { Error::Reqwest(e) => ("reqwest", e.to_string()), Error::Serde(e) => ("serde", e.to_string()), Error::Io(e) => ("IO", e.to_string()), - Error::ResponseError(e) => ( - "response", - format!("status code {}\n{}", e.status, e.content), - ), + Error::ResponseError(e) => { + if let Ok(body) = serde_json::from_str::(&e.content) { + write!(f, "{}", body.message)?; + if let Some(docs) = &body.documentation { + write!(f, "\n{docs}")?; + } + return Ok(()); + } + + ( + "response", + format!("status code {}\n{}", e.status, e.content), + ) + } }; write!(f, "error in {}: {}", module, e) } diff --git a/sdks/rust/src/models/actor_create_actor_runtime_request.rs b/sdks/rust/src/models/actor_create_actor_runtime_request.rs index 99841b8b..133335c2 100644 --- a/sdks/rust/src/models/actor_create_actor_runtime_request.rs +++ b/sdks/rust/src/models/actor_create_actor_runtime_request.rs @@ -10,17 +10,12 @@ #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] pub struct ActorCreateActorRuntimeRequest { - #[serde(rename = "arguments", skip_serializing_if = "Option::is_none")] - pub arguments: Option>, #[serde(rename = "environment", skip_serializing_if = "Option::is_none")] pub environment: Option<::std::collections::HashMap>, } impl ActorCreateActorRuntimeRequest { pub fn new() -> ActorCreateActorRuntimeRequest { - ActorCreateActorRuntimeRequest { - arguments: None, - environment: None, - } + ActorCreateActorRuntimeRequest { environment: None } } }