Leaf crashes encoding array of optional UUIDs
bottlehall opened this issue · comments
Describe the bug
Leaf crashes encoding array of optional UUIDs as context.
Steps to reproduce
- Having checked using latest version of toolbox, create new project using
vapor new...
and requireLeaf
. - Update
Package.swift
to includeLeaf
in targetApp
. - Replace contents of route.swift with:
func routes(_ app: Application) throws {
app.get("hello") { req -> EventLoopFuture<View> in
let nils:[UUID?] = [nil,nil,nil]
let context = opt(nils: nils)
return req.leaf.render("blah", context)
}
}
struct opt: Codable {
let nils:[UUID?]
}
- Build, run and attempt to get the route from within a browser.
- Get error:
Leaf/LeafEncoder.swift:192: Fatal error: Unexpectedly found nil while unwrapping an Optional value
self.array.append(encoder.container!.data!)
- The error occurs attempting to unwrap
data
.
Expected behaviour
I expected it to pass context to use in the view's leaf file.
Environment
- Vapor Framework version: 4.48
- Vapor Toolbox version: 18.0.0
- OS version: macOS 11.4 (but problem exists on Ubuntu 20.4 as well)
Additional context
I encountered the issue with data type UUID?
as shown above, but it exists for other data types as well, such Bool?
and String?
.