Skip to content

Leaf crashes encoding array of optional UUIDs #197

@bottlehall

Description

@bottlehall

Describe the bug

Leaf crashes encoding array of optional UUIDs as context.

Steps to reproduce

  1. Having checked using latest version of toolbox, create new project using vapor new... and require Leaf.
  2. Update Package.swift to include Leaf in target App.
  3. 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?]
}
  1. Build, run and attempt to get the route from within a browser.
  2. Get error:

Leaf/LeafEncoder.swift:192: Fatal error: Unexpectedly found nil while unwrapping an Optional value

self.array.append(encoder.container!.data!)
  1. 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?.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions