-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4092a1c
commit 5036ce2
Showing
1 changed file
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
fn into(self: Self) -> JsValue { | ||
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; | ||
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; | ||
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; | ||
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; | ||
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; | ||
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; | ||
crate::HQError { | ||
err_type: crate::HQErrorType::MalformedProject, | ||
msg: format!("{}", format_args!($($args)*)), | ||
file: file!().to_string(), | ||
line: line!(), | ||
column: column!() | ||
} | ||
}}; | ||
} |