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

Fix display of exception error messages, #1079 #1080

Merged
merged 4 commits into from
May 4, 2020

Conversation

hdgarrood
Copy link
Contributor

@hdgarrood hdgarrood commented Apr 23, 2020

Fixes #1079. Running the test script from that issue now prints

Migrating: ALTER TABLE "person" ALTER COLUMN "age" TYPE INT8
[Debug#SQL] ALTER TABLE "person" ALTER COLUMN "age" TYPE INT8; []
persistent-repro-exe:

Database migration: manual intervention required.
The unsafe actions are prefixed by '***' below:

*** ALTER TABLE "person" DROP COLUMN "age";

This is arguably a breaking change, since if people were catching this exception in their code before, they'll need to change their uses of catch to catch this type. If #969 was previously released without a breaking-level version bump and nobody complained, though, this is probably okay to release without a breaking-level version bump too?

Before submitting your PR, check that you've:

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

Fixes yesodweb#1079. Running the test script from that issue now prints

    Migrating: ALTER TABLE "person" ALTER COLUMN "age" TYPE INT8
    [Debug#SQL] ALTER TABLE "person" ALTER COLUMN "age" TYPE INT8; []
    persistent-repro-exe:

    Database migration: manual intervention required.
    The unsafe actions are prefixed by '***' below:

    *** ALTER TABLE "person" DROP COLUMN "age";
Copy link
Collaborator

@parsonsmatt parsonsmatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few changes please - also this can be released with 2.11.0.0 which is unreleased so far.

@@ -1,5 +1,9 @@
# Changelog for persistent

## 2.11.1.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got to update the changelog to make it less confusing - can you put this in 2.11.0.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing! I’ve seen people use a heading “unreleased changes” at the top of changelogs, which seems to work okay.

where
displayMigration :: (Bool, Sql) -> String
displayMigration (True, s) = "*** " ++ unpack s ++ ";"
displayMigration (False, s) = " " ++ unpack s ++ ";"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have a derived Show instance and a custom implementation of displayException.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that to start with, but unfortunately GHC uses Show, not displayException, when exiting due to an uncaught exception 🤷‍♂️ I’m not sure how else to handle it. Maybe the exception type could just be data UnsafeMigrationException = UnsafeMigrationException and we could instead print the human readable error message before throwing it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s not super helpful if people do want to catch the error, though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you serious, GHC? okay, this is fine then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha yeah that was more or less my reaction too

persistent/persistent.cabal Outdated Show resolved Hide resolved
hdgarrood and others added 2 commits May 4, 2020 13:52
Co-authored-by: Matt Parsons <parsonsmatt@gmail.com>
@parsonsmatt parsonsmatt merged commit e877e17 into yesodweb:master May 4, 2020
@hdgarrood hdgarrood deleted the fix-exception-display-1079 branch May 4, 2020 15:51
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.

Migration error messages are not printed correctly
2 participants