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

Remove os.Exit calls in pkg layer #61

Merged
merged 1 commit into from
Mar 22, 2021
Merged

Remove os.Exit calls in pkg layer #61

merged 1 commit into from
Mar 22, 2021

Conversation

Crevil
Copy link
Member

@Crevil Crevil commented Mar 22, 2021

Currently a UI instance is passed around to all parts of shuttle allowing layers
to report messages to the user. It also provides methods ExitWithError,
ExitWithErrorCode and CheckIfError which are fatal messages stopping shuttle
completely by calling os.Exit. This makes shuttle in it self hard to test and
provides unclear exit paths of the code.

This change contains multiple changes to fix above issues.

The methods from package ui are removed and instead a checkError function is
added to package cmd which is responsible for selecting an exit code based on
the error. This greatly improvoes maintainability of the code and makes it
easier to reason about any possible exit paths from code in packages of pkg/*.

Some dead code is removed from package pkg/config. An unused CheckIfError
function was laying around here and as this change moves functionality around
related to the nature of this one I figured it was worth removing now.

During the change I found a couple of bugs in the error reporting that is fixed
as well.

When using command 'run' with invalid arguments exit code 1 indicating a shuttle
failure is reported instead of 2 indicating bad user input.

If a plan cannot be fetched due to an unknown protocol a panic is thrown. It now
returns an ExitCode error indicating bad user input.

Errors around the .shuttle directory are now also detected and propagated
instead of silently ignored.

Currently a UI instance is passed around to all parts of shuttle allowing layers
to report messages to the user. It also provides methods ExitWithError,
ExitWithErrorCode and CheckIfError which are fatal messages stopping shuttle
completely by calling os.Exit. This makes shuttle in it self hard to test and
provides unclear exit paths of the code.

This change contains multiple changes to fix above issues.

The methods from package ui are removed and instead a checkError function is
added to package cmd which is responsible for selecting an exit code based on
the error. This greatly improvoes maintainability of the code and makes it
easier to reason about any possible exit paths from code in packages of pkg/*.

Some dead code is removed from package pkg/config. An unused CheckIfError
function was laying around here and as this change moves functionality around
related to the nature of this one I figured it was worth removing now.

During the change I found a couple of bugs in the error reporting that is fixed
as well.

When using command 'run' with invalid arguments exit code 1 indicating a shuttle
failure is reported instead of 2 indicating bad user input.

If a plan cannot be fetched due to an unknown protocol a panic is thrown. It now
returns an ExitCode error indicating bad user input.

Errors around the .shuttle directory are now also detected and propagated
instead of silently ignored.
@Crevil Crevil requested a review from a team March 22, 2021 10:31
@Crevil
Copy link
Member Author

Crevil commented Mar 22, 2021

This is a stepping stone to fix #59 by making the executor package testable.

Copy link
Member

@mahlunar mahlunar left a comment

Choose a reason for hiding this comment

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

Awesome 🚀

Copy link
Member

@kaspernissen kaspernissen left a comment

Choose a reason for hiding this comment

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

\lgtm
Great with better error handling 🙏

@Crevil Crevil merged commit 4a2ffdb into master Mar 22, 2021
@Crevil Crevil deleted the refactor/exit-paths branch March 22, 2021 11:45
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

3 participants