Don't log files that dont load throw error instead

remove swift-log dependency
This commit is contained in:
Adam Fowler
2021-03-18 15:25:46 +00:00
parent 4af21bb4cf
commit aa30dcbddf
4 changed files with 15 additions and 14 deletions

View File

@@ -3,7 +3,7 @@ import Logging
extension HBMustacheLibrary {
/// Load templates from a folder
func loadTemplates(from directory: String, withExtension extension: String = "mustache", logger: Logger?) {
func loadTemplates(from directory: String, withExtension extension: String = "mustache") throws {
var directory = directory
if !directory.hasSuffix("/") {
directory += "/"
@@ -15,11 +15,12 @@ extension HBMustacheLibrary {
guard path.hasSuffix(extWithDot) else { continue }
guard let data = fs.contents(atPath: directory + path) else { continue }
let string = String(decoding: data, as: Unicode.UTF8.self)
guard let template = try? HBMustacheTemplate(string: string) else {
logger?.error("Failed to load \(path)")
continue
let template: HBMustacheTemplate
do {
template = try HBMustacheTemplate(string: string)
} catch {
throw Error.failedToLoad(path, error)
}
logger?.debug("Loading \(path)")
// drop ".mustache" from path to get name
let name = String(path.dropLast(extWithDot.count))
register(template, named: name)