generated from ElnuDev/rust-project
parent
9009ae9e24
commit
2c72d5fc15
@ -1,22 +1,18 @@
|
||||
use derive_more::From;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use thiserror::Error;
|
||||
use wasm_bindgen::JsValue;
|
||||
|
||||
#[derive(From, IntoStaticStr)]
|
||||
use super::JsError;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum FetchFileError {
|
||||
#[strum(serialize = "Failed to fetch file")]
|
||||
Request(JsValue),
|
||||
#[strum(serialize = "Failed to read fetched file to string")]
|
||||
#[error("Failed to fetch file")]
|
||||
Request(#[from] JsError),
|
||||
#[error("Failed to read fetched file to string")]
|
||||
ReadToString,
|
||||
}
|
||||
|
||||
impl ToString for FetchFileError {
|
||||
fn to_string(&self) -> String {
|
||||
use FetchFileError::*;
|
||||
match self {
|
||||
Request(error) => error.as_string(),
|
||||
_ => None,
|
||||
}
|
||||
.unwrap_or_else(|| "".to_string())
|
||||
impl From<JsValue> for FetchFileError {
|
||||
fn from(value: JsValue) -> Self {
|
||||
Self::Request(value.into())
|
||||
}
|
||||
}
|
@ -1,38 +1,13 @@
|
||||
use derive_more::From;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::FetchFileError;
|
||||
|
||||
#[derive(From, IntoStaticStr)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum FetchKleError {
|
||||
#[strum(
|
||||
serialize = "Invalid source. Must be KLE layout, gist URL, gist ID, or direct URL to JSON file"
|
||||
)]
|
||||
#[error("Invalid source. Must be KLE layout, gist URL, gist ID, or direct URL to JSON file")]
|
||||
InvalidSource,
|
||||
#[strum(serialize = "Failed to fetch file")]
|
||||
FetchFile(FetchFileError),
|
||||
#[strum(serialize = "Failed to parse KLE JSON")]
|
||||
Serde(serde_json::Error),
|
||||
}
|
||||
|
||||
impl ToString for FetchKleError {
|
||||
fn to_string(&self) -> String {
|
||||
use FetchKleError::*;
|
||||
match self {
|
||||
FetchFile(error) => Some(match error {
|
||||
FetchFileError::Request(error_info) => {
|
||||
let mut full_error = <&FetchFileError as Into<&str>>::into(error).to_string();
|
||||
if let Some(error_info) = error_info.as_string() {
|
||||
full_error.push_str(": ");
|
||||
full_error.push_str(&error_info);
|
||||
}
|
||||
full_error
|
||||
}
|
||||
FetchFileError::ReadToString => error.to_string(),
|
||||
}),
|
||||
Serde(error) => Some(error.to_string()),
|
||||
_ => None,
|
||||
}
|
||||
.unwrap_or_else(|| "".to_string())
|
||||
}
|
||||
#[error("Failed to fetch file")]
|
||||
FetchFile(#[from] FetchFileError),
|
||||
#[error("Failed to parse KLE JSON")]
|
||||
Serde(#[from] serde_json::Error),
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
use thiserror::Error;
|
||||
use wasm_bindgen::JsValue;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
#[error("Error reported from JavaScript")]
|
||||
pub struct JsError(JsValue);
|
||||
|
||||
impl From<JsValue> for JsError {
|
||||
fn from(value: JsValue) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
@ -1,24 +1,20 @@
|
||||
use derive_more::From;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use thiserror::Error;
|
||||
use wasm_bindgen::JsValue;
|
||||
|
||||
#[derive(From, IntoStaticStr)]
|
||||
use super::JsError;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ReadFileError {
|
||||
#[strum(serialize = "No file chosen")]
|
||||
#[error("No file chosen")]
|
||||
NoFile,
|
||||
#[strum(serialize = "Failed to open file")]
|
||||
TextAwait(JsValue),
|
||||
#[strum(serialize = "Failed to parse file to string")]
|
||||
#[error("Failed to open file")]
|
||||
TextAwait(#[from] JsError),
|
||||
#[error("Failed to parse file to string")]
|
||||
ParseToString,
|
||||
}
|
||||
|
||||
impl ToString for ReadFileError {
|
||||
fn to_string(&self) -> String {
|
||||
use ReadFileError::*;
|
||||
match self {
|
||||
TextAwait(error) => error.as_string(),
|
||||
_ => None,
|
||||
}
|
||||
.unwrap_or_else(|| "".to_string())
|
||||
impl From<JsValue> for ReadFileError {
|
||||
fn from(value: JsValue) -> Self {
|
||||
Self::TextAwait(value.into())
|
||||
}
|
||||
}
|
@ -1,21 +1,11 @@
|
||||
use derive_more::From;
|
||||
use strum_macros::IntoStaticStr;
|
||||
use thiserror::Error;
|
||||
|
||||
use super::ReadFileError;
|
||||
|
||||
#[derive(From, IntoStaticStr)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ReadKleError {
|
||||
ReadFile(ReadFileError),
|
||||
#[strum(serialize = "Failed to parse KLE JSON")]
|
||||
Serde(serde_json::Error),
|
||||
}
|
||||
|
||||
impl ToString for ReadKleError {
|
||||
fn to_string(&self) -> String {
|
||||
use ReadKleError::*;
|
||||
match self {
|
||||
ReadFile(error) => error.to_string(),
|
||||
Serde(error) => error.to_string(),
|
||||
}
|
||||
}
|
||||
#[error("Failed to read file")]
|
||||
ReadFile(#[from] ReadFileError),
|
||||
#[error("Failed to parse KLE JSON")]
|
||||
Serde(#[from] serde_json::Error),
|
||||
}
|
Loading…
Reference in new issue