diff --git a/lib/runtime-core/src/error.rs b/lib/runtime-core/src/error.rs index 734e11cff..9e1eba8fe 100644 --- a/lib/runtime-core/src/error.rs +++ b/lib/runtime-core/src/error.rs @@ -76,6 +76,31 @@ impl PartialEq for LinkError { } } +impl std::fmt::Display for LinkError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self { + LinkError::ImportNotFound {namespace, name} => write!(f, "Import not found, namespace: {}, name: {}", namespace, name), + LinkError::IncorrectGlobalDescriptor {namespace, name,expected,found} => { + write!(f, "Incorrect global descriptor, namespace: {}, name: {}, expected global descriptor: {:?}, found global descriptor: {:?}", namespace, name, expected, found) + }, + LinkError::IncorrectImportSignature{namespace, name,expected,found} => { + write!(f, "Incorrect import signature, namespace: {}, name: {}, expected signature: {}, found signature: {}", namespace, name, expected, found) + } + LinkError::IncorrectImportType{namespace, name,expected,found} => { + write!(f, "Incorrect import type, namespace: {}, name: {}, expected type: {}, found type: {}", namespace, name, expected, found) + } + LinkError::IncorrectMemoryDescriptor{namespace, name,expected,found} => { + write!(f, "Incorrect memory descriptor, namespace: {}, name: {}, expected memory descriptor: {:?}, found memory descriptor: {:?}", namespace, name, expected, found) + }, + LinkError::IncorrectTableDescriptor{namespace, name,expected,found} => { + write!(f, "Incorrect table descriptor, namespace: {}, name: {}, expected table descriptor: {:?}, found table descriptor: {:?}", namespace, name, expected, found) + }, + } + } +} + +impl std::error::Error for LinkError {} + /// This is the error type returned when calling /// a webassembly function. ///