fix(cli): print farewell after successful cleanup - #116
Conversation
| }, | ||
|
|
||
| PersistentPostRunE: func(_ *cobra.Command, _ []string) error { | ||
| PersistentPostRunE: func(cmd *cobra.Command, _ []string) error { |
There was a problem hiding this comment.
Thank you, Daniel. One more thing I noticed is that when closing resources such as the DB, logger, etc, the current implementation exits the function as soon as an error occurs while closing a resource and prints the close error.
To make it more robust, how about collecting any errors that occur while closing the resources and returning them all at the end, if there are any? In that case, the output would be something like:
go run .
Thanks for using Pgxcli.
See you next time.
[error: failed to close the database connection]
We have to decide whether farewell message should be printed or not, if close error occurs. You can address this in another PR.
There was a problem hiding this comment.
Addressed in 584a3e9. Cleanup now attempts to close the application, database client, and logger even if an earlier close fails, then returns all close errors with errors.Join. For the farewell behavior, I chose to preserve #110’s intent: if any cleanup step fails, no farewell is printed. Added tests for cleanup order, error aggregation, and farewell behavior.
06a0082 to
01337d3
Compare
What does this PR do?
This is a follow-up to #110 and addresses the cleanup ordering noted in this review comment.
PR #110 correctly removed the farewell from
--helpand--version, but moved it intoRunE, beforePersistentPostRunEcloses the application, database client, and logger. If cleanup fails, the farewell is printed before the command returns an error.This change moves the farewell to the end of
PersistentPostRunE, so it is printed only after cleanup succeeds.Because persistent hooks can also run for child commands, the farewell is limited to the root command. This keeps future non-interactive commands, such as
pgxcli export, from including the interactive farewell in their output.Reproduction
Using the default history path:
Exit pgxcli with
\q.On the current
main, the farewell is printed before the history-save error. With this change, only the error is printed.Remember to restore the file permissions:
chmod u+w ~/.pgxcli_history.jsonl