Files
snapd/store/errors.go

292 lines
8.6 KiB
Go
Raw Permalink Normal View History

2016-03-24 20:26:10 +01:00
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2014-2018 Canonical Ltd
2016-03-24 20:26:10 +01:00
*
* 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 store
import (
"errors"
"fmt"
"net/url"
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
"sort"
"strings"
2019-08-21 17:12:27 +02:00
"github.com/snapcore/snapd/snap/channel"
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
"github.com/snapcore/snapd/strutil"
2016-03-24 20:26:10 +01:00
)
var (
// ErrBadQuery is returned from Find when the query has special characters in strange places.
ErrBadQuery = errors.New("bad query")
// ErrInvalidScope is returned from Find when an invalid scope is requested.
ErrInvalidScope = errors.New("invalid scope")
2016-03-24 20:26:10 +01:00
// ErrSnapNotFound is returned when a snap can not be found
ErrSnapNotFound = errors.New("snap not found")
// ErrUnauthenticated is returned when authentication is needed to complete the query
ErrUnauthenticated = errors.New("you need to log in first")
// ErrAuthenticationNeeds2fa is returned if the authentication needs 2factor
ErrAuthenticationNeeds2fa = errors.New("two factor authentication required")
2016-03-24 20:26:10 +01:00
// Err2faFailed is returned when 2fa failed (e.g., a bad token was given)
Err2faFailed = errors.New("two factor authentication failed")
2016-03-24 20:26:10 +01:00
// ErrInvalidCredentials is returned on login error
// It can also be returned when refreshing the discharge
// macaroon if the user has changed their password.
2016-03-24 20:26:10 +01:00
ErrInvalidCredentials = errors.New("invalid credentials")
// ErrTOSNotAccepted is returned when the user has not accepted the store's terms of service.
ErrTOSNotAccepted = errors.New("terms of service not accepted")
// ErrNoPaymentMethods is returned when the user has no valid payment methods associated with their account.
ErrNoPaymentMethods = errors.New("no payment methods")
// ErrPaymentDeclined is returned when the user's payment method was declined by the upstream payment provider.
ErrPaymentDeclined = errors.New("payment declined")
// ErrLocalSnap is returned when an operation that only applies to snaps that come from a store was attempted on a local snap.
ErrLocalSnap = errors.New("cannot perform operation on local snap")
// ErrNoUpdateAvailable is returned when an update is attempetd for a snap that has no update available.
ErrNoUpdateAvailable = errors.New("snap has no updates available")
2016-03-24 20:26:10 +01:00
)
// RevisionNotAvailableError is returned when an install is attempted for a snap but the/a revision is not available (given install constraints).
type RevisionNotAvailableError struct {
Action string
Channel string
2019-08-21 17:12:27 +02:00
Releases []channel.Channel
}
func (e *RevisionNotAvailableError) Error() string {
return "no snap revision available as specified"
}
// DownloadError represents a download error
type DownloadError struct {
2016-03-24 20:26:10 +01:00
Code int
URL *url.URL
}
func (e *DownloadError) Error() string {
2016-03-24 20:26:10 +01:00
return fmt.Sprintf("received an unexpected http response code (%v) when trying to download %s", e.Code, e.URL)
}
// PasswordPolicyError is returned in a few corner cases, most notably
// when the password has been force-reset.
type PasswordPolicyError map[string]stringList
func (e PasswordPolicyError) Error() string {
var msg string
if reason, ok := e["reason"]; ok && len(reason) == 1 {
msg = reason[0]
if location, ok := e["location"]; ok && len(location) == 1 {
msg += "\nTo address this, go to: " + location[0] + "\n"
}
} else {
for k, vs := range e {
msg += fmt.Sprintf("%s: %s\n", k, strings.Join(vs, " "))
}
}
return msg
}
// InvalidAuthDataError signals that the authentication data didn't pass validation.
type InvalidAuthDataError map[string]stringList
func (e InvalidAuthDataError) Error() string {
var es []string
for _, v := range e {
es = append(es, v...)
}
// XXX: confirm with server people that extra args are all
// full sentences (with periods and capitalization)
// (empirically this checks out)
return strings.Join(es, " ")
}
// SnapActionError conveys errors that were reported on otherwise overall successful snap action (install/refresh) request.
type SnapActionError struct {
2020-09-27 23:38:17 +02:00
// NoResults is set if there were no results in the response
NoResults bool
// Refresh errors by snap name.
Refresh map[string]error
// Install errors by snap name.
Install map[string]error
// Download errors by snap name.
Download map[string]error
// Other errors.
Other []error
}
// SingleOpError returns the single operation, snap name, and error if
// e represents a single error of a single operation on a single snap
// (i.e. if e.Other is empty, and e.Refresh, e.Install and e.Download
// have a single error in total).
// In any other case, the error returned will be nil.
func (e SnapActionError) SingleOpError() (op, name string, err error) {
if len(e.Other) > 0 {
return "", "", nil
}
nRefresh := len(e.Refresh)
nInstall := len(e.Install)
nDownload := len(e.Download)
if nRefresh+nInstall+nDownload != 1 {
return "", "", nil
}
var errs map[string]error
switch {
case nRefresh > 0:
op = "refresh"
errs = e.Refresh
case nInstall > 0:
op = "install"
errs = e.Install
case nDownload > 0:
op = "download"
errs = e.Download
}
for name, err = range errs {
return op, name, err
}
// can't happen
return "", "", nil
}
func (e SnapActionError) Error() string {
nRefresh := len(e.Refresh)
nInstall := len(e.Install)
nDownload := len(e.Download)
nOther := len(e.Other)
// single error
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
switch nRefresh + nInstall + nDownload + nOther {
case 0:
if e.NoResults {
// this is an atypical result
return "no install/refresh information results from the store"
}
case 1:
if nOther == 0 {
op, name, err := e.SingleOpError()
return fmt.Sprintf("cannot %s snap %q: %v", op, name, err)
} else {
return fmt.Sprintf("cannot refresh, install, or download: %v", e.Other[0])
}
}
header := "cannot refresh, install, or download:"
if nOther == 0 {
// at least one of nDownload, nInstall, or nRefresh is > 0
switch {
case nDownload == 0 && nRefresh == 0:
header = "cannot install:"
case nDownload == 0 && nInstall == 0:
header = "cannot refresh:"
case nRefresh == 0 && nInstall == 0:
header = "cannot download:"
case nDownload == 0:
header = "cannot refresh or install:"
case nInstall == 0:
header = "cannot refresh or download:"
case nRefresh == 0:
header = "cannot install or download:"
}
}
// reverse the "snap->error" map to "error->snap", as the
// common case is that all snaps fail with the same error
// (e.g. "no refresh available")
errToSnaps := map[string][]string{}
errKeys := []string{} // poorman's ordered map
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
for _, m := range []map[string]error{e.Refresh, e.Install, e.Download} {
for snapName, err := range m {
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
k := err.Error()
v, ok := errToSnaps[k]
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
if !ok {
errKeys = append(errKeys, k)
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
}
errToSnaps[k] = append(v, snapName)
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
}
}
es := make([]string, 1, 1+len(errToSnaps)+nOther)
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
es[0] = header
for _, k := range errKeys {
sort.Strings(errToSnaps[k])
es = append(es, fmt.Sprintf("%s: %s", k, strutil.Quoted(errToSnaps[k])))
}
for _, e := range e.Other {
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
es = append(es, e.Error())
}
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
if len(es) == 2 {
// header + 1 reason
return strings.Join(es, " ")
}
store: be less verbose in the common refresh case of "no updates" Before this change, every snap refresh would log, even without DEBUG, something like: Jul 17 08:03:16 fleet snapd[4819]: 2018/07/17 08:03:16.096014 storehelpers.go:398: cannot refresh: Jul 17 08:03:16 fleet snapd[4819]: snap "bofh": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "interdenominational-counterintelligences": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shellcheck": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "unifonter": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "hello-world": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "wethr": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "cavestory": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "nethack": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "tmnationsforever": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "flare-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xbill-xaw": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "quake-shareware": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "telegram-desktop": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "bash-shell-rpg": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "go": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "shattered-pixel-dungeon": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "xonotic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "youtube-dl-casept": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "mosaic": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "spotify": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "firefox": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "http": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "minecraft": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "vlc": snap has no updates available Jul 17 08:03:16 fleet snapd[4819]: snap "test-snapd-tools": snap has no updates available this change turns things around, and instead you'll get Jul 17 16:02:49 fleet snapd[5123]: 2018/07/19 16:02:49.310941 storehelpers.go:398: cannot refresh: snap has no updates available: "atom", "bash-shell-rpg", "cavestory", "core", "firefox", "flare-rpg", "gnome-3-26-1604", "gnome-calculator", "go", "gtk-common-themes", "hello-world", "http", "interdenominational-counterintelligences", "minecraft", "mosaic", "nethack", "quake-shareware", "shattered-pixel-dungeon", "shellcheck", "spotify", "telegram-desktop", "test-snapd-tools", "tmnationsforever", "unifonter", "vlc", "wethr", "xbill-xaw", "xonotic", "youtube-dl-casept" which is IMHO better. It still goes multi-line if there's more than one "kind" of error (still reversed, “error message: quoted list of snaps”, though).
2018-07-19 16:16:52 +01:00
return strings.Join(es, "\n")
}
// Authorization soft-expiry errors that get handled automatically.
var (
errUserAuthorizationNeedsRefresh = errors.New("soft-expired user authorization needs refresh")
errDeviceAuthorizationNeedsRefresh = errors.New("soft-expired device authorization needs refresh")
)
2019-08-21 17:12:27 +02:00
func translateSnapActionError(action, snapChannel, code, message string, releases []snapRelease) error {
switch code {
case "revision-not-found":
e := &RevisionNotAvailableError{
Action: action,
2019-08-21 17:12:27 +02:00
Channel: snapChannel,
}
if len(releases) != 0 {
2019-08-21 17:12:27 +02:00
parsedReleases := make([]channel.Channel, len(releases))
for i := 0; i < len(releases); i++ {
var err error
2019-08-21 17:12:27 +02:00
parsedReleases[i], err = channel.Parse(releases[i].Channel, releases[i].Architecture)
if err != nil {
// shouldn't happen, return error without Releases
return e
}
}
e.Releases = parsedReleases
}
return e
case "id-not-found", "name-not-found":
return ErrSnapNotFound
case "user-authorization-needs-refresh":
return errUserAuthorizationNeedsRefresh
case "device-authorization-needs-refresh":
return errDeviceAuthorizationNeedsRefresh
default:
return fmt.Errorf("%v", message)
}
}