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.
- Note: Uses global objects.
*/
init?(atRoot folder: URL) throws {
init?(atRoot folder: URL) {
self.inputFolder = folder
self.path = ""
@ -175,10 +175,10 @@ struct Element {
}
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]
do {
subFolders = try FileManager.default
@ -188,13 +188,13 @@ struct Element {
log.add(error: "Failed to read subfolders", source: source ?? "root", error: error)
return
}
self.elements = try subFolders.compactMap { subFolder in
self.elements = subFolders.compactMap { subFolder in
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.path = path
@ -252,7 +252,7 @@ struct Element {
// All properties initialized
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)
}
func generate(site: Element) throws {
func generate(site: Element) {
site.requiredFiles.forEach(files.require)
site.externalFiles.forEach(files.exclude)
try site.languages.forEach {
try generate(site: site, metadata: $0)
site.languages.forEach {
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 template = try LocalizedSiteTemplate(
let template = LocalizedSiteTemplate(
factory: templates,
language: language,
site: site)

View File

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

View File

@ -10,7 +10,7 @@ struct PrefilledTopBarTemplate {
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.language = language
self.sections = sections

View File

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