| 1 | //! Custom types for tracing errors. |
| 2 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/; |
| 3 | |
| 4 | use craterust-analyzer cargo pete 0.13.0 crate/::ptracerrust-analyzer cargo pete 0.13.0 ptracer/::Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#; |
| 5 | |
| 6 | /// Alias for `Result<T, self::Error>`. |
| 7 | pub type Resultrust-analyzer cargo pete 0.13.0 error/Result#<T> = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, Errorrust-analyzer cargo pete 0.13.0 error/Error#>; |
| 8 | |
| 9 | /// A tracing error. |
| 10 | /// |
| 11 | /// Tracees are controlled by the tracer, but still impacted by their environment. In |
| 12 | /// particular, they may die unexpectedly while in ptrace-stop. Some errors can be due to |
| 13 | /// this, and will not necessarily be followed by a `wait()` status reporting the tracee's |
| 14 | /// death. This should be observed as an error with a `source` of |
| 15 | /// `nix::Error::Sys(Errno::ESRCH)`. |
| 16 | /// |
| 17 | /// For this reason, tracing programs may need to handle an `ESRCH` error on any |
| 18 | /// `ptrace()` operation. |
| 19 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(thiserrorrust-analyzer cargo thiserror 2.0.16 crate/::Errorrust-analyzer cargo thiserror-impl 2.0.16 Error:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 20 | pub enum Errorrust-analyzer cargo pete 0.13.0 error/Error# { |
| 21 | #[errorrust-analyzer cargo thiserror-impl 2.0.16 error:("Could not attach to tracee = {pid}")] |
| 22 | Attachrust-analyzer cargo pete 0.13.0 error/Error#Attach# { |
| 23 | pidrust-analyzer cargo pete 0.13.0 error/Error#Attach#pid.: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#, |
| 24 | sourcerust-analyzer cargo pete 0.13.0 error/Error#Attach#source.: nixrust-analyzer cargo nix 0.30.1 crate/::Errorrust-analyzer cargo nix 0.30.1 Error#, |
| 25 | }, |
| 26 | |
| 27 | #[errorrust-analyzer cargo thiserror-impl 2.0.16 error:("Tracee died while in ptrace-stop")] |
| 28 | TraceeDiedrust-analyzer cargo pete 0.13.0 error/Error#TraceeDied# { pidrust-analyzer cargo pete 0.13.0 error/Error#TraceeDied#pid.: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#, sourcerust-analyzer cargo pete 0.13.0 error/Error#TraceeDied#source.: nixrust-analyzer cargo nix 0.30.1 crate/::Errorrust-analyzer cargo nix 0.30.1 Error# }, |
| 29 | |
| 30 | #[errorrust-analyzer cargo thiserror-impl 2.0.16 error:("Input/output error")] |
| 31 | IOrust-analyzer cargo pete 0.13.0 error/Error#IO#(#[from] iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#), |
| 32 | |
| 33 | #[errorrust-analyzer cargo thiserror-impl 2.0.16 error:("OS error")] |
| 34 | OSrust-analyzer cargo pete 0.13.0 error/Error#OS#(#[from] nixrust-analyzer cargo nix 0.30.1 crate/::Errorrust-analyzer cargo nix 0.30.1 Error#), |
| 35 | |
| 36 | #[errorrust-analyzer cargo thiserror-impl 2.0.16 error:("Internal error: {0}. Please open an issue at https://github.com/ranweiler/pete/issues")] |
| 37 | Internalrust-analyzer cargo pete 0.13.0 error/Error#Internal#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#), |
| 38 | } |
| 39 | |
| 40 | impl Errorrust-analyzer cargo pete 0.13.0 error/Error# { |
| 41 | pub fn tracee_diedrust-analyzer cargo pete 0.13.0 error/impl#[Error]tracee_died().(&self) -> bool { |
| 42 | if let Errorrust-analyzer cargo pete 0.13.0 error/Error#::TraceeDiedrust-analyzer cargo pete 0.13.0 error/Error#TraceeDied# { .. } = self { |
| 43 | true |
| 44 | } else { |
| 45 | false |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | macro_rules! internal_errorrust-analyzer cargo pete 0.13.0 error/internal_error! { |
| 51 | ($ctx: expr) => {{ |
| 52 | return Err($crate::error::Error::Internal($ctx.into())); |
| 53 | }} |
| 54 | } |
| 55 | |
| 56 | pub(craterust-analyzer cargo pete 0.13.0 crate/) trait ResultExtrust-analyzer cargo pete 0.13.0 error/ResultExt#<T> { |
| 57 | /// Maps an `ESRCH` error result to `Error::TraceeDied`. |
| 58 | /// |
| 59 | /// Should only be called on results of `ptrace()` operations on valid tracees known |
| 60 | /// to be in ptrace-stop. |
| 61 | fn died_if_esrchrust-analyzer cargo pete 0.13.0 error/ResultExt#died_if_esrch().(self, pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<T>; |
| 62 | } |
| 63 | |
| 64 | impl<T> ResultExtrust-analyzer cargo pete 0.13.0 error/ResultExt#<T> for stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<T, nixrust-analyzer cargo nix 0.30.1 crate/::Errorrust-analyzer cargo nix 0.30.1 Error#> { |
| 65 | fn died_if_esrchrust-analyzer cargo pete 0.13.0 error/impl#[`std::result::Result<T, nix::errno::Errno>`][`ResultExt<T>`]died_if_esrch().(self, pid: Pidrust-analyzer cargo nix 0.30.1 unistd/Pid#) -> Resultrust-analyzer cargo pete 0.13.0 error/Result#<T> { |
| 66 | use nixrust-analyzer cargo nix 0.30.1 crate/::errnorust-analyzer cargo nix 0.30.1 errno/::Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#; |
| 67 | |
| 68 | self.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|err| { |
| 69 | if err rust-analyzer cargo nix 0.30.1 errno/consts/impl#[Errno][`PartialEq<Self>`]eq().==rust-analyzer cargo nix 0.30.1 errno/consts/impl#[Errno][`PartialEq<Self>`]eq(). rust-analyzer cargo nix 0.30.1 errno/consts/impl#[Errno][`PartialEq<Self>`]eq().Errnorust-analyzer cargo nix 0.30.1 errno/consts/Errno#::ESRCHrust-analyzer cargo nix 0.30.1 errno/consts/Errno#ESRCH# { |
| 70 | Errorrust-analyzer cargo pete 0.13.0 error/Error#::TraceeDiedrust-analyzer cargo pete 0.13.0 error/Error#TraceeDied# { pidrust-analyzer cargo pete 0.13.0 error/Error#TraceeDied#pid., sourcerust-analyzer cargo pete 0.13.0 error/Error#TraceeDied#source.: err } |
| 71 | } else { |
| 72 | err.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 73 | } |
| 74 | }) |
| 75 | } |
| 76 | } |