Skip to main content

nokhwa_core/
error.rs

1/*
2 * Copyright 2022 l1npengtul <l1npengtul@protonmail.com> / The Nokhwa Contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use crate::types::{ApiBackend, FrameFormat};
18use thiserror::Error;
19
20/// All errors in `nokhwa`.
21#[allow(clippy::module_name_repetitions)]
22#[derive(Error, Debug, Clone)]
23pub enum NokhwaError {
24    #[error("Unitialized Camera. Call `init()` first!")]
25    UnitializedError,
26    #[error("Could not initialize {backend}: {error}")]
27    InitializeError { backend: ApiBackend, error: String },
28    #[error("Could not shutdown {backend}: {error}")]
29    ShutdownError { backend: ApiBackend, error: String },
30    #[error("Error: {0}")]
31    GeneralError(String),
32    #[error("Could not generate required structure {structure}: {error}")]
33    StructureError { structure: String, error: String },
34    #[error("Could not open device {0}: {1}")]
35    OpenDeviceError(String, String),
36    #[error("Could not get device property {property}: {error}")]
37    GetPropertyError { property: String, error: String },
38    #[error("Could not set device property {property} with value {value}: {error}")]
39    SetPropertyError {
40        property: String,
41        value: String,
42        error: String,
43    },
44    #[error("Could not open device stream: {0}")]
45    OpenStreamError(String),
46    #[error("Could not capture frame: {0}")]
47    ReadFrameError(String),
48    #[error("Could not process frame {src} to {destination}: {error}")]
49    ProcessFrameError {
50        src: FrameFormat,
51        destination: String,
52        error: String,
53    },
54    #[error("Could not stop stream: {0}")]
55    StreamShutdownError(String),
56    #[error("This operation is not supported by backend {0}.")]
57    UnsupportedOperationError(ApiBackend),
58    #[error("This operation is not implemented yet: {0}")]
59    NotImplementedError(String),
60}