changer Never return type to Error in ErrorReporter

this resolves warning related to Never type
This commit is contained in:
Ilya Puchka
2017-11-29 23:41:18 +01:00
parent 5878c323a2
commit 27135f3ea3
2 changed files with 7 additions and 7 deletions

View File

@@ -47,7 +47,7 @@ public struct Environment {
do { do {
return try template.render(context) return try template.render(context)
} catch { } catch {
try errorReporter.report(error: error) throw errorReporter.reportError(error)
} }
} }
@@ -66,7 +66,7 @@ public struct Environment {
do { do {
return try closure() return try closure()
} catch { } catch {
try errorReporter.report(error: error) throw errorReporter.reportError(error)
} }
} }

View File

@@ -46,17 +46,17 @@ public class ErrorReporterContext {
public protocol ErrorReporter: class { public protocol ErrorReporter: class {
var context: ErrorReporterContext! { get set } var context: ErrorReporterContext! { get set }
func report(error: Error) throws -> Never func reportError(_ error: Error) -> Error
func contextAwareError(_ error: TemplateSyntaxError, context: ErrorReporterContext) -> Error? func contextAwareError(_ error: TemplateSyntaxError, context: ErrorReporterContext) -> Error?
} }
open class SimpleErrorReporter: ErrorReporter { open class SimpleErrorReporter: ErrorReporter {
public var context: ErrorReporterContext! public var context: ErrorReporterContext!
open func report(error: Error) throws -> Never { open func reportError(_ error: Error) -> Error {
guard let syntaxError = error as? TemplateSyntaxError else { throw error } guard let syntaxError = error as? TemplateSyntaxError else { return error }
guard let context = context else { throw error } guard let context = context else { return error }
throw contextAwareError(syntaxError, context: context) ?? error return contextAwareError(syntaxError, context: context) ?? error
} }
// TODO: add stack trace using parent context // TODO: add stack trace using parent context