self_meter/
error.rs

1use std::io;
2use std::num::ParseIntError;
3
4use Pid;
5
6
7quick_error! {
8    #[derive(Debug)]
9    /// Error reading or parsing /proc/uptime
10    pub enum UptimeError {
11        Io(err: io::Error) {
12            description("IO error")
13            display("{}", err)
14            from()
15        }
16        ParseInt(e: ParseIntError) {
17            description("error parsing int")
18            display("error parsing int: {}", e)
19            from()
20        }
21        BadFormat {
22            description("bad format")
23        }
24    }
25}
26
27quick_error! {
28    #[derive(Debug)]
29    /// Error reading or parsing /proc/self/stat or /proc/self/task/<TID>/stat
30    pub enum StatError {
31        Io(err: io::Error) {
32            description("IO error")
33            display("{}", err)
34            from()
35        }
36        ParseInt(e: ParseIntError) {
37            description("error parsing int")
38            display("error parsing int: {}", e)
39            from()
40        }
41        BadFormat {
42            description("bad format")
43        }
44    }
45}
46
47quick_error! {
48    #[derive(Debug)]
49    /// Error reading or parsing /proc/self/io
50    pub enum IoStatError {
51        Io(err: io::Error) {
52            description("IO error")
53            display("{}", err)
54            from()
55        }
56        ParseInt(e: ParseIntError) {
57            description("error parsing int")
58            display("error parsing int: {}", e)
59            from()
60        }
61    }
62}
63
64quick_error! {
65    #[derive(Debug)]
66    /// Error reading or parsing /proc/self/status
67    pub enum StatusError {
68        Io(err: io::Error) {
69            description("IO error")
70            display("{}", err)
71            from()
72        }
73        ParseInt(e: ParseIntError) {
74            description("error parsing int")
75            display("error parsing int: {}", e)
76            from()
77        }
78        BadUnit {
79            description("bad unit in memory data")
80        }
81        BadFormat {
82            description("bad format")
83        }
84    }
85}
86
87
88quick_error! {
89    #[derive(Debug)]
90    /// Error scanning process info in /proc
91    pub enum Error {
92        /// Error reading uptime value
93        Uptime(err: UptimeError) {
94            description("Error reading /proc/uptime")
95            display("Error reading /proc/uptime: {}", err)
96            from()
97        }
98        /// Error reading /proc/self/status
99        Status(err: StatusError) {
100            description("Error reading /proc/self/status")
101            display("Error reading /proc/self/status: {}", err)
102            from()
103        }
104        /// Error reading /proc/self/stat
105        Stat(err: StatError) {
106            description("Error reading /proc/self/stat")
107            display("Error reading /proc/self/stat: {}", err)
108        }
109        /// Error reading thread status
110        ThreadStat(tid: Pid, err: StatError) {
111            description("Error reading /proc/self/task/<TID>/stat")
112            display("Error reading /proc/self/task/{}/stat: {}", tid, err)
113        }
114        /// Error reading IO stats
115        IoStat(err: IoStatError) {
116            description("Error reading /proc/self/io")
117            display("Error reading /proc/self/io: {}", err)
118            from()
119        }
120    }
121}