1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2014-2016 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package snap
import (
"fmt"
)
type AlreadyInstalledError struct {
Snap string
}
func (e AlreadyInstalledError) Error() string {
return fmt.Sprintf("snap %q is already installed", e.Snap)
}
type AlreadyInstalledComponentError struct {
Component string
}
func (e AlreadyInstalledComponentError) Error() string {
return fmt.Sprintf("component %q is already installed", e.Component)
}
type NotInstalledError struct {
Snap string
Rev Revision
}
func (e NotInstalledError) Error() string {
if e.Rev.Unset() {
return fmt.Sprintf("snap %q is not installed", e.Snap)
}
return fmt.Sprintf("revision %s of snap %q is not installed", e.Rev, e.Snap)
}
func (e *NotInstalledError) Is(err error) bool {
_, ok := err.(*NotInstalledError)
return ok
}
// NotSnapError is returned if an operation expects a snap file or snap dir
// but no valid input is provided. When creating it ensure "Err" is set
// so that a useful error can be displayed to the user.
type NotSnapError struct {
Path string
Err error
}
func (e NotSnapError) Error() string {
// e.Err should always be set but support if not
if e.Err == nil {
return fmt.Sprintf("cannot process snap or snapdir %q", e.Path)
}
return fmt.Sprintf("cannot process snap or snapdir: %v", e.Err)
}
// ComponentNotInstalledError is used when a component is not in the
// system while trying to manage it.
type ComponentNotInstalledError struct {
NotInstalledError
Component string
CompRev Revision
}
func (e ComponentNotInstalledError) Error() string {
if e.CompRev.Unset() {
return fmt.Sprintf("component %q is not installed for revision %s of snap %q",
e.Component, e.Rev, e.Snap)
}
return fmt.Sprintf("revision %s of component %q is not installed for revision %s of snap %q",
e.CompRev, e.Component, e.Rev, e.Snap)
}
|