diff --git a/Cargo.lock b/Cargo.lock index 27f364e..179400f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -397,7 +397,7 @@ dependencies = [ [[package]] name = "comline-codegen" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=5a76de9011bb7f4f6ded0d507e95c5844bc0c63f#5a76de9011bb7f4f6ded0d507e95c5844bc0c63f" +source = "git+https://github.com/ComlineProject/generation?rev=f919acfe00c313f4d16d7f0bf285c900d80f2513#f919acfe00c313f4d16d7f0bf285c900d80f2513" dependencies = [ "comline-core", "eyre", @@ -406,7 +406,7 @@ dependencies = [ [[package]] name = "comline-codegen-rust" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-rust?rev=87cb367c0b513615403b92521ecf5e831ae66ef0#87cb367c0b513615403b92521ecf5e831ae66ef0" +source = "git+https://github.com/ComlineProject/comline-rust?rev=79e04883b38918803359ae91696b1683613b43ce#79e04883b38918803359ae91696b1683613b43ce" dependencies = [ "comline-codegen", "comline-core", @@ -416,7 +416,7 @@ dependencies = [ [[package]] name = "comline-codegen-typescript" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-typescript?rev=5f104255d67dc0152ad2a17921603529733f8e57#5f104255d67dc0152ad2a17921603529733f8e57" +source = "git+https://github.com/ComlineProject/comline-typescript?rev=def265c76df44f67857b0cd8177efe072509ba4c#def265c76df44f67857b0cd8177efe072509ba4c" dependencies = [ "comline-codegen", "comline-core", @@ -426,7 +426,7 @@ dependencies = [ [[package]] name = "comline-core" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=86e4c4e37ca8e46de79c10b72afe9492c85f75d0#86e4c4e37ca8e46de79c10b72afe9492c85f75d0" +source = "git+https://github.com/ComlineProject/core?rev=30dc8ed4125a2d854d7fb221371715d63e7700c5#30dc8ed4125a2d854d7fb221371715d63e7700c5" dependencies = [ "ariadne", "blake3", @@ -455,7 +455,7 @@ dependencies = [ [[package]] name = "comline-core-stdlib" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=86e4c4e37ca8e46de79c10b72afe9492c85f75d0#86e4c4e37ca8e46de79c10b72afe9492c85f75d0" +source = "git+https://github.com/ComlineProject/core?rev=30dc8ed4125a2d854d7fb221371715d63e7700c5#30dc8ed4125a2d854d7fb221371715d63e7700c5" [[package]] name = "concolor" diff --git a/Cargo.toml b/Cargo.toml index e71fc6b..7ee27e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,15 +29,15 @@ toml = "0.8" # needs real I/O (git fetch, filesystem), so it's off by default for # `comline-core`'s wasm32 consumers (the playground editor, the language # server); the CLI is the one consumer that actually runs `comline build`. -comline-core = { git = "https://github.com/ComlineProject/core", rev = "86e4c4e37ca8e46de79c10b72afe9492c85f75d0", features = ["deps"] } +comline-core = { git = "https://github.com/ComlineProject/core", rev = "30dc8ed4125a2d854d7fb221371715d63e7700c5", features = ["deps"] } # All three pinned to revs that agree on one `comline-codegen`, and bumped # together: comline-rust and comline-typescript's codegen crates consume # `comline-codegen`'s types, so the rev below must be byte-identical to the # one *they* pin - Cargo only unifies a git dependency across identical rev # strings, and two copies of `GenRequest` are two incompatible types. -comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "5a76de9011bb7f4f6ded0d507e95c5844bc0c63f" } -comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "87cb367c0b513615403b92521ecf5e831ae66ef0", optional = true } -comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "5f104255d67dc0152ad2a17921603529733f8e57", optional = true } +comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "f919acfe00c313f4d16d7f0bf285c900d80f2513" } +comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "79e04883b38918803359ae91696b1683613b43ce", optional = true } +comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "def265c76df44f67857b0cd8177efe072509ba4c", optional = true } [features] # Which language generators are compiled in. Drop one to shed its whole diff --git a/tests/cli/end_to_end.rs b/tests/cli/end_to_end.rs index 84a6eef..44e76dd 100644 --- a/tests/cli/end_to_end.rs +++ b/tests/cli/end_to_end.rs @@ -2,7 +2,8 @@ //! `comline generate --mode lib` → the emitted crate is compiled against //! `comline-runtime` and a hand-written driver runs a client ⇆ provider //! round-trip over an in-memory transport (a request/response call, a raised -//! typed error, a one-way notify). +//! typed error, the *second* of two declared errors, a provider fault, a +//! one-way notify). //! //! Slow: it fetches and builds `comline-runtime`. Needs network. @@ -17,8 +18,10 @@ const DRIVER: &str = r#" use std::sync::{Arc, Mutex}; use std::thread; -use chat_e2e::chat::{Chat, ChatClient, ChatDispatcher, ChatSendError, Message, Rejected}; -use comline_runtime::contract::CallError; +use chat_e2e::chat::{ + Chat, ChatClient, ChatDispatcher, ChatSendError, Message, Rejected, TooLong, +}; +use comline_runtime::contract::{CallError, Fault, RuntimeError}; use comline_runtime::format::MsgPack; use comline_runtime::transport::duplex; @@ -27,9 +30,22 @@ struct Svc { } impl Chat for Svc { - fn send(&self, text: &str) -> Result { + fn send(&self, text: &str) -> Result> { if text.is_empty() { - return Err(ChatSendError::Rejected(Rejected { reason: "empty".into() })); + // A declared error: `From for Fault` means `?`/`.into()` + // works, but spell it out here so the test pins the shape. + return Err(Fault::App(ChatSendError::Rejected(Rejected { + reason: "empty".into(), + }))); + } + if text.len() > 8 { + // the second error in `! Rejected, TooLong` + return Err(Fault::App(ChatSendError::TooLong(TooLong { limit: 8 }))); + } + if text == "boom" { + // Nothing in the schema declares this failure. Before the fault + // channel the provider's only options were to panic or to lie. + return Err(Fault::Internal); } Ok(Message { body: format!("echo: {text}"), seq: 1 }) } @@ -63,6 +79,33 @@ fn client_and_provider_over_duplex() { other => panic!("expected a Rejected, got {other:?}"), } + // The declared error renders through the generated `Display`, from the + // schema's `message` template. + assert_eq!( + Rejected { reason: "empty".into() }.to_string(), + "rejected: empty", + ); + + // Both arms of `! Rejected, TooLong` are reachable, and each decodes + // into its own variant rather than into whichever shares an ordinal. + match client.send("far too long to accept").unwrap_err() { + CallError::App(ChatSendError::TooLong(t)) => { + assert_eq!(t.limit, 8); + assert_eq!(t.to_string(), "too long: 8 max"); + } + other => panic!("expected a TooLong, got {other:?}"), + } + + // An undeclared failure arrives as a fault, not as some ordinal the + // client would have decoded into the wrong error type. + match client.send("boom").unwrap_err() { + CallError::Runtime(RuntimeError::Provider) => {} + other => panic!("expected a provider fault, got {other:?}"), + } + + // and the connection survives it — a fault is a reply, not a teardown + assert_eq!(client.send("ok").unwrap().body, "echo: ok"); + client.note("saved").unwrap(); // one-way drop(client); diff --git a/tests/fixtures/chat_project/src/chat.ids b/tests/fixtures/chat_project/src/chat.ids index 2005a14..db4484f 100644 --- a/tests/fixtures/chat_project/src/chat.ids +++ b/tests/fixtures/chat_project/src/chat.ids @@ -8,9 +8,14 @@ error Rejected { reason: str } +error TooLong { + message = "too long: {self.limit} max" + limit: u32 +} + protocol Chat { - /// Request/response with a struct return and a raised error. - function send(text: str) -> Message ! Rejected; + /// Request/response with a struct return, raising either of two errors. + function send(text: str) -> Message ! Rejected, TooLong; /// Fire-and-forget. function note(text: str); }