Correctly label non-throwing functions

Remove throws from Element constructor
This commit is contained in:
Christoph Hagen 2022-09-08 09:30:54 +02:00
parent 28623d1209
commit 81b373fb5a
5 changed files with 20 additions and 20 deletions

View File

@ -141,7 +141,7 @@ struct Element {
- Parameter folder: The root folder of the site content. - Parameter folder: The root folder of the site content.
- Note: Uses global objects. - Note: Uses global objects.
*/ */
init?(atRoot folder: URL) throws { init?(atRoot folder: URL) {
self.inputFolder = folder self.inputFolder = folder
self.path = "" self.path = ""
@ -175,10 +175,10 @@ struct Element {
} }
files.add(page: path, id: id) files.add(page: path, id: id)
try self.readElements(in: folder, source: nil) self.readElements(in: folder, source: nil)
} }
mutating func readElements(in folder: URL, source: String?) throws { mutating func readElements(in folder: URL, source: String?) {
let subFolders: [URL] let subFolders: [URL]
do { do {
subFolders = try FileManager.default subFolders = try FileManager.default
@ -188,13 +188,13 @@ struct Element {
log.add(error: "Failed to read subfolders", source: source ?? "root", error: error) log.add(error: "Failed to read subfolders", source: source ?? "root", error: error)
return return
} }
self.elements = try subFolders.compactMap { subFolder in self.elements = subFolders.compactMap { subFolder in
let s = (source.unwrapped { $0 + "/" } ?? "") + subFolder.lastPathComponent let s = (source.unwrapped { $0 + "/" } ?? "") + subFolder.lastPathComponent
return try Element(parent: self, folder: subFolder, path: s) return Element(parent: self, folder: subFolder, path: s)
} }
} }
init?(parent: Element, folder: URL, path: String) throws { init?(parent: Element, folder: URL, path: String) {
self.inputFolder = folder self.inputFolder = folder
self.path = path self.path = path
@ -252,7 +252,7 @@ struct Element {
// All properties initialized // All properties initialized
files.add(page: path, id: id) files.add(page: path, id: id)
try self.readElements(in: folder, source: path) self.readElements(in: folder, source: path)
} }
} }

View File

@ -9,17 +9,17 @@ struct SiteGenerator {
self.templates = try TemplateFactory(templateFolder: templatesFolder) self.templates = try TemplateFactory(templateFolder: templatesFolder)
} }
func generate(site: Element) throws { func generate(site: Element) {
site.requiredFiles.forEach(files.require) site.requiredFiles.forEach(files.require)
site.externalFiles.forEach(files.exclude) site.externalFiles.forEach(files.exclude)
try site.languages.forEach { site.languages.forEach {
try generate(site: site, metadata: $0) generate(site: site, metadata: $0)
} }
} }
private func generate(site: Element, metadata: Element.LocalizedMetadata) throws { private func generate(site: Element, metadata: Element.LocalizedMetadata) {
let language = metadata.language let language = metadata.language
let template = try LocalizedSiteTemplate( let template = LocalizedSiteTemplate(
factory: templates, factory: templates,
language: language, language: language,
site: site) site: site)

View File

@ -35,7 +35,7 @@ struct LocalizedSiteTemplate {
factory.page factory.page
} }
init(factory: TemplateFactory, language: String, site: Element) throws { init(factory: TemplateFactory, language: String, site: Element) {
self.author = site.author self.author = site.author
self.factory = factory self.factory = factory
@ -61,7 +61,7 @@ struct LocalizedSiteTemplate {
url: $0.path + Element.htmlPagePathAddition(for: language)) url: $0.path + Element.htmlPagePathAddition(for: language))
} }
self.topBar = try .init( self.topBar = .init(
factory: factory, factory: factory,
language: language, language: language,
sections: sections, sections: sections,

View File

@ -10,7 +10,7 @@ struct PrefilledTopBarTemplate {
private let factory: TemplateFactory private let factory: TemplateFactory
init(factory: TemplateFactory, language: String, sections: [SectionInfo], topBarWebsiteTitle: String) throws { init(factory: TemplateFactory, language: String, sections: [SectionInfo], topBarWebsiteTitle: String) {
self.factory = factory self.factory = factory
self.language = language self.language = language
self.sections = sections self.sections = sections

View File

@ -12,13 +12,13 @@ let files = FileSystem(
in: configuration.contentDirectory, in: configuration.contentDirectory,
to: configuration.outputDirectory) to: configuration.outputDirectory)
do { guard let siteData = Element(atRoot: configuration.contentDirectory) else {
guard let siteData = try Element(atRoot: configuration.contentDirectory) else {
exit(0) exit(0)
} }
do {
let siteGenerator = try SiteGenerator() let siteGenerator = try SiteGenerator()
try siteGenerator.generate(site: siteData) siteGenerator.generate(site: siteData)
} catch { } catch {
print(error) print(error)
exit(0) exit(0)