diff --git a/Sources/Environment.swift b/Sources/Environment.swift index 611e14e..d612ae4 100644 --- a/Sources/Environment.swift +++ b/Sources/Environment.swift @@ -47,7 +47,7 @@ public struct Environment { do { return try template.render(context) } catch { - try errorReporter.report(error: error) + throw errorReporter.reportError(error) } } @@ -66,7 +66,7 @@ public struct Environment { do { return try closure() } catch { - try errorReporter.report(error: error) + throw errorReporter.reportError(error) } } diff --git a/Sources/Errors.swift b/Sources/Errors.swift index 8fb988e..97e93b7 100644 --- a/Sources/Errors.swift +++ b/Sources/Errors.swift @@ -46,17 +46,17 @@ public class ErrorReporterContext { public protocol ErrorReporter: class { var context: ErrorReporterContext! { get set } - func report(error: Error) throws -> Never + func reportError(_ error: Error) -> Error func contextAwareError(_ error: TemplateSyntaxError, context: ErrorReporterContext) -> Error? } open class SimpleErrorReporter: ErrorReporter { public var context: ErrorReporterContext! - open func report(error: Error) throws -> Never { - guard let syntaxError = error as? TemplateSyntaxError else { throw error } - guard let context = context else { throw error } - throw contextAwareError(syntaxError, context: context) ?? error + open func reportError(_ error: Error) -> Error { + guard let syntaxError = error as? TemplateSyntaxError else { return error } + guard let context = context else { return error } + return contextAwareError(syntaxError, context: context) ?? error } // TODO: add stack trace using parent context