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

Improve database value decoding diagnostics #384

Merged
merged 31 commits into from
Aug 13, 2018
Merged

Conversation

groue
Copy link
Owner

@groue groue commented Jul 14, 2018

This PR makes as much information as possible available when a database value conversion error happens:

struct Player: Decodable, FetchableRecord {
    var id: Int64
    var name: String
    var score: Int
}

// fatal error: could not convert database value NULL to String
// (column: `name`, column index: 1, row: [id:42 name:NULL score:100],
// sql: `SELECT * FROM player WHERE id = ?`, arguments: [42])
let player = try Player.fetchOne(db, key: 42)

In the example above, the error message helps understanding that the Player.name property should be made optional, or that the player.name database column should be changed so that it never contains null values.

And in the following example, it is easy to spot and fix the typo:

struct Player: Decodable, FetchableRecord {
    var id: Int64
    var name: String
    var scor: Int
}

// fatal error: could not read Int from missing column `scor`
// (row: [id:42 name:"Arthur" score:100],
// sql: `SELECT * FROM player WHERE id = ?`, arguments: [42])
let player = try Player.fetchOne(db, key: 42)

With previous GRDB versions, it was sometimes difficult to know which columns or properties would need fixing.

@groue groue force-pushed the conversionDebugInfo branch from cd87991 to 62b272e Compare August 3, 2018 06:31
@groue groue force-pushed the conversionDebugInfo branch from 62b272e to 78a6f72 Compare August 6, 2018 11:45
@groue groue merged commit 8eee52d into development Aug 13, 2018
@groue groue deleted the conversionDebugInfo branch August 13, 2018 05:45
groue added a commit that referenced this pull request Aug 13, 2018
…ecords

This is the real final touch for #384, after all
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