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