Files
snapd/snap/errors.go
Andrew Phelps 8a7f3f2c63 o/devicestate, overlord, daemon: add flag to devicestate.Remodel to force an offline remodel (#13494)
This flag will enable offline remodeling, even when all snaps required for the remodel are not provided locally. The remodel will fall back to using already installed snaps in situations that it can. This includes simple channel switches, and when the required revision of a snap is already installed. If a snap is required for the remodel, and the snap is neither provided locally or already installed, then the remodel will fail.

* snap: add support for errors.Is for NotInstalledError

* o/snapstate: add Type to SnapSetup created in snapstate.Switch

* o/devicestate, overlord, daemon: add flag to devicestate.Remodel to force an offline remodel

This flag will enable offline remodeling, even when all snaps required
for the remodel are not provided locally. The remodel will fall back to
using already installed snaps in situations that it can. This includes
simple channel switches, and when the required revision of a snap is
already installed.

* o/devicestate: re-word comment on RemodelOptions.Offline

* o/devicestate: convert sideInfoAndPathFromID to a method on remodelVariant

* o/devicestate: make comment in UpdateWithDeviceContext more clear

* o/devicestate: add TODO about looking for other revisions

* o/devicestate: add comment explaining that case in UpdateWithDeviceContext is unexpected

* o/devicestate: prefix unexpected state error with "internal error"

* o/devicestate: use var for default initialization

* o/devicestate: invert if in UpdateWithDeviceContext to reduce some nesting

* o/devicestate: rename sideInfoAndPathFromID and add some clarifying comments

* o/devicestate: remove unused parameter from remodelEssentialSnapTasks

* o/devicestate: correct copy-pasted comment
2024-01-30 15:17:38 +01:00

67 lines
1.7 KiB
Go

// -*- 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 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)
}