ironflow_runtime/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum RuntimeError {
8 #[error("failed to bind address: {0}")]
10 Bind(std::io::Error),
11 #[error("http server error: {0}")]
13 Serve(std::io::Error),
14}
15
16#[cfg(test)]
17mod tests {
18 use super::*;
19
20 #[test]
21 fn bind_error_display() {
22 let err = RuntimeError::Bind(std::io::Error::new(
23 std::io::ErrorKind::AddrInUse,
24 "port taken",
25 ));
26 assert_eq!(err.to_string(), "failed to bind address: port taken");
27 }
28
29 #[test]
30 fn serve_error_display() {
31 let err = RuntimeError::Serve(std::io::Error::other("fatal"));
32 assert_eq!(err.to_string(), "http server error: fatal");
33 }
34
35 #[test]
36 fn runtime_error_implements_std_error() {
37 let err = RuntimeError::Bind(std::io::Error::other("x"));
38 let _: &dyn std::error::Error = &err;
39 }
40
41 #[test]
42 fn bind_error_debug() {
43 let err = RuntimeError::Bind(std::io::Error::other("test"));
44 let debug_str = format!("{:?}", err);
45 assert!(debug_str.contains("Bind"));
46 }
47
48 #[test]
49 fn serve_error_debug() {
50 let err = RuntimeError::Serve(std::io::Error::other("test"));
51 let debug_str = format!("{:?}", err);
52 assert!(debug_str.contains("Serve"));
53 }
54
55 #[test]
56 fn error_variants_are_error() {
57 use std::error::Error;
58
59 let err_bind: Box<dyn Error> = Box::new(RuntimeError::Bind(std::io::Error::other("x")));
60 let err_serve: Box<dyn Error> = Box::new(RuntimeError::Serve(std::io::Error::other("x")));
61
62 assert!(!err_bind.to_string().is_empty());
63 assert!(!err_serve.to_string().is_empty());
64 }
65}