common_mem_prof/jemalloc/
error.rs1use std::any::Any;
16use std::path::PathBuf;
17
18use common_error::ext::{BoxedError, ErrorExt};
19use common_error::status_code::StatusCode;
20use common_macro::stack_trace_debug;
21use snafu::{Location, Snafu};
22
23#[derive(Snafu)]
24#[snafu(visibility(pub))]
25#[stack_trace_debug]
26pub enum Error {
27 #[snafu(display("Failed to read OPT_PROF"))]
28 ReadOptProf {
29 #[snafu(source)]
30 error: tikv_jemalloc_ctl::Error,
31 },
32
33 #[snafu(display("Memory profiling is not enabled"))]
34 ProfilingNotEnabled,
35
36 #[snafu(display("Failed to build temp file from given path: {:?}", path))]
37 BuildTempPath {
38 path: PathBuf,
39 #[snafu(implicit)]
40 location: Location,
41 },
42
43 #[snafu(display("Failed to open temp file: {}", path))]
44 OpenTempFile {
45 path: String,
46 #[snafu(source)]
47 error: std::io::Error,
48 },
49
50 #[snafu(display("Failed to dump profiling data to temp file: {:?}", path))]
51 DumpProfileData {
52 path: PathBuf,
53 #[snafu(source)]
54 error: tikv_jemalloc_ctl::Error,
55 },
56}
57
58impl ErrorExt for Error {
59 fn status_code(&self) -> StatusCode {
60 match self {
61 Error::ReadOptProf { .. } => StatusCode::Internal,
62 Error::ProfilingNotEnabled => StatusCode::InvalidArguments,
63 Error::BuildTempPath { .. } => StatusCode::Internal,
64 Error::OpenTempFile { .. } => StatusCode::StorageUnavailable,
65 Error::DumpProfileData { .. } => StatusCode::StorageUnavailable,
66 }
67 }
68
69 fn as_any(&self) -> &dyn Any {
70 self
71 }
72}
73
74impl From<Error> for crate::error::Error {
75 fn from(e: Error) -> Self {
76 Self::Internal {
77 source: BoxedError::new(e),
78 }
79 }
80}