Skip to content

Commit

Permalink
add better error messages for iceoryx2 service open/create errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dmackdev committed Dec 4, 2024
1 parent 64dcc88 commit 7924524
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use comrak::Arena;
use directories::ProjectDirs;
use iceoryx2::{
node::NodeBuilder,
service::{builder::publish_subscribe::Builder, ipc::Service},
service::{
builder::publish_subscribe::{Builder, PublishSubscribeCreateError, PublishSubscribeOpenError},
ipc::Service,
},
};
use presenterm::{
CommandSource, Config, Exporter, GraphicsMode, HighlightThemeSet, ImagePrinter, ImageProtocol, ImageRegistry,
Expand All @@ -30,6 +33,34 @@ pub enum SpeakerNotesMode {
Receiver,
}

#[derive(thiserror::Error, Debug)]
enum IpcServiceError {
#[error("no presenterm process in publisher mode running for presentation")]
ServiceOpenError,
#[error("existing presenterm process in publisher mode already running for presentation")]
ServiceCreateError,
#[error("{0}")]
Other(String),
}

impl From<PublishSubscribeOpenError> for IpcServiceError {
fn from(value: PublishSubscribeOpenError) -> Self {
match value {
PublishSubscribeOpenError::DoesNotExist => Self::ServiceOpenError,
_ => Self::Other(value.to_string()),
}
}
}

impl From<PublishSubscribeCreateError> for IpcServiceError {
fn from(value: PublishSubscribeCreateError) -> Self {
match value {
PublishSubscribeCreateError::AlreadyExists => Self::ServiceCreateError,
_ => Self::Other(value.to_string()),
}
}
}

/// Run slideshows from your terminal.
#[derive(Parser)]
#[command()]
Expand Down Expand Up @@ -309,7 +340,11 @@ fn run(mut cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
}
} else {
let speaker_notes_event_receiver = if let Some(SpeakerNotesMode::Receiver) = cli.speaker_notes_mode {
let receiver = create_speaker_notes_service_builder(&path)?.open()?.subscriber_builder().create()?;
let receiver = create_speaker_notes_service_builder(&path)?
.open()
.map_err(|err| Cli::command().error(ErrorKind::InvalidValue, IpcServiceError::from(err)))?
.subscriber_builder()
.create()?;
Some(receiver)
} else {
None
Expand All @@ -318,7 +353,11 @@ fn run(mut cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
options.print_modal_background = matches!(graphics_mode, GraphicsMode::Kitty { .. });

let speaker_notes_event_publisher = if let Some(SpeakerNotesMode::Publisher) = cli.speaker_notes_mode {
let publisher = create_speaker_notes_service_builder(&path)?.create()?.publisher_builder().create()?;
let publisher = create_speaker_notes_service_builder(&path)?
.create()
.map_err(|err| Cli::command().error(ErrorKind::InvalidValue, IpcServiceError::from(err)))?
.publisher_builder()
.create()?;
Some(publisher)
} else {
None
Expand Down

0 comments on commit 7924524

Please sign in to comment.