tauri_plugin_brightness/error.rs
1// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5use serde::{Serialize, Serializer};
6
7/// Alias for a [`Result`](std::result::Result) with the error type [`Error`].
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Errors returned by the plugin commands.
11///
12/// Every variant serializes to its [`Display`](std::fmt::Display) text, so a
13/// JavaScript caller receives a readable string in the rejected promise.
14#[derive(Debug, thiserror::Error)]
15#[non_exhaustive]
16pub enum Error {
17 /// A brightness backend failed.
18 #[error(transparent)]
19 Brightness(#[from] tauri_brightness_core::Error),
20
21 /// A Tauri API failed.
22 #[error(transparent)]
23 Tauri(#[from] tauri::Error),
24}
25
26impl Serialize for Error {
27 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
28 where
29 S: Serializer,
30 {
31 serializer.serialize_str(self.to_string().as_ref())
32 }
33}