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 error message when a SQL insert fails with a custom primary key #757

Merged
merged 1 commit into from
Jan 16, 2018

Conversation

MaxGabriel
Copy link
Member

@MaxGabriel MaxGabriel commented Dec 16, 2017

My coworker was using a custom primary key like so:

User sql=users
    Id sqltype=uuid default=uuid_generate_v4
    email Email sqltype=text
    UniqueEmail email
    createdAt UTCTime
    modifiedAt UTCTime
    deriving Show Eq Typeable

But didn't specify the type of the Id to be UUID. This caused Persistent to expect an Int64, leading to a very confusing error message on insert:

*** Exception: runFakeHandler issue: InternalError "Invalid result from a SQL insert, got: [PersistDbSpecific \"70c2418d-fb00-43f7-818d-eaf962612030\"]

By providing the actual underlying error, it gets much clearer:

*** Exception: runFakeHandler issue: InternalError "Invalid result from a SQL insert, got: [PersistDbSpecific \"70c2418d-fb00-43f7-818d-eaf962612030\"]. Error was: \"int64 Expected Integer, received: PersistDbSpecific \\\"70c2418d-fb00-43f7-818d-eaf962612030\\\"\"

Not sure if a new version is necessary for this, but I'm holding off since the master version of Persistent is deprecated anyway.

My coworker was using a custom primary key like so:

```
User sql=users
    Id sqltype=uuid default=uuid_generate_v4
    email Email sqltype=text
    UniqueEmail email
    createdAt UTCTime
    modifiedAt UTCTime
    deriving Show Eq Typeable
```

But didn't specify the type of the Id to be UUID. This caused Persistent to expect an Int64, leading to a very confusing error message on insert:

```
*** Exception: runFakeHandler issue: InternalError "Invalid result from a SQL insert, got: [PersistDbSpecific \"70c2418d-fb00-43f7-818d-eaf962612030\"]
```

By providing the actual underlying error, it gets much clearer:

```
*** Exception: runFakeHandler issue: InternalError "Invalid result from a SQL insert, got: [PersistDbSpecific \"70c2418d-fb00-43f7-818d-eaf962612030\"]. Error was: \"int64 Expected Integer, received: PersistDbSpecific \\\"70c2418d-fb00-43f7-818d-eaf962612030\\\"\"
```
@MaxGabriel MaxGabriel merged commit 57f2b96 into master Jan 16, 2018
@parsonsmatt parsonsmatt deleted the improveSqlInsertErrorMessage branch April 20, 2021 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant