Skip to content

Commit

Permalink
add error.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
pufferfish101007 committed Jan 19, 2024
1 parent 4092a1c commit 5036ce2
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
use alloc::string::String;
use wasm_bindgen::JsValue;

#[derive(Debug)] // todo: get rid of this once all expects are gone
pub struct HQError {
pub err_type: HQErrorType,
pub msg: String,
pub file: String,
pub line: u32,
pub column: u32,
}
#[derive(Debug)] // todo: get rid of this once all expects are gone
pub enum HQErrorType {
MalformedProject,
InternalError,
Unimplemented,
}

impl Into<JsValue> for HQError {

Check failure on line 19 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lint (clippy)

an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
fn into(self: Self) -> JsValue {

Check failure on line 20 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lint (clippy)

the type of the `self` parameter does not need to be arbitrary
JsValue::from_str(match self.err_type {
HQErrorType::Unimplemented => format!("todo: {}<br>at {}:{}:{}<br>this is a bug or missing feature that is known and will be fixed or implemented in a future update", self.msg, self.file, self.line, self.column),
HQErrorType::InternalError => format!("error: {}<br>at {}:{}:{}<br>this is probably a bug with HyperQuark itself. Please report this bug, with this error message, at <a href=\"https://github.com/hyperquark/hyperquark/issues/new\">https://github.com/hyperquark/hyperquark/issues/new</a>", self.msg, self.file, self.line, self.column),
HQErrorType::MalformedProject => format!("error: {}<br>at {}:{}:{}<br>this is probably a problem with the project itself, but if it works in vanilla scratch then this is a bug; please report it, by creating an issue at <a href=\"https://github.com/hyperquark/hyperquark/issues/new\">https://github.com/hyperquark/hyperquark/issues/new</a>, including this error message", self.msg, self.file, self.line, self.column),
}.as_str())
}
}

#[macro_export]
macro_rules! hq_todo {
($($args:tt)+) => {{
use crate::alloc::string::ToString;

Check failure on line 32 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lint (clippy)

`crate` references the macro call's crate
return Err(crate::HQError {
err_type: crate::HQErrorType::Unimplemented,
msg: format!("{}", format_args!($($args)*)),
file: file!().to_string(),
line: line!(),
column: column!()
});
}};
}

#[macro_export]
macro_rules! hq_bug {
($($args:tt)+) => {{
use crate::alloc::string::ToString;

Check failure on line 46 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lint (clippy)

`crate` references the macro call's crate
return Err(crate::HQError {
err_type: crate::HQErrorType::InternalError,
msg: format!("{}", format_args!($($args)*)),
file: file!().to_string(),
line: line!(),
column: column!()
});
}};
}

#[macro_export]
macro_rules! hq_bad_proj {
($($args:tt)+) => {{
use crate::alloc::string::ToString;

Check failure on line 60 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lint (clippy)

`crate` references the macro call's crate
return Err(crate::HQError {
err_type: crate::HQErrorType::MalformedProject,
msg: format!("{}", format_args!($($args)*)),
file: file!().to_string(),
line: line!(),
column: column!()
});
}};
}

#[macro_export]
macro_rules! make_hq_todo {
($($args:tt)+) => {{
use crate::alloc::string::ToString;

Check failure on line 74 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lint (clippy)

`crate` references the macro call's crate
crate::HQError {
err_type: crate::HQErrorType::Unimplemented,
msg: format!("{}", format_args!($($args)*)),
file: file!().to_string(),
line: line!(),
column: column!()
}
}};
}

#[macro_export]
macro_rules! make_hq_bug {
($($args:tt)+) => {{
use crate::alloc::string::ToString;

Check failure on line 88 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lint (clippy)

`crate` references the macro call's crate
crate::HQError {
err_type: crate::HQErrorType::InternalError,
msg: format!("{}", format_args!($($args)*)),
file: file!().to_string(),
line: line!(),
column: column!()
}
}};
}

#[macro_export]
macro_rules! make_hq_bad_proj {
($($args:tt)+) => {{
use crate::alloc::string::ToString;

Check failure on line 102 in src/error.rs

View workflow job for this annotation

GitHub Actions / Lint (clippy)

`crate` references the macro call's crate
crate::HQError {
err_type: crate::HQErrorType::MalformedProject,
msg: format!("{}", format_args!($($args)*)),
file: file!().to_string(),
line: line!(),
column: column!()
}
}};
}

0 comments on commit 5036ce2

Please sign in to comment.