github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/hash/errors.go (about) 1 // Copyright (c) 2015-2021 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 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 Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package hash 19 20 import ( 21 "errors" 22 "fmt" 23 ) 24 25 // SHA256Mismatch - when content sha256 does not match with what was sent from client. 26 type SHA256Mismatch struct { 27 ExpectedSHA256 string 28 CalculatedSHA256 string 29 } 30 31 func (e SHA256Mismatch) Error() string { 32 return "Bad sha256: Expected " + e.ExpectedSHA256 + " does not match calculated " + e.CalculatedSHA256 33 } 34 35 // BadDigest - Content-MD5 you specified did not match what we received. 36 type BadDigest struct { 37 ExpectedMD5 string 38 CalculatedMD5 string 39 } 40 41 func (e BadDigest) Error() string { 42 return "Bad digest: Expected " + e.ExpectedMD5 + " does not match calculated " + e.CalculatedMD5 43 } 44 45 // SizeTooSmall reader size too small 46 type SizeTooSmall struct { 47 Want int64 48 Got int64 49 } 50 51 func (e SizeTooSmall) Error() string { 52 return fmt.Sprintf("Size small: got %d, want %d", e.Got, e.Want) 53 } 54 55 // SizeTooLarge reader size too large 56 type SizeTooLarge struct { 57 Want int64 58 Got int64 59 } 60 61 func (e SizeTooLarge) Error() string { 62 return fmt.Sprintf("Size large: got %d, want %d", e.Got, e.Want) 63 } 64 65 // SizeMismatch error size mismatch 66 type SizeMismatch struct { 67 Want int64 68 Got int64 69 } 70 71 func (e SizeMismatch) Error() string { 72 return fmt.Sprintf("Size mismatch: got %d, want %d", e.Got, e.Want) 73 } 74 75 // ChecksumMismatch - when content checksum does not match with what was sent from client. 76 type ChecksumMismatch struct { 77 Want string 78 Got string 79 } 80 81 func (e ChecksumMismatch) Error() string { 82 return "Bad checksum: Want " + e.Want + " does not match calculated " + e.Got 83 } 84 85 // IsChecksumMismatch matches if 'err' is hash.ChecksumMismatch 86 func IsChecksumMismatch(err error) bool { 87 var herr ChecksumMismatch 88 return errors.As(err, &herr) 89 }