Skip to content

Commit

Permalink
Add Type to relationshipWasNil RuneError (#86)
Browse files Browse the repository at this point in the history
* Add Type to relationshipWasNil RuneError

Co-authored-by: Sean Miller <[email protected]>
  • Loading branch information
seanmiller802 and Sean Miller authored Jun 14, 2022
1 parent da80749 commit d62982c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Sources/Alchemy/SQL/Rune/Relationships/Relationship.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public protocol RelationshipAllowed {

extension Model {
public static func from(_ value: Self?) throws -> Self {
try value.unwrap(or: RuneError.relationshipWasNil)
try value.unwrap(or: RuneError.relationshipWasNil(type: Self.self))
}
}

Expand Down
4 changes: 3 additions & 1 deletion Sources/Alchemy/SQL/Rune/RuneError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public struct RuneError: Error {
public static let notFound = RuneError("Unable to find an element of this type.")

/// Couldn't unwrap a relationship that was expected to be nonnil.
public static let relationshipWasNil = RuneError("This non-optional relationship had no matching models.")
public static func relationshipWasNil<M: Model>(type: M.Type) -> RuneError {
RuneError("This non-optional relationship to \(type) has no matching models.")
}

/// Couldn't sync a model; its id was nil.
public static let syncErrorNoId = RuneError("Can't .sync() an object with a nil `id`.")
Expand Down

0 comments on commit d62982c

Please sign in to comment.