tauri_plugin_keygen_rs2/
error.rs1use keygen_rs::errors::{Error as KeygenError, ErrorMeta};
2use serde::Serialize;
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum Error {
7 #[error(transparent)]
8 IoError(#[from] std::io::Error),
9
10 #[error("Path resolve error: {0}")]
11 PathResolveError(String),
12
13 #[error("Keygen error: {0}")]
14 KeygenError(#[from] KeygenError),
15
16 #[error("No license found")]
17 NoLicenseError,
18
19 #[error("No machine found")]
20 NoMachineError,
21}
22
23#[derive(Debug, Serialize)]
24pub struct InvokeError {
25 pub code: String,
26 pub detail: String,
27}
28
29impl From<Error> for InvokeError {
30 fn from(value: Error) -> Self {
31 match value {
32 Error::KeygenError(err) => Self {
33 code: err.code(),
34 detail: err.detail(),
35 },
36 Error::NoLicenseError => Self {
37 code: "NO LICENSE".into(),
38 detail: "Can't activate a machine. Current app state has no license. Call validate(key) first.".into(),
39 },
40 err => {
41 let msg = match err {
42 Error::IoError(err) => err.to_string(),
43 Error::PathResolveError(msg) => msg,
44 _ => "Unknown error".into(),
45 };
46 Self {
47 code: "ERROR".into(),
48 detail: msg,
49 }
50 }
51 }
52 }
53}