aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-14 17:44:40 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-14 17:44:40 -0500
commitae7718447d24ea0517e7154873c2b55fdd89538d (patch)
treeb51390fdd22940624ad84dfd2f1d82f0480f4284 /src
parent826f85eeed936137a0535a217df03e0fa7bc84f7 (diff)
downloadpty-process-ae7718447d24ea0517e7154873c2b55fdd89538d.tar.gz
pty-process-ae7718447d24ea0517e7154873c2b55fdd89538d.zip
drop thiserror
Diffstat (limited to 'src')
-rw-r--r--src/error.rs65
1 files changed, 50 insertions, 15 deletions
diff --git a/src/error.rs b/src/error.rs
index b4ca3d5..597d692 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,33 +1,68 @@
/// Error type for this crate
-#[derive(thiserror::Error, Debug)]
+#[derive(Debug)]
pub enum Error {
/// error making pty async
- #[error("error making pty async")]
- AsyncPty(#[source] std::io::Error),
+ AsyncPty(std::io::Error),
/// error making pty async
- #[error("error making pty async")]
- AsyncPtyNix(#[source] nix::Error),
+ AsyncPtyNix(nix::Error),
/// error creating pty
- #[error("error creating pty")]
- CreatePty(#[source] nix::Error),
+ CreatePty(nix::Error),
/// error opening pts at \<path\>
- #[error("error opening pts at {1}")]
- OpenPts(#[source] std::io::Error, std::path::PathBuf),
+ OpenPts(std::io::Error, std::path::PathBuf),
/// error setting terminal size
- #[error("error setting terminal size")]
- SetTermSize(#[source] nix::Error),
+ SetTermSize(nix::Error),
/// error spawning subprocess
- #[error("error spawning subprocess")]
- Spawn(#[source] std::io::Error),
+ Spawn(std::io::Error),
/// error spawning subprocess
- #[error("error spawning subprocess")]
- SpawnNix(#[source] nix::Error),
+ SpawnNix(nix::Error),
+}
+
+impl std::fmt::Display for Error {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self {
+ Self::AsyncPty(e) => {
+ write!(f, "error making pty async: {}", e)
+ }
+ Self::AsyncPtyNix(e) => {
+ write!(f, "error making pty async: {}", e)
+ }
+ Self::CreatePty(e) => {
+ write!(f, "error creating pty: {}", e)
+ }
+ Self::OpenPts(e, path) => {
+ write!(f, "error opening pts at {}: {}", path.display(), e)
+ }
+ Self::SetTermSize(e) => {
+ write!(f, "error setting terminal size: {}", e)
+ }
+ Self::Spawn(e) => {
+ write!(f, "error spawning subprocess: {}", e)
+ }
+ Self::SpawnNix(e) => {
+ write!(f, "error spawning subprocess: {}", e)
+ }
+ }
+ }
+}
+
+impl std::error::Error for Error {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ match self {
+ Self::AsyncPty(e) | Self::Spawn(e) | Self::OpenPts(e, _) => {
+ Some(e)
+ }
+ Self::AsyncPtyNix(e) | Self::SpawnNix(e) | Self::CreatePty(e) => {
+ Some(e)
+ }
+ Self::SetTermSize(e) => Some(e),
+ }
+ }
}
/// Convenience wrapper for `Result`s using [`Error`](Error)