-
-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add structured IPC error types with miette diagnostics #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ use crate::Result; | |||||||||
| use crate::daemon::{Daemon, RunOptions}; | ||||||||||
| use crate::env; | ||||||||||
| use interprocess::local_socket::{GenericFilePath, Name, ToFsName}; | ||||||||||
| use miette::IntoDiagnostic; | ||||||||||
| use miette::{Context, IntoDiagnostic}; | ||||||||||
| use std::path::PathBuf; | ||||||||||
|
|
||||||||||
| pub(crate) mod client; | ||||||||||
|
|
@@ -60,22 +60,29 @@ fn fs_name(name: &str) -> Result<Name<'_>> { | |||||||||
| } | ||||||||||
|
|
||||||||||
| fn serialize<T: serde::Serialize>(msg: &T) -> Result<Vec<u8>> { | ||||||||||
| let msg = if *env::IPC_JSON { | ||||||||||
| serde_json::to_vec(msg).into_diagnostic()? | ||||||||||
| if *env::IPC_JSON { | ||||||||||
| serde_json::to_vec(msg) | ||||||||||
| .into_diagnostic() | ||||||||||
| .wrap_err("failed to serialize IPC message as JSON") | ||||||||||
| } else { | ||||||||||
| rmp_serde::to_vec(msg).into_diagnostic()? | ||||||||||
| }; | ||||||||||
| Ok(msg) | ||||||||||
| rmp_serde::to_vec(msg) | ||||||||||
| .into_diagnostic() | ||||||||||
| .wrap_err("failed to serialize IPC message as MessagePack") | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| fn deserialize<T: serde::de::DeserializeOwned>(bytes: &[u8]) -> Result<T> { | ||||||||||
| let mut bytes = bytes.to_vec(); | ||||||||||
| bytes.pop(); | ||||||||||
| trace!("msg: {:?}", std::str::from_utf8(&bytes).unwrap_or_default()); | ||||||||||
| let msg = if *env::IPC_JSON { | ||||||||||
| serde_json::from_slice(&bytes).into_diagnostic()? | ||||||||||
| let preview = std::str::from_utf8(&bytes).unwrap_or("<binary>"); | ||||||||||
| trace!("msg: {:?}", preview); | ||||||||||
|
Comment on lines
+77
to
+78
|
||||||||||
| let preview = std::str::from_utf8(&bytes).unwrap_or("<binary>"); | |
| trace!("msg: {:?}", preview); | |
| let decoded_message = std::str::from_utf8(&bytes).unwrap_or("<binary>"); | |
| trace!("msg: {:?}", decoded_message); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help text 'ensure the supervisor is running with: pitchfork supervisor start' is duplicated in the
detailsfield here (line 70-71) and in the fallback case (lines 81-82). Consider extracting this message to a constant to maintain consistency.