wasmedge-hs-0.17.1.0: Haskell bindings for the WasmEdge WebAssembly runtime
Copyright(c) 2026 Tushar Adhatrao
LicenseMIT
Stabilitystable
Safe HaskellNone
LanguageGHC2021

WasmEdge.Error

Description

This module defines WasmEdgeError, the exception type thrown by all operations that fail in the WasmEdge C runtime. It also provides the ErrCategory and ErrCode types that mirror the C API enums.

Most users only need to catch WasmEdgeError in an exception handler:

result <- try (runWasmFile vm "module.wasm" "main" []) :: IO (Either WasmEdgeError [WasmVal])
Synopsis

Error type

data WasmEdgeError #

An error returned by the WasmEdge runtime.

Thrown as a Haskell exception by all public API functions that encounter a failed WasmEdge_Result. Can also be caught as SomeException.

Constructors

WasmEdgeError 

Fields

Instances

Instances details
NFData WasmEdgeError # 
Instance details

Defined in WasmEdge.Error

Methods

rnf :: WasmEdgeError -> () #

Exception WasmEdgeError # 
Instance details

Defined in WasmEdge.Error

Generic WasmEdgeError # 
Instance details

Defined in WasmEdge.Error

Associated Types

type Rep WasmEdgeError 
Instance details

Defined in WasmEdge.Error

type Rep WasmEdgeError = D1 ('MetaData "WasmEdgeError" "WasmEdge.Error" "wasmedge-hs-0.17.1.0-inplace" 'False) (C1 ('MetaCons "WasmEdgeError" 'PrefixI 'True) (S1 ('MetaSel ('Just "weErrCategory") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ErrCategory) :*: (S1 ('MetaSel ('Just "weErrCode") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "weErrMessage") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text))))
Show WasmEdgeError # 
Instance details

Defined in WasmEdge.Error

Eq WasmEdgeError # 
Instance details

Defined in WasmEdge.Error

type Rep WasmEdgeError # 
Instance details

Defined in WasmEdge.Error

type Rep WasmEdgeError = D1 ('MetaData "WasmEdgeError" "WasmEdge.Error" "wasmedge-hs-0.17.1.0-inplace" 'False) (C1 ('MetaCons "WasmEdgeError" 'PrefixI 'True) (S1 ('MetaSel ('Just "weErrCategory") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ErrCategory) :*: (S1 ('MetaSel ('Just "weErrCode") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Word32) :*: S1 ('MetaSel ('Just "weErrMessage") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text))))

type WasmResult a = Either WasmEdgeError a #

A computation that may return a WasmEdgeError. Use throwOnLeft to re-raise as an exception, or pattern-match directly.

Error category

data ErrCategory #

Maps to the C WasmEdge_ErrCategory enum.

Constructors

ErrCategory_WASM

Error from the WebAssembly spec (code is ErrCode)

ErrCategory_UserDefined

User-defined error code (e.g., from host functions)

ErrCategory_Unknown Word32

An unrecognised category (future-proofing)

Instances

Instances details
NFData ErrCategory # 
Instance details

Defined in WasmEdge.Error

Methods

rnf :: ErrCategory -> () #

Generic ErrCategory # 
Instance details

Defined in WasmEdge.Error

Associated Types

type Rep ErrCategory 
Instance details

Defined in WasmEdge.Error

type Rep ErrCategory = D1 ('MetaData "ErrCategory" "WasmEdge.Error" "wasmedge-hs-0.17.1.0-inplace" 'False) (C1 ('MetaCons "ErrCategory_WASM" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "ErrCategory_UserDefined" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ErrCategory_Unknown" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32))))
Show ErrCategory # 
Instance details

Defined in WasmEdge.Error

Eq ErrCategory # 
Instance details

Defined in WasmEdge.Error

type Rep ErrCategory # 
Instance details

Defined in WasmEdge.Error

type Rep ErrCategory = D1 ('MetaData "ErrCategory" "WasmEdge.Error" "wasmedge-hs-0.17.1.0-inplace" 'False) (C1 ('MetaCons "ErrCategory_WASM" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "ErrCategory_UserDefined" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "ErrCategory_Unknown" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word32))))

mkErrCategory :: Word32 -> ErrCategory #

Convert a raw C enum value (Word32) to ErrCategory.

Common predicates

isSuccess :: WasmEdgeError -> Bool #

True if the error has error code 0 (should not happen in practice, but guards against malformed results).

isUserError :: WasmEdgeError -> Bool #

True if this is a user-defined error from a host function.

formatError :: WasmEdgeError -> String #

Format a WasmEdgeError into a human-readable string with a hex error code.

Convenience

throwOnLeft :: WasmResult a -> IO a #

Throw a WasmEdgeError as an IO exception on Left, or unwrap Right.

Useful for step-by-step WASM pipelines where you want errors to propagate as exceptions rather than handling them inline:

withVM Nothing Nothing $ vm -> do
  loadWasmFile vm "module.wasm" >>= throwOnLeft
  validate vm                    >>= throwOnLeft
  instantiate vm                 >>= throwOnLeft
  execute vm "run" []            >>= throwOnLeft