Skip to main content

async_ebpf/
error.rs

1use std::sync::Arc;
2
3use elf::{relocation::Rel, ParseError};
4use thiserror::Error as ThisError;
5
6#[derive(ThisError, Debug, Clone)]
7#[error("ebpf runtime error: {0}")]
8/// Public error wrapper for runtime failures.
9pub struct Error(pub(crate) RuntimeError);
10
11#[derive(ThisError, Debug, Clone)]
12pub(crate) enum RuntimeError {
13  #[error("invalid argument: {0}")]
14  InvalidArgument(&'static str),
15
16  #[error("platform error: {0}")]
17  PlatformError(&'static str),
18
19  #[error("helper returned error: {0}")]
20  HelperError(&'static str),
21
22  #[error("helper returned error during async invocation: {0}")]
23  AsyncHelperError(&'static str),
24
25  #[error("linker returned error: {0}")]
26  Linker(LinkerError),
27
28  #[error("memory fault at virtual address {0:#x}")]
29  MemoryFault(usize),
30}
31
32#[derive(ThisError, Debug, Clone)]
33pub(crate) enum LinkerError {
34  #[error("invalid elf image: {0}")]
35  InvalidElf(&'static str),
36
37  #[error("bad relocation: {0} ({1:?})")]
38  Reloc(String, Rel),
39
40  #[error("program rejected: {0}")]
41  Rejected(String),
42
43  #[error("elf parse failed: {0}")]
44  Parse(Arc<ParseError>),
45}
46
47impl From<ParseError> for LinkerError {
48  fn from(e: ParseError) -> Self {
49    Self::Parse(Arc::new(e))
50  }
51}