Skip to main content

global_hotkey/
error.rs

1// Copyright 2022-2022 Tauri Programme within The Commons Conservancy
2// SPDX-License-Identifier: Apache-2.0
3// SPDX-License-Identifier: MIT
4
5use thiserror::Error;
6
7use crate::hotkey::HotKey;
8
9/// Errors returned by tray-icon.
10#[non_exhaustive]
11#[derive(Error, Debug)]
12pub enum Error {
13    #[error(transparent)]
14    OsError(#[from] std::io::Error),
15    #[error("{0}")]
16    HotKeyParseError(String),
17    #[error("Couldn't recognize \"{0}\" as a valid HotKey Code, if you feel like it should be, please report this to https://github.com/tauri-apps/global-hotkey")]
18    UnrecognizedHotKeyCode(String),
19    #[error("Unexpected empty token while parsing hotkey: \"{0}\"")]
20    EmptyHotKeyToken(String),
21    #[error("Unexpected hotkey string format: \"{0}\", a hotkey should have the modifiers first and only contain one main key")]
22    UnexpectedHotKeyFormat(String),
23    #[error("Unable to register hotkey: {0}")]
24    FailedToRegister(String),
25    #[error("Failed to unregister hotkey: {0:?}")]
26    FailedToUnRegister(HotKey),
27    #[error("HotKey already registered: {0:?}")]
28    AlreadyRegistered(HotKey),
29    #[error("Failed to watch media key event")]
30    FailedToWatchMediaKeyEvent,
31}
32
33/// Convenient type alias of Result type for tray-icon.
34pub type Result<T> = std::result::Result<T, Error>;