github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/overlord/snapstate/policy/errors.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2019 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package policy 21 22 import ( 23 "errors" 24 "strconv" 25 "strings" 26 ) 27 28 var ( 29 errNoName = errors.New("snap has no name (not installed?)") 30 errInUseForBoot = errors.New("snap is being used for boot") 31 errRequired = errors.New("snap is required") 32 errIsModel = errors.New("snap is used by the model") 33 34 errSnapdNotRemovableOnCore = errors.New("snapd required on core devices") 35 errSnapdNotYetRemovableOnClassic = errors.New("remove all other snaps first") 36 37 errEphemeralSnapsNotRemovalable = errors.New("no snaps are removable in any of the ephemeral modes") 38 ) 39 40 type inUseByErr []string 41 42 func (e inUseByErr) Error() string { 43 switch len(e) { 44 case 0: 45 // how 46 return "snap is being used" 47 case 1: 48 return "snap is being used by snap " + e[0] + "." 49 case 2, 3, 4, 5: 50 return "snap is being used by snaps " + strings.Join(e[:len(e)-1], ", ") + " and " + e[len(e)-1] + "." 51 default: 52 return "snap is being used by snaps " + strings.Join(e[:5], ", ") + " and " + strconv.Itoa(len(e)-5) + " more." 53 } 54 }