Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Implement log redirection interface #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

unclechu
Copy link

@unclechu unclechu commented Oct 1, 2020

Relates to #34 (satisfies second part).

  1. Adds alternative runMigrationA and runMigrationsA functions with additional argument of type Either Text Text -> IO () where Left is an error message and Right is an info message
  2. By default sends error messages to stderr instead of stdout
  3. Usage info in migrate executable is printed to stderr instead of stdout in case arguments are incorrect and executable exits with error exit code

This is the second attempt to implement the feature after #35

Copy link

@MasseR MasseR left a comment

Choose a reason for hiding this comment

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

All in all, I like these changes a lot more than the previous ones. My comments can be categorized into a few sections

  • Nitpicking
  • Autoformatter
  • Thumbs ups

As a 3rd party, I don't see any obvious blockers on this. Maintainer will have the final say.

src/Database/PostgreSQL/Simple/Migration.hs Show resolved Hide resolved

-- | A version of 'runMigrations' which gives you control of where the log
-- messages are sent to.
runMigrationsA
Copy link

Choose a reason for hiding this comment

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

I know I said runMigrationsA in the previous review, but this could probably have a more descriptive name? I'm terrible at naming things.

Copy link
Author

Choose a reason for hiding this comment

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

@MasseR Ha, I have the same problem. I couldn’t come up with something good. I could name it as runMigrationsWithCustomLogWriteFn but I’m hesitating to add this.

scriptsInDirectory dir >>= go
where
go fs = sequenceMigrations (executeMigrationFile <$> fs)
executeMigrationFile f = executeMigration con verbose f =<< BS.readFile (dir ++ "/" ++ f)
Copy link

Choose a reason for hiding this comment

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

It looks like you ran some kind of autoformatter to the source? I don't mind and if were the maintainer I would pass this, but maybe be on the safe side and avoid autoformatters on unfamiliar codebases? Formatting can be a touchy subject for some.

Copy link
Author

Choose a reason for hiding this comment

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

No, I didn’t use no formatter. All changes are manual. I realized almost all the lines in the code are limited to 80 chars. But only some aren’t. So I split those lines into few.

Copy link

Choose a reason for hiding this comment

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

I'm still hesitant on it. These kinds of extra changes are just extra noise for the reviewer/maintainer.

Copy link
Author

Choose a reason for hiding this comment

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

I had to touch this line anyway.

@@ -51,7 +53,7 @@ ppException a = catch a ehandler
ehandler e = maybe (throw e) (*> exitFailure)
(pSqlError <$> fromException e)
bsToString = T.unpack . T.decodeUtf8
pSqlError e = mapM_ putStrLn
pSqlError e = mapM_ (hPutStrLn stderr)
Copy link

Choose a reason for hiding this comment

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

This is a visible change in behavior, I'm hesitant on this. As far as changes go, this is one of the more benign ones, but does change the behavior

postgresql-simple-migration --help | grep foo
postgresql-simple-migration --help | less
postgresql-simple-migration --help 2>&1 | grep foo

Copy link
Author

@unclechu unclechu Oct 2, 2020

Choose a reason for hiding this comment

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

  1. None of the commands you provided as an example are related to this line in an any way
  2. There’s no such argument --help, I added it to Implement abstract interface for log writes #35 but didn’t in this MR, the command will fail
  3. This will print to stderr only in case there were some errors while applying migrations

If you refer to the usage of printUsage:

  1. If you provide correct -h argument it will, as before, print usage info to stdout thus, if you use the program correctly, it will work as before.
  2. If you provide incorrect arguments the program, as before, will fail and (this changed in this MR) will print usage info to stderr as it should. If you rely somewhere on failure scenario caused by using incorrect arguments then you’re doing something wrong and you’re using the program incorrectly. I think you should not pay any attention to copying bugs in order to keep behavior the same unless you build some platform emulation tool (e.g. WineHQ).
  3. Someone may try to use --help argument (which doesn’t exist), it’s the most default one for getting usage info. But to whom I’m telling this, you just tried to do so in your example! And in Bash, if you don’t use set -eo pipefail, the grepping from your example would succeed (before this change) but this is so only because Bash sucks, it sweeps most of the errors under the carpet by default. It is still a bug. But just for this case I thought it was a good idea to add --help argument alongwith -h one as a part of the MR (which I did in Implement abstract interface for log writes #35 but you were against it, I still think it is a good idea).

@pjones
Copy link

pjones commented Oct 30, 2020

What's the status of this PR? Does anyone need any help?

@unclechu
Copy link
Author

@pjones We’re just waiting for maintainer’s feedback.

@unclechu
Copy link
Author

If you ask me it’s ready to go.

@unclechu
Copy link
Author

unclechu commented Nov 5, 2020

@ameingast Let’s ping the maintainer in case he missed or didn’t receive a notification.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants