summaryrefslogtreecommitdiff
path: root/crates/parser/src/error.rs
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2023-12-03 22:54:28 +0100
committerHenry Gressmann <mail@henrygressmann.de>2023-12-03 22:54:28 +0100
commitd1c1e5c6adb85effbd29a82ebde76681468e2504 (patch)
tree08ed67e1630985ca86c86b9e0571c6c6f4c7f304 /crates/parser/src/error.rs
parent0b3dc0eb015fadeee3d6417451e6951cb8a6d751 (diff)
feat: new tinywasm api
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/parser/src/error.rs')
-rw-r--r--crates/parser/src/error.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/crates/parser/src/error.rs b/crates/parser/src/error.rs
index ee217c7..6fa9e25 100644
--- a/crates/parser/src/error.rs
+++ b/crates/parser/src/error.rs
@@ -1,3 +1,5 @@
+use core::fmt::Debug;
+
use alloc::string::{String, ToString};
use wasmparser::Encoding;
@@ -14,6 +16,29 @@ pub enum ParseError {
Other(String),
}
+impl Debug for ParseError {
+ fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ match self {
+ Self::InvalidType => write!(f, "invalid type"),
+ Self::UnsupportedSection(section) => write!(f, "unsupported section: {}", section),
+ Self::DuplicateSection(section) => write!(f, "duplicate section: {}", section),
+ Self::EmptySection(section) => write!(f, "empty section: {}", section),
+ Self::UnsupportedOperator(operator) => write!(f, "unsupported operator: {}", operator),
+ Self::ParseError { message, offset } => {
+ write!(f, "error parsing module: {} at offset {}", message, offset)
+ }
+ Self::InvalidEncoding(encoding) => write!(f, "invalid encoding: {:?}", encoding),
+ Self::InvalidLocalCount { expected, actual } => write!(
+ f,
+ "invalid local count: expected {}, actual {}",
+ expected, actual
+ ),
+ Self::EndNotReached => write!(f, "end of module not reached"),
+ Self::Other(message) => write!(f, "unknown error: {}", message),
+ }
+ }
+}
+
impl From<wasmparser::BinaryReaderError> for ParseError {
fn from(value: wasmparser::BinaryReaderError) -> Self {
Self::ParseError {