Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor PersistenceError.recordNotFound #486

Merged
merged 5 commits into from
Feb 26, 2019
Merged

Conversation

groue
Copy link
Owner

@groue groue commented Feb 25, 2019

In GRDB 3 PersistenceError was defined as below:

// GRDB 3
public enum PersistenceError: Error {
    /// Thrown by MutablePersistableRecord.update() when no matching row could be
    /// found in the database.
    case recordNotFound(MutablePersistableRecord)
}

With such a definition, one can only build PersistenceError.recordNotFound with a fully defined record instance. It is impossible to throw this error with partial information. But some apps need that.

This PR changes the definition of PersistenceError to:

// GRDB 4
public enum PersistenceError: Error {
    case recordNotFound(databaseTableName: String, key: [String: DatabaseValue])
}

When you catch this error, you get the table and the primary key of the unfound record:

do {
    let place = Place(id: nil, name: "Valencia")
    try place.update(db)
} catch {
    print(error)
    // prints "Key not found in table place: [id:NULL]"
}

@groue groue added this to the GRDB 4.0.0 milestone Feb 25, 2019
@groue groue mentioned this pull request Feb 25, 2019
26 tasks
@groue groue merged commit 8faff70 into GRDB-4.0 Feb 26, 2019
@groue groue deleted the feature/RecordNotFound branch February 26, 2019 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant