Skip to content

Success/error refactoring#84

Merged
febbraro merged 14 commits intodevelopfrom
feature/error-handling
Oct 26, 2017
Merged

Success/error refactoring#84
febbraro merged 14 commits intodevelopfrom
feature/error-handling

Conversation

@febbraro
Copy link
Member

@febbraro febbraro commented Oct 12, 2017

This allows us to centrally control how things get handled for success and error. It also means we don't need to config which commands provide notifications or not b/c we can just not call those or we can make cmd.Success and cmd.NotifySuccess and cmd.Error and cmd.NotifyError and that leaves it up to each command to control if it integrates with notifications or not?

@grayside
Copy link
Contributor

I like a lot about this. If a given command wants a non-default handling of the notification they can replace the relevant function.

The downside is we will need to have the Run callback for each command do something like:

if err == nil {
  return cmd.Success(...)
} else {
  return cmd.Error(...)
}

The other thing is that we should have the command name in the message, and I'd prefer not to have that explicitly set by the command, it should just be part of the command calling the notification. Can BaseCommand access the calling command name? Maybe it needs to be passed the context as well, cmd.Success(ctx, message) and cmd.Error(ctx, message, code)

@febbraro
Copy link
Member Author

I'm not sure I follow the comment about the Run callback, or really how it is different than what we do now which is cmd.out.Error.Fatal when something really bad happens, or return nil if we end in a good state.

@grayside
Copy link
Contributor

In this case, it's a very minor point that if we switch to a model where we return an error or a nil to indicate success/failure, we will first need to evaluate that err state to take one or other action.

An alternative might be:

return cmd.Complete(ctx, err, messageOnError, codeOnError)

Then the evaluation of whether this was a success or failure can be done centrally. However, I think the finer-grained control of your existing approach is better.

…en for 'docker system prune'

and project sync (next pass)
@febbraro febbraro changed the title Demonstrate success/error refactoring [WIP] Demonstrate success/error refactoring Oct 18, 2017
@febbraro
Copy link
Member Author

Did another pass, this needs to be tested, I only verified that it compiles

@grayside grayside added this to the v2.0 milestone Oct 25, 2017
@febbraro febbraro changed the title [WIP] Demonstrate success/error refactoring Demonstrate success/error refactoring Oct 25, 2017
"flag"
"github.com/phase2/rig/cli/util"
"github.com/urfave/cli"
"fmt"
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought we were loosely following:

  • system packages (alphabetical)
  • upstream packages (alphabetical)
  • custom packages (alphabetical)

Copy link
Member Author

Choose a reason for hiding this comment

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

oops, will fix.

readyConfig := &ProjectConfig{}
for _, filePath := range discovery {
if config, err := NewProjectConfigFromFile(filePath); err == nil {
if projectConfigFile != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

How did this PR sweep up the recursive config loading?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I rebased at some point, but this is weird. Maybe I will rebase on develop again just for good measure

@febbraro febbraro changed the title Demonstrate success/error refactoring Success/error refactoring Oct 25, 2017
@febbraro
Copy link
Member Author

So my rebasing has now pulled everything we have put into develop into this PR even though it is already in the target branch. Apparently I have no idea how to rebase and manage git branches. sigh

@febbraro febbraro changed the base branch from develop to master October 26, 2017 06:10
@febbraro febbraro changed the base branch from master to develop October 26, 2017 06:10
@febbraro febbraro merged commit 2f2fd16 into develop Oct 26, 2017
@febbraro febbraro deleted the feature/error-handling branch October 26, 2017 06:14
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.

2 participants