use smol_bytes::Utf8Bytes;
use crate::{
arrange::{EdgeId, NodeId},
resource::{ResourceKind, ResourceName},
};
#[cfg(test)]
mod tests;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnknownNodeError {
name: Utf8Bytes,
}
impl UnknownNodeError {
#[inline]
pub(crate) const fn new(name: Utf8Bytes) -> Self {
Self { name }
}
#[inline]
#[must_use]
pub fn name(&self) -> &str {
self.name.as_str()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UndeclaredResourceError {
node: NodeId,
name: Utf8Bytes,
resource: &'static ResourceName,
}
impl UndeclaredResourceError {
#[inline]
pub(crate) const fn new(node: NodeId, name: Utf8Bytes, resource: &'static ResourceName) -> Self {
Self {
node,
name,
resource,
}
}
#[inline]
#[must_use]
pub const fn node(&self) -> NodeId {
self.node
}
#[inline]
#[must_use]
pub fn name(&self) -> &str {
self.name.as_str()
}
#[inline]
#[must_use]
pub const fn resource(&self) -> &'static ResourceName {
self.resource
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnboundSlotError {
slot: Utf8Bytes,
kind: ResourceKind,
candidates: Vec<&'static ResourceName>,
}
impl UnboundSlotError {
#[inline]
pub(crate) const fn new(
slot: Utf8Bytes,
kind: ResourceKind,
candidates: Vec<&'static ResourceName>,
) -> Self {
Self {
slot,
kind,
candidates,
}
}
#[inline]
#[must_use]
pub fn slot(&self) -> &str {
self.slot.as_str()
}
#[inline]
#[must_use]
pub const fn kind(&self) -> ResourceKind {
self.kind
}
#[inline]
#[must_use]
pub fn candidates(&self) -> &[&'static ResourceName] {
&self.candidates
}
#[must_use]
pub fn advice(&self) -> String {
if self.candidates.is_empty() {
return format!(
"this deployment declares no resource that holds {kind}; declare one with \
`#[ingraph::resource(…)]` and mount it on the graph root",
kind = self.kind,
);
}
let listed = self
.candidates
.iter()
.map(|name| format!("`{}`", name.as_str()))
.collect::<Vec<_>>()
.join(", ");
format!(
"this deployment declares {count} resources that hold {kind} ({listed}), and choosing \
between them is not this framework's to do; write `resource = \"…\"` on the leg",
count = self.candidates.len(),
kind = self.kind,
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PureLeafError {
node: NodeId,
name: Utf8Bytes,
}
impl PureLeafError {
#[inline]
pub(crate) const fn new(node: NodeId, name: Utf8Bytes) -> Self {
Self { node, name }
}
#[inline]
#[must_use]
pub const fn node(&self) -> NodeId {
self.node
}
#[inline]
#[must_use]
pub fn name(&self) -> &str {
self.name.as_str()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct LandsNowhereError {
node: NodeId,
name: Utf8Bytes,
}
impl LandsNowhereError {
#[inline]
pub(crate) const fn new(node: NodeId, name: Utf8Bytes) -> Self {
Self { node, name }
}
#[inline]
#[must_use]
pub const fn node(&self) -> NodeId {
self.node
}
#[inline]
#[must_use]
pub fn name(&self) -> &str {
self.name.as_str()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FeederAbsentError {
edge: EdgeId,
consumer: NodeId,
consumer_name: Utf8Bytes,
watched: NodeId,
watched_name: Utf8Bytes,
}
impl FeederAbsentError {
#[inline]
pub(crate) const fn new(
edge: EdgeId,
consumer: NodeId,
consumer_name: Utf8Bytes,
watched: NodeId,
watched_name: Utf8Bytes,
) -> Self {
Self {
edge,
consumer,
consumer_name,
watched,
watched_name,
}
}
#[inline]
#[must_use]
pub const fn edge(&self) -> EdgeId {
self.edge
}
#[inline]
#[must_use]
pub const fn consumer(&self) -> NodeId {
self.consumer
}
#[inline]
#[must_use]
pub fn consumer_name(&self) -> &str {
self.consumer_name.as_str()
}
#[inline]
#[must_use]
pub const fn watched(&self) -> NodeId {
self.watched
}
#[inline]
#[must_use]
pub fn watched_name(&self) -> &str {
self.watched_name.as_str()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DisabledUpstreamError {
edge: EdgeId,
consumer: NodeId,
consumer_name: Utf8Bytes,
producer: NodeId,
producer_name: Utf8Bytes,
}
impl DisabledUpstreamError {
#[inline]
pub(crate) const fn new(
edge: EdgeId,
consumer: NodeId,
consumer_name: Utf8Bytes,
producer: NodeId,
producer_name: Utf8Bytes,
) -> Self {
Self {
edge,
consumer,
consumer_name,
producer,
producer_name,
}
}
#[inline]
#[must_use]
pub const fn edge(&self) -> EdgeId {
self.edge
}
#[inline]
#[must_use]
pub const fn consumer(&self) -> NodeId {
self.consumer
}
#[inline]
#[must_use]
pub fn consumer_name(&self) -> &str {
self.consumer_name.as_str()
}
#[inline]
#[must_use]
pub const fn producer(&self) -> NodeId {
self.producer
}
#[inline]
#[must_use]
pub fn producer_name(&self) -> &str {
self.producer_name.as_str()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnbridgedOriginError {
edge: EdgeId,
origin: NodeId,
origin_name: Utf8Bytes,
consumer: NodeId,
consumer_name: Utf8Bytes,
listen: &'static str,
}
impl UnbridgedOriginError {
#[inline]
pub(crate) const fn new(
edge: EdgeId,
origin: NodeId,
origin_name: Utf8Bytes,
consumer: NodeId,
consumer_name: Utf8Bytes,
listen: &'static str,
) -> Self {
Self {
edge,
origin,
origin_name,
consumer,
consumer_name,
listen,
}
}
#[inline]
#[must_use]
pub const fn listen(&self) -> &'static str {
self.listen
}
#[inline]
#[must_use]
pub const fn edge(&self) -> EdgeId {
self.edge
}
#[inline]
#[must_use]
pub const fn origin(&self) -> NodeId {
self.origin
}
#[inline]
#[must_use]
pub fn origin_name(&self) -> &str {
self.origin_name.as_str()
}
#[inline]
#[must_use]
pub const fn consumer(&self) -> NodeId {
self.consumer
}
#[inline]
#[must_use]
pub fn consumer_name(&self) -> &str {
self.consumer_name.as_str()
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SplitOriginError {
origin: NodeId,
origin_name: Utf8Bytes,
consumers: Vec<Utf8Bytes>,
}
impl SplitOriginError {
#[inline]
pub(crate) const fn new(
origin: NodeId,
origin_name: Utf8Bytes,
consumers: Vec<Utf8Bytes>,
) -> Self {
Self {
origin,
origin_name,
consumers,
}
}
#[inline]
#[must_use]
pub const fn origin(&self) -> NodeId {
self.origin
}
#[inline]
#[must_use]
pub fn origin_name(&self) -> &str {
self.origin_name.as_str()
}
#[inline]
#[must_use]
pub fn consumers(&self) -> &[Utf8Bytes] {
&self.consumers
}
#[inline]
#[must_use]
pub fn count(&self) -> usize {
self.consumers.len()
}
fn listed(&self) -> String {
self
.consumers
.iter()
.map(|name| format!("`{}`", name.as_str()))
.collect::<Vec<_>>()
.join(", ")
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DroppingUnboundedError {
node: NodeId,
name: Utf8Bytes,
upstream: usize,
}
impl DroppingUnboundedError {
#[inline]
pub(crate) const fn new(node: NodeId, name: Utf8Bytes, upstream: usize) -> Self {
Self {
node,
name,
upstream,
}
}
#[inline]
#[must_use]
pub const fn node(&self) -> NodeId {
self.node
}
#[inline]
#[must_use]
pub fn name(&self) -> &str {
self.name.as_str()
}
#[inline]
#[must_use]
pub const fn upstream(&self) -> usize {
self.upstream
}
}
#[derive(
Debug,
Clone,
PartialEq,
Eq,
derive_more::Display,
derive_more::IsVariant,
derive_more::Unwrap,
derive_more::TryUnwrap,
)]
#[unwrap(ref, ref_mut)]
#[try_unwrap(ref, ref_mut)]
#[non_exhaustive]
pub enum Refusal {
#[display("the options name `{}`, which this arrangement does not declare", _0.name())]
UnknownNode(UnknownNodeError),
#[display(
"{} (`{}`) demands the resource `{}`, which no declaration registered; \
declare it with `#[ingraph::resource]`",
_0.node(), _0.name(), _0.resource().as_str()
)]
UndeclaredResource(Box<UndeclaredResourceError>),
#[display(
"{} (`{}`) lands nothing, publishes to nobody, polls nothing and answers nobody; \
give it a consumer, a store, a poll upstream, or a query arm",
_0.node(), _0.name()
)]
PureLeaf(PureLeafError),
#[display(
"{} (`{}`) declares that it lands, and holds no write lane and publishes to nobody; \
give it a lane of its own, or a consumer that lands what it emits",
_0.node(), _0.name()
)]
LandsNowhere(LandsNowhereError),
#[display(
"{} (`{}`) listens on the channel of {} (`{}`), which this deployment does not launch (no \
section names it); listen to its changes instead, or launch it",
_0.consumer(), _0.consumer_name(), _0.producer(), _0.producer_name()
)]
DisabledUpstream(Box<DisabledUpstreamError>),
#[display(
"{} (`{}`) takes its query edge from {} (`{}`), which this deployment does not launch (no \
section names it); a query has no store to fall back on, so launch it",
_0.consumer(), _0.consumer_name(), _0.producer(), _0.producer_name()
)]
DisabledQueryUpstream(Box<DisabledUpstreamError>),
#[display(
"{} (`{}`) listens to the changes of {} (`{}`), and no node of this graph lands into that \
store; say `external` if the store is filled from another process, or subscribe to `{}` \
directly if you meant the in-graph geometry, or add the node that lands into it",
_0.consumer(), _0.consumer_name(), _0.watched(), _0.watched_name(), _0.watched_name()
)]
FeederAbsent(Box<FeederAbsentError>),
#[display(
"{} (`{}`) listens to the origin {} (`{}`) by `{}`, and an origin has nothing to be heard \
through that word with: it lands nothing, so there is no store to watch or poll, and it answers \
nobody, so there is no door to ask; subscribe to `{}` over the channel, which is what an origin \
publishes on",
_0.consumer(), _0.consumer_name(), _0.origin(), _0.origin_name(), _0.listen(), _0.origin_name()
)]
UnbridgedOrigin(Box<UnbridgedOriginError>),
#[display(
"{} (`{}`) is an origin and this deployment launches {} consumers of it ({}), but an origin has \
ONE feed and it becomes ONE edge — put a pass-through operator under `{}` and fan out from \
there, or launch one of them",
_0.origin(), _0.origin_name(), _0.count(), _0.listed(), _0.origin_name()
)]
SplitOrigin(Box<SplitOriginError>),
#[display(
"`{}` subscribes to `{}`, which this graph root does not mount; give the root a field for it, \
or point the subscription at a node the root declares",
_0.node(), _0.upstream()
)]
UnknownUpstream(UnknownUpstreamError),
#[display(
"`{}`'s `{}` clock grants itself `write = \"{}\"`, which this graph root does not mount; give \
the root a field for it, or point the grant at a node the root declares",
_0.node(), _0.clock(), _0.granted()
)]
UnknownGrant(UnknownGrantError),
#[display(
"`{}`'s `{}` clock grants itself `write = \"{}\"`, and `{}` keeps no store to write into — a \
pure node's output is computed and gone; grant a node that lands, or drop the word",
_0.node(), _0.clock(), _0.granted(), _0.mount()
)]
GrantsNoStore(GrantsNoStoreError),
#[display(
"{} (`{}`) opens its upstream #{} unbounded, and this deployment's overflow policy sheds; \
nothing overflows a queue nothing bounds — bound the edge, or run a policy that blocks",
_0.node(), _0.name(), _0.upstream()
)]
DroppingUnbounded(Box<DroppingUnboundedError>),
#[display(
"the `{}` corpus names no resource, and {}",
_0.slot(), _0.advice()
)]
UnboundSlot(Box<UnboundSlotError>),
#[display("{}", _0.sentence())]
Arrangement(ArrangementError),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnknownUpstreamError {
node: Utf8Bytes,
upstream: &'static str,
}
impl UnknownUpstreamError {
#[inline]
pub(crate) const fn new(node: Utf8Bytes, upstream: &'static str) -> Self {
Self { node, upstream }
}
#[inline]
#[must_use]
pub fn node(&self) -> &str {
self.node.as_str()
}
#[inline]
#[must_use]
pub const fn upstream(&self) -> &'static str {
self.upstream
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UnknownGrantError {
node: Utf8Bytes,
clock: &'static str,
granted: &'static str,
}
impl UnknownGrantError {
#[inline]
pub(crate) const fn new(node: Utf8Bytes, clock: &'static str, granted: &'static str) -> Self {
Self {
node,
clock,
granted,
}
}
#[inline]
#[must_use]
pub fn node(&self) -> &str {
self.node.as_str()
}
#[inline]
#[must_use]
pub const fn clock(&self) -> &'static str {
self.clock
}
#[inline]
#[must_use]
pub const fn granted(&self) -> &'static str {
self.granted
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GrantsNoStoreError {
node: Utf8Bytes,
clock: &'static str,
mount: Utf8Bytes,
granted: &'static str,
}
impl GrantsNoStoreError {
#[inline]
pub(crate) const fn new(
node: Utf8Bytes,
clock: &'static str,
mount: Utf8Bytes,
granted: &'static str,
) -> Self {
Self {
node,
clock,
mount,
granted,
}
}
#[inline]
#[must_use]
pub fn node(&self) -> &str {
self.node.as_str()
}
#[inline]
#[must_use]
pub const fn clock(&self) -> &'static str {
self.clock
}
#[inline]
#[must_use]
pub fn mount(&self) -> &str {
self.mount.as_str()
}
#[inline]
#[must_use]
pub const fn granted(&self) -> &'static str {
self.granted
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ArrangementError {
sentence: Utf8Bytes,
}
impl ArrangementError {
#[inline]
pub(crate) fn new(sentence: impl Into<Utf8Bytes>) -> Self {
Self {
sentence: sentence.into(),
}
}
#[inline]
#[must_use]
pub fn sentence(&self) -> &str {
self.sentence.as_str()
}
}