From 6e876761607fa0c0e87d6da293d7a0121613b4ae Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Thu, 14 Feb 2019 18:40:52 -0800 Subject: [PATCH] Impl error for link error (#182) --- lib/runtime-core/src/error.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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. ///