kpal_plugin/
errors.rs

1//! Structures that provide error information to clients of the plugin library.
2
3use std::{error::Error, fmt};
4
5pub static ERRORS: [&[u8]; 12] = [
6    // 0 PLUGIN_OK
7    b"Plugin OK\0",
8    // 1 UNDEFINED_ERR
9    b"Undefined error\0",
10    // 2 PLUGIN_INIT_ERR,
11    b"Plugin failed to initialize\0",
12    // 3 ATTRIBUTE_DOES_NOT_EXIST
13    b"Attribute does not exist\0",
14    // 4 ATTRIBUTE_TYPE_MISMATCH
15    b"Attribute types do not match\0",
16    // 5 ATTRIBUTE_IS_NOT_SETTABLE
17    b"Attribute cannot be set\0",
18    // 6 IO_ERR
19    b"IO operation failed\0",
20    // 7 NUMERIC_CONVERSION_ERR
21    b"Could not convert numeric value into a different type\0",
22    // 8 NULL_PTR_ERR
23    b"The plugin encountered a null pointer\0",
24    // 9 CALLBACK_ERR
25    b"The plugin attribute's callback failed\0",
26    // 10 UPDATE_CACHED_VALUE_ERR
27    b"Could not update plugin attribute's cached value\0",
28    // 11 LIFECYCLE_PHASE_ERR
29    b"Unrecognized lifecycle phase\0",
30];
31
32/// An error that is raised when a plugin is assumed to be in its run phase but it has not yet been
33/// initialized.
34///
35/// This error type is provided as a convenience for use in plugin libraries.
36#[derive(Debug)]
37pub struct PluginUninitializedError {}
38
39impl Error for PluginUninitializedError {}
40
41impl fmt::Display for PluginUninitializedError {
42    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43        write!(f, "PluginUninitializederror")
44    }
45}
46
47pub mod error_codes {
48    //! Constants that indicate specific error codes that a plugin can return.
49    use libc::c_int;
50
51    pub const PLUGIN_OK: c_int = 0;
52    pub const UNDEFINED_ERR: c_int = 1;
53    pub const PLUGIN_INIT_ERR: c_int = 2;
54    pub const ATTRIBUTE_DOES_NOT_EXIST: c_int = 3;
55    pub const ATTRIBUTE_TYPE_MISMATCH: c_int = 4;
56    pub const ATTRIBUTE_IS_NOT_SETTABLE: c_int = 5;
57    pub const IO_ERR: c_int = 6;
58    pub const NUMERIC_CONVERSION_ERR: c_int = 7;
59    pub const NULL_PTR_ERR: c_int = 8;
60    pub const CALLBACK_ERR: c_int = 9;
61    pub const UPDATE_CACHED_VALUE_ERR: c_int = 10;
62    pub const LIFECYCLE_PHASE_ERR: c_int = 11;
63}