generated from ElnuDev/rust-project
use thiserror
This commit is contained in:
parent
9009ae9e24
commit
2c72d5fc15
16 changed files with 104 additions and 163 deletions
42
Cargo.lock
generated
42
Cargo.lock
generated
|
@ -410,12 +410,6 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "convert_case"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
|
||||
|
||||
[[package]]
|
||||
name = "convert_case"
|
||||
version = "0.6.0"
|
||||
|
@ -464,19 +458,6 @@ dependencies = [
|
|||
"syn 2.0.28",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_more"
|
||||
version = "0.99.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
|
||||
dependencies = [
|
||||
"convert_case 0.4.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"rustc_version",
|
||||
"syn 1.0.109",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.10.7"
|
||||
|
@ -504,7 +485,7 @@ name = "dyesub"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"askama",
|
||||
"derive_more",
|
||||
"err-derive",
|
||||
"kle-serial",
|
||||
"lazy_static",
|
||||
"serde_json",
|
||||
|
@ -526,7 +507,6 @@ name = "dyesub-tool"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"class_list",
|
||||
"derive_more",
|
||||
"kle-serial",
|
||||
"lazy_static",
|
||||
"leptos",
|
||||
|
@ -534,6 +514,7 @@ dependencies = [
|
|||
"strum",
|
||||
"strum_macros",
|
||||
"svg-units",
|
||||
"thiserror",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
|
@ -1111,7 +1092,7 @@ checksum = "0bdd7a21d20ca21bb12d67d050d4b0ad9973b156bce98f499f8b1789f11959dd"
|
|||
dependencies = [
|
||||
"attribute-derive",
|
||||
"cfg-if",
|
||||
"convert_case 0.6.0",
|
||||
"convert_case",
|
||||
"html-escape",
|
||||
"itertools",
|
||||
"leptos_hot_reload",
|
||||
|
@ -1712,15 +1693,6 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
|
||||
dependencies = [
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.8"
|
||||
|
@ -1767,12 +1739,6 @@ version = "1.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c309e515543e67811222dbc9e3dd7e1056279b782e1dacffe4242b718734fb6"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.183"
|
||||
|
@ -1978,11 +1944,11 @@ dependencies = [
|
|||
name = "svg-units"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"err-derive",
|
||||
"lazy_static",
|
||||
"regex",
|
||||
"strum",
|
||||
"strum_macros",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -6,7 +6,6 @@ edition = "2021"
|
|||
[dependencies]
|
||||
svg-units = { path = "../svg-units" }
|
||||
class_list = "0.1.1"
|
||||
derive_more = "0.99.17"
|
||||
kle-serial = "0.2.2"
|
||||
lazy_static = "1.4.0"
|
||||
leptos = { version = "0.4.8", features = ["csr", "nightly"] }
|
||||
|
@ -15,6 +14,7 @@ strum = "0.25.0"
|
|||
strum_macros = "0.25.2"
|
||||
wasm-bindgen = "0.2.87"
|
||||
wasm-bindgen-futures = "0.4.37"
|
||||
thiserror = "1.0.47"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3.64"
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::error::Error;
|
||||
|
||||
use leptos::{html::Input, *};
|
||||
use web_sys::File;
|
||||
|
||||
|
@ -20,24 +22,15 @@ pub fn KeyboardFromFile(
|
|||
Ok(keyboard) => {
|
||||
set_result_message(Some(ResultMessageData {
|
||||
title: "Success".to_owned(),
|
||||
message: view! { cx,
|
||||
"Loaded KLE layout "<b>{&keyboard.metadata.name}</b>" successfully!"
|
||||
}
|
||||
.into_view(cx),
|
||||
message: format!("Loaded KLE layout <b>{}</b> successfully!", &keyboard.metadata.name),
|
||||
colorway: Colorway::Ok,
|
||||
}));
|
||||
set_keyboard(Some(keyboard));
|
||||
}
|
||||
Err(err) => {
|
||||
set_result_message(Some(ResultMessageData {
|
||||
message: view! { cx,
|
||||
{
|
||||
err.to_string()
|
||||
}
|
||||
}
|
||||
.into_view(cx),
|
||||
title: <ReadKleError as Into<&str>>::into(err).to_string(),
|
||||
colorway: Colorway::Bad,
|
||||
set_result_message(Some({
|
||||
let error: Box<dyn Error> = Box::new(err);
|
||||
error.into()
|
||||
}));
|
||||
file_input().unwrap().set_value("");
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::error::Error;
|
||||
|
||||
use leptos::{html::Input, *};
|
||||
use web_sys::SubmitEvent;
|
||||
|
||||
|
@ -24,24 +26,15 @@ pub fn KeyboardFromWeb(
|
|||
Ok(keyboard) => {
|
||||
set_result_message(Some(ResultMessageData {
|
||||
title: "Success".to_owned(),
|
||||
message: view! { cx,
|
||||
"Loaded KLE layout "<b>{&keyboard.metadata.name}</b>" successfully!"
|
||||
}
|
||||
.into_view(cx),
|
||||
message: format!("Loaded KLE layout <b>{}</b> successfully!", &keyboard.metadata.name),
|
||||
colorway: Colorway::Ok,
|
||||
}));
|
||||
set_keyboard(Some(keyboard));
|
||||
}
|
||||
Err(err) => {
|
||||
set_result_message(Some(ResultMessageData {
|
||||
message: view! { cx,
|
||||
{
|
||||
err.to_string()
|
||||
}
|
||||
}
|
||||
.into_view(cx),
|
||||
title: <FetchKleError as Into<&str>>::into(err).to_string(),
|
||||
colorway: Colorway::Bad,
|
||||
set_result_message(Some({
|
||||
let error: Box<dyn Error> = Box::new(err);
|
||||
error.into()
|
||||
}));
|
||||
input_element().unwrap().set_value("");
|
||||
}
|
||||
|
|
|
@ -1,15 +1,29 @@
|
|||
use class_list::class_list;
|
||||
use leptos::*;
|
||||
use std::error::Error;
|
||||
|
||||
use crate::models::Colorway;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ResultMessageData {
|
||||
pub title: String,
|
||||
pub message: View,
|
||||
pub message: String,
|
||||
pub colorway: Colorway,
|
||||
}
|
||||
|
||||
impl From<Box<dyn Error>> for ResultMessageData {
|
||||
fn from(value: Box<dyn Error>) -> Self {
|
||||
Self {
|
||||
title: value.to_string(),
|
||||
message: value
|
||||
.source()
|
||||
.map(|source| source.to_string())
|
||||
.unwrap_or_else(|| "".to_string()),
|
||||
colorway: Colorway::Bad,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn ResultMessage(cx: Scope, message: ReadSignal<Option<ResultMessageData>>) -> impl IntoView {
|
||||
let (open, set_open) = create_signal(cx, true);
|
||||
|
@ -24,7 +38,7 @@ pub fn ResultMessage(cx: Scope, message: ReadSignal<Option<ResultMessageData>>)
|
|||
<div class=class_list!["box", colorway] style="position: relative">
|
||||
<strong class="block titlebar">{title}</strong>
|
||||
<button class="iconbutton" on:click=move |_| set_open(false) style="position: absolute; bottom: 0.5em; right: 0.5em">"×"</button>
|
||||
<p>{message}</p>
|
||||
<p inner_html=message />
|
||||
</div>
|
||||
})}
|
||||
</Show>
|
||||
|
|
|
@ -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),
|
||||
}
|
12
dyesub-tool/src/error/jserror.rs
Normal file
12
dyesub-tool/src/error/jserror.rs
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -9,3 +9,6 @@ pub use fetchkle::FetchKleError;
|
|||
|
||||
mod readkle;
|
||||
pub use readkle::ReadKleError;
|
||||
|
||||
mod jserror;
|
||||
pub use jserror::JsError;
|
|
@ -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),
|
||||
}
|
|
@ -8,7 +8,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
svg-units = { path = "../svg-units" }
|
||||
askama = "0.12.0"
|
||||
derive_more = "0.99.17"
|
||||
kle-serial = "0.2.2"
|
||||
lazy_static = "1.4.0"
|
||||
serde_json = "1.0.105"
|
||||
err-derive = "0.3.1"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::path::Path;
|
||||
|
||||
use askama::Template;
|
||||
use derive_more::From;
|
||||
use err_derive::Error;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use svg_units::{SVGMeasure, SVGUnit};
|
||||
|
@ -38,11 +38,14 @@ mod filters {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(From, Debug)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
Io(std::io::Error),
|
||||
Template(askama::Error),
|
||||
LayoutParse(serde_json::Error),
|
||||
#[error(display = "I/O error")]
|
||||
Io(#[cause] std::io::Error),
|
||||
#[error(display = "Templating error")]
|
||||
Template(#[cause] askama::Error),
|
||||
#[error(display = "Failed to parse KLE JSON")]
|
||||
LayoutParse(#[cause] serde_json::Error),
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
|
|
@ -66,7 +66,7 @@ Updating `cargoHash`:
|
|||
pname = "dyesub-cli";
|
||||
version = "0.1.0";
|
||||
buildAndTestSubdir = "dyesub-cli";
|
||||
cargoHash = "sha256-6nbUjVjroFp2KZEk0wDisCUw2e9GtVxFgsGZm8xEe2A=";
|
||||
cargoHash = "sha256-3i+msqsUkNtVAx1eOZFftYRCDg+nVFZDhbdOIC8xvxM=";
|
||||
meta = meta // {
|
||||
description = "A tool for generating dye sublimation transfer sheet SVGs for Japanese thumb shift 拇指シフト keycaps.";
|
||||
};
|
||||
|
|
|
@ -6,8 +6,8 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
err-derive = "0.3.1"
|
||||
lazy_static = "1.4.0"
|
||||
regex = "1.9.3"
|
||||
strum = "0.25.0"
|
||||
strum_macros = "0.25.2"
|
||||
thiserror = "1.0.47"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use super::SVGUnit;
|
||||
use err_derive::Error;
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use thiserror::Error;
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::num::ParseFloatError;
|
||||
|
@ -35,13 +35,13 @@ impl SVGMeasure {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum SVGMeasureParseError {
|
||||
#[error(display = "Failed to parse measure number")]
|
||||
ParseMeasure(#[source] ParseFloatError),
|
||||
#[error(display = "Failed to parse measure unit")]
|
||||
ParseUnit(#[source] ParseError),
|
||||
#[error(display = "Invalid measure format")]
|
||||
#[error("Failed to parse measure number")]
|
||||
ParseMeasure(#[from] ParseFloatError),
|
||||
#[error("Failed to parse measure unit")]
|
||||
ParseUnit(#[from] ParseError),
|
||||
#[error("Invalid measure format")]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue