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

snap: do exit 0 on install/remove if that snap is already installed or already removed #2292

Merged
merged 9 commits into from Nov 24, 2016

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented Nov 17, 2016

LP: #1622782

@mvo5 mvo5 force-pushed the bugfix/no-error-if-already-installed branch from ac06fdd to 6d28db7 Compare November 17, 2016 10:12
@jacekn
Copy link

jacekn commented Nov 17, 2016

This PR does not address root cause of the problem in LP: #1622782

It will allow for another way to detect "snap already installed" failure (using exit code rather than string) but calls like this will still cause traceback:
subprocess.check_call(["snap", "insatll", "snapname"])

The least surprising behaviour is that of apt - if package is already installed let user know and exit with code 0

@mvo5 mvo5 changed the title snap: do exit 1 if a snap that is already installed is asked to be installed again snap: do exit 0 if a snap that is already installed is asked to be installed again (instead of exit 1) Nov 17, 2016
@mvo5
Copy link
Contributor Author

mvo5 commented Nov 17, 2016

@jacekn Silly me, the title of the PR was wrong. The goal is to have subprocess.check_call(["snap", "install", "already-installed-snap"]) not fail, the code should return cleanly (exit 0).

@mvo5 mvo5 changed the title snap: do exit 0 if a snap that is already installed is asked to be installed again (instead of exit 1) snap: do exit 0 on install/remove if that snap is already installed or already removed Nov 18, 2016
@mvo5 mvo5 force-pushed the bugfix/no-error-if-already-installed branch from f94448a to 68e4d5a Compare November 18, 2016 10:11
@mvo5 mvo5 added this to the 2.18 milestone Nov 24, 2016
Copy link
Collaborator

@zyga zyga left a comment

Choose a reason for hiding this comment

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

A much welcome improvement. I've added a few comments but I don't think any of them block this.

@@ -971,6 +971,40 @@ func (inst *snapInstruction) dispatch() snapActionFunc {
return snapInstructionDispTable[inst.Action]
}

func (inst *snapInstruction) errToResponse(err error) Response {
if _, ok := err.(*snap.AlreadyInstalledError); ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

A switch on the type would feel nicer here but you don't have to change it now.

}

func (e AlreadyInstalledError) Error() string {
return fmt.Sprintf("snap %q is already installed", e.Snap)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps a place to add i18n (later)

}

type NotInstalledError struct {
Snap string
Copy link
Collaborator

Choose a reason for hiding this comment

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

SnapRef ;-)

Rev Revision
}

func (e NotInstalledError) Error() string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice :)

@chipaca chipaca merged commit e0dae61 into snapcore:master Nov 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants