Skip to main content

ohos_arkui_input_binding/
error.rs

1use ohos_arkui_input_sys::*;
2use ohos_enum_derive::EnumFrom;
3
4#[derive(Debug, Clone)]
5pub enum ArkUIInputError {
6    InternalError(i32),
7    DeviceTypeNotSupported(String, u32),
8}
9
10impl std::fmt::Display for ArkUIInputError {
11    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12        match self {
13            ArkUIInputError::InternalError(err) => write!(f, "Internal error: {}", err),
14            ArkUIInputError::DeviceTypeNotSupported(api, device_type) => {
15                write!(
16                    f,
17                    "You'r trying to use {} api, current device type not supported: {}",
18                    api, device_type
19                )
20            }
21        }
22    }
23}
24
25impl std::error::Error for ArkUIInputError {}
26
27#[derive(Debug, EnumFrom)]
28#[config(ArkUI_ErrorCode, "ArkUI_ErrorCode_ARKUI_ERROR_CODE_")]
29pub enum ArkUIErrorCode {
30    ParamInvalid,
31    AttributeOrEventNotSupported,
32    #[suffix("ARKTS_NODE_NOT_SUPPORTED")]
33    ArkTSNodeNotSupported,
34    AdapterNotBound,
35    AdapterExist,
36    ChildNodeExist,
37    NodeEventParamIndexOutOfRange,
38    NodeEventParamInvalid,
39    NodeIndexInvalid,
40    BufferSizeError,
41    NonScrollableContainer,
42    BufferSizeNotEnough,
43}
44
45impl AsRef<str> for ArkUIErrorCode {
46    fn as_ref(&self) -> &str {
47        match self {
48            ArkUIErrorCode::AdapterExist => "AdapterExist",
49            ArkUIErrorCode::AdapterNotBound => "AdapterNotBound",
50            ArkUIErrorCode::ArkTSNodeNotSupported => "ArkTSNodeNotSupported",
51            ArkUIErrorCode::AttributeOrEventNotSupported => "AttributeOrEventNotSupported",
52            ArkUIErrorCode::BufferSizeError => "BufferSizeError",
53            ArkUIErrorCode::BufferSizeNotEnough => "BufferSizeNotEnough",
54            ArkUIErrorCode::ChildNodeExist => "ChildNodeExist",
55            ArkUIErrorCode::NonScrollableContainer => "NonScrollableContainer",
56            ArkUIErrorCode::NodeEventParamIndexOutOfRange => "NodeEventParamIndexOutOfRange",
57            ArkUIErrorCode::NodeEventParamInvalid => "NodeEventParamInvalid",
58            ArkUIErrorCode::NodeIndexInvalid => "NodeIndexInvalid",
59            ArkUIErrorCode::ParamInvalid => "ParamInvalid",
60        }
61    }
62}