1

I' am new to Vapor and Leaf.

I have defined a route that should query data from the DB and pass it to a view. The problem: As soon as I call this route I get a fatal error in the LeadEncoder File Row 162 (superEncoder Function). Here is a Picture:

Fatal Error Picture

enter image description here

Route File:

app.get("dashboard") { req async throws -> View in
    let result = try await Cocktail.query(on: req.db).all()
    let context = CocktailContext(cocktails: result)
        
    return try await req.view.render("dashboard", context)
}

Context File:

struct CocktailContext: Codable, Content {
    let cocktails: [Cocktail]
}

Model File:

final class Cocktail: Model, Content, Codable {
    static let schema = "cocktail"
    
    @ID(key: .id)
    var id: UUID?

    @Field(key: "name")
    var name: String
    
    @Field(key: "description")
    var description: String
    
    @Field(key: "amount_ml")
    var amount_ml: Int
    
    @Field(key: "img_url")
    var img_url: String
    
    @OptionalField(key: "video_url")
    var video_url: String?
    
    @Parent(key: "difficulty_id")
    var difficulty_id: Difficulty
    
    @Parent(key: "glass_id")
    var glass_id: Glass

    init() { }

    init(name: String, description: String, amount_ml: Int, image_url: String, video_url: String?, difficulty_id: Difficulty.IDValue, glass_id: Glass.IDValue) {
        self.id = UUID()
        self.name = name
        self.description = description
        self.amount_ml = amount_ml
        self.img_url = image_url
        self.video_url = video_url
        self.$difficulty_id.id = difficulty_id
        self.$glass_id.id = glass_id
    }
}

What am I doing wrong? I can't find it in the vapor documentary and I can't find a more detailed description of the error so far. All I know is that the data is queried correctly from the DB...

Thank you in advance!

Dharmesh Kheni
  • 71,228
  • 33
  • 160
  • 165
PsKinggood
  • 43
  • 6
  • 1
    Try running a package update - there are no fatal errors in the current version of the code - https://github.com/vapor/leaf/blob/main/Sources/Leaf/LeafEncoder.swift – 0xTim Sep 29 '22 at 09:21

0 Answers0