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

Projects
None yet
1 participant
@MaxGabriel
Member

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.

Improve error message when a SQL insert fails with a custom primary key
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 force-pushed the improveSqlInsertErrorMessage branch from 189e843 to 9a16736 Dec 16, 2017

@MaxGabriel MaxGabriel merged commit 57f2b96 into master Jan 16, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment