Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

elk-#8 Impl error trait for user facing errors #46

Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ elk_cargo_fmt_and_clippy_template: &ELK_CARGO_FMT_AND_CLIPPY
- cargo clippy -- -D warnings

elk_common_build_debug_template: &ELK_COMMON_BUILD_DEBUG
build_script: cargo build --all-targets
build_script: cargo build --workspace --all-targets

elk_common_build_and_test_debug_template: &ELK_COMMON_BUILD_AND_TEST_DEBUG
<<: *ELK_COMMON_BUILD_DEBUG
test_script: cargo test --workspace --no-fail-fast

elk_common_build_release_template: &ELK_COMMON_BUILD_RELEASE
build_script: cargo build --release --all-targets
build_script: cargo build --release --workspace --all-targets

elk_common_build_and_test_no_doc_tests_release_template: &ELK_COMMON_BUILD_AND_TEST_NO_DOC_TESTS_RELEASE
<<: *ELK_COMMON_BUILD_RELEASE
Expand Down
8 changes: 8 additions & 0 deletions elkodon/src/global_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ pub enum ConfigCreationError {
UnableToDeserializeContents,
}

impl std::fmt::Display for ConfigCreationError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for ConfigCreationError {}

#[derive(Serialize, Deserialize, Default, Debug, Clone)]
pub struct Service {
pub directory: String,
Expand Down
8 changes: 8 additions & 0 deletions elkodon/src/port/details/publisher_connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ enum_gen! { ConnectionFailure
SharedMemoryOpenError to UnableToMapPublishersDataSegment
}

impl std::fmt::Display for ConnectionFailure {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for ConnectionFailure {}

#[derive(Debug)]
pub(crate) struct Connection<'global_config, Service: service::Details<'global_config>> {
pub(crate) receiver:
Expand Down
8 changes: 8 additions & 0 deletions elkodon/src/port/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ pub enum ListenerCreateError {
ResourceCreationFailed,
}

impl std::fmt::Display for ListenerCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for ListenerCreateError {}

#[derive(Debug)]
pub struct Listener<'a, 'global_config: 'a, Service: service::Details<'global_config>> {
_dynamic_config_guard: Option<UniqueIndex<'a>>,
Expand Down
8 changes: 8 additions & 0 deletions elkodon/src/port/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ pub enum DegrationAction {
Fail,
}

impl std::fmt::Display for DegrationAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for DegrationAction {}

tiny_fn! {
pub struct DegrationCallback = Fn(service: service::static_config::StaticConfig, publisher_id: UniquePublisherId, subscriber_id: UniqueSubscriberId) -> DegrationAction;
}
Expand Down
16 changes: 16 additions & 0 deletions elkodon/src/port/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,27 @@ pub enum NotifierCreateError {
ExceedsMaxSupportedNotifiers,
}

impl std::fmt::Display for NotifierCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for NotifierCreateError {}

#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum NotifierConnectionUpdateFailure {
OnlyPartialUpdate,
}

impl std::fmt::Display for NotifierConnectionUpdateFailure {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for NotifierConnectionUpdateFailure {}

#[derive(Debug, Default)]
struct ListenerConnections<'global_config, Service: service::Details<'global_config>> {
#[allow(clippy::type_complexity)]
Expand Down
24 changes: 24 additions & 0 deletions elkodon/src/port/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,43 @@ pub enum PublisherCreateError {
UnableToCreateDataSegment,
}

impl std::fmt::Display for PublisherCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for PublisherCreateError {}

#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
pub enum LoanError {
OutOfMemory,
ExceedsMaxLoanedChunks,
InternalFailure,
}

impl std::fmt::Display for LoanError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for LoanError {}

enum_gen! { SendCopyError
mapping:
LoanError to LoanError,
ZeroCopyCreationError to ConnectionError
}

impl std::fmt::Display for SendCopyError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for SendCopyError {}

pub(crate) fn data_segment_name(publisher_id: UniquePublisherId) -> FileName {
let msg = "The system does not support the required file name length for the publishers data segment.";
let origin = "data_segment_name()";
Expand Down
16 changes: 16 additions & 0 deletions elkodon/src/port/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,27 @@ pub enum ReceiveError {
ConnectionFailure(ConnectionFailure),
}

impl std::fmt::Display for ReceiveError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for ReceiveError {}

#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum SubscriberCreateError {
ExceedsMaxSupportedSubscribers,
}

impl std::fmt::Display for SubscriberCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for SubscriberCreateError {}

#[derive(Debug)]
pub struct Subscriber<
'a,
Expand Down
24 changes: 24 additions & 0 deletions elkodon/src/service/builder/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ pub enum EventOpenError {
UnableToOpenDynamicServiceInformation,
}

impl std::fmt::Display for EventOpenError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for EventOpenError {}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum EventCreateError {
Corrupted,
Expand All @@ -31,13 +39,29 @@ pub enum EventCreateError {
UnableToCreateStaticServiceInformation,
}

impl std::fmt::Display for EventCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for EventCreateError {}

enum_gen! {
EventOpenOrCreateError
mapping:
EventOpenError,
EventCreateError
}

impl std::fmt::Display for EventOpenOrCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for EventOpenOrCreateError {}

#[derive(Debug)]
pub struct Builder<'global_config, ServiceType: service::Details<'global_config>> {
base: builder::BuilderWithServiceType<'global_config, ServiceType>,
Expand Down
16 changes: 16 additions & 0 deletions elkodon/src/service/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,29 @@ enum_gen! {
DynamicStorageOpenError
}

impl std::fmt::Display for OpenDynamicStorageFailure {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for OpenDynamicStorageFailure {}

enum_gen! {
ReadStaticStorageFailure
mapping:
StaticStorageOpenError,
StaticStorageReadError
}

impl std::fmt::Display for ReadStaticStorageFailure {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for ReadStaticStorageFailure {}

#[derive(Debug)]
pub struct Builder<S: Service> {
name: ServiceName,
Expand Down
24 changes: 24 additions & 0 deletions elkodon/src/service/builder/publish_subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ pub enum PublishSubscribeOpenError {
UnableToOpenDynamicServiceInformation,
}

impl std::fmt::Display for PublishSubscribeOpenError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for PublishSubscribeOpenError {}

#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
pub enum PublishSubscribeCreateError {
Corrupted,
Expand All @@ -41,6 +49,14 @@ pub enum PublishSubscribeCreateError {
UnableToCreateStaticServiceInformation,
}

impl std::fmt::Display for PublishSubscribeCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for PublishSubscribeCreateError {}

#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq)]
enum ServiceAvailabilityState {
ServiceState(ServiceState),
Expand All @@ -54,6 +70,14 @@ enum_gen! {
PublishSubscribeCreateError
}

impl std::fmt::Display for PublishSubscribeOpenOrCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for PublishSubscribeOpenOrCreateError {}

#[derive(Debug)]
pub struct Builder<'global_config, ServiceType: service::Details<'global_config>> {
base: builder::BuilderWithServiceType<'global_config, ServiceType>,
Expand Down
16 changes: 16 additions & 0 deletions elkodon/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,28 @@ pub enum ServiceDoesExistError {
InternalError,
}

impl std::fmt::Display for ServiceDoesExistError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for ServiceDoesExistError {}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ServiceListError {
InsufficientPermissions,
InternalError,
}

impl std::fmt::Display for ServiceListError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for ServiceListError {}

pub(crate) fn event_concept_name(listener_id: &UniqueListenerId) -> FileName {
let msg = "The system does not support the required file name length for the listeners event concept name.";
let origin = "event_concept_name()";
Expand Down
8 changes: 8 additions & 0 deletions elkodon_bb/container/src/semantic_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ pub enum SemanticStringError {
ExceedsMaximumLength,
}

impl std::fmt::Display for SemanticStringError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for SemanticStringError {}

pub trait SemanticStringAccessor<const CAPACITY: usize> {
/// Creates a new empty SemanticStringAccessor which may violates the content contract.
///
Expand Down
32 changes: 32 additions & 0 deletions elkodon_cal/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,58 @@ pub enum NotifierNotifyError {
InternalFailure,
}

impl std::fmt::Display for NotifierNotifyError {
elfenpiff marked this conversation as resolved.
Show resolved Hide resolved
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for NotifierNotifyError {}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum NotifierCreateError {
DoesNotExist,
InsufficientPermissions,
InternalFailure,
}

impl std::fmt::Display for NotifierCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for NotifierCreateError {}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum ListenerWaitError {
ContractViolation,
InternalFailure,
}

impl std::fmt::Display for ListenerWaitError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for ListenerWaitError {}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum ListenerCreateError {
AlreadyExists,
InsufficientPermissions,
InternalFailure,
}

impl std::fmt::Display for ListenerCreateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::write!(f, "{}::{:?}", std::stringify!(Self), self)
}
}

impl std::error::Error for ListenerCreateError {}

/// The default suffix of every event
pub const DEFAULT_SUFFIX: FileName = unsafe { FileName::new_unchecked(b".event") };

Expand Down
Loading
Loading