github.com/hasnat/dolt/go@v0.0.0-20210628190320-9eb5d843fbb7/store/blobstore/errors.go (about) 1 // Copyright 2019 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package blobstore 16 17 // NotFound is an error type used only when a key is not found in a Blobstore. 18 type NotFound struct { 19 Key string 20 } 21 22 // Error returns the key which was not found 23 func (nf NotFound) Error() string { 24 return "Blob not found: " + nf.Key 25 } 26 27 // IsNotFoundError is a helper method used to determine if returned errors resulted 28 // because the key didn't exist as opposed to something going wrong. 29 func IsNotFoundError(err error) bool { 30 _, ok := err.(NotFound) 31 32 return ok 33 } 34 35 // CheckAndPutError is an error type used when CheckAndPut fails because of a version 36 // mismatch. 37 type CheckAndPutError struct { 38 Key string 39 ExpectedVersion string 40 ActualVersion string 41 } 42 43 // Error (Required method of error) returns an error message for debugging 44 func (err CheckAndPutError) Error() string { 45 return "Blob: \"" + err.Key + "\" expected: \"" + err.ExpectedVersion + "\" actual: \"" + err.ActualVersion + "\"" 46 } 47 48 // IsCheckAndPutError is a helper method used to determine if CheckAndPut errors 49 // resulted because of version mismatches (Which happens when you have multiple) 50 // writers of a blob with a given key. 51 func IsCheckAndPutError(err error) bool { 52 _, ok := err.(CheckAndPutError) 53 54 return ok 55 }