Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 48 additions & 5 deletions tests/cli/end_to_end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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;

Expand All @@ -27,9 +30,22 @@ struct Svc {
}

impl Chat for Svc {
fn send(&self, text: &str) -> Result<Message, ChatSendError> {
fn send(&self, text: &str) -> Result<Message, Fault<ChatSendError>> {
if text.is_empty() {
return Err(ChatSendError::Rejected(Rejected { reason: "empty".into() }));
// A declared error: `From<E> for Fault<E>` 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 })
}
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions tests/fixtures/chat_project/src/chat.ids
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading