github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/s3select/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 s3select 19 20 import "strings" 21 22 // SelectError - represents s3 select error specified in 23 // https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectSELECTContent.html#RESTObjectSELECTContent-responses-special-errors. 24 type SelectError interface { 25 Cause() error 26 ErrorCode() string 27 ErrorMessage() string 28 HTTPStatusCode() int 29 Error() string 30 } 31 32 type s3Error struct { 33 code string 34 message string 35 statusCode int 36 cause error 37 } 38 39 func (err *s3Error) Cause() error { 40 return err.cause 41 } 42 43 func (err *s3Error) ErrorCode() string { 44 return err.code 45 } 46 47 func (err *s3Error) ErrorMessage() string { 48 return err.message 49 } 50 51 func (err *s3Error) HTTPStatusCode() int { 52 return err.statusCode 53 } 54 55 func (err *s3Error) Error() string { 56 return err.message 57 } 58 59 func errMalformedXML(err error) *s3Error { 60 return &s3Error{ 61 code: "MalformedXML", 62 message: "The XML provided was not well-formed or did not validate against our published schema. Check the service documentation and try again: " + err.Error(), 63 statusCode: 400, 64 cause: err, 65 } 66 } 67 68 func errInvalidCompressionFormat(err error) *s3Error { 69 return &s3Error{ 70 code: "InvalidCompressionFormat", 71 message: "The file is not in a supported compression format. GZIP, BZIP2, ZSTD, LZ4, S2 and SNAPPY are supported.", 72 statusCode: 400, 73 cause: err, 74 } 75 } 76 77 func errInvalidCompression(err error, t CompressionType) *s3Error { 78 return &s3Error{ 79 code: "InvalidCompressionFormat", 80 message: strings.ToUpper(string(t)) + " is not applicable to the queried object. Please correct the request and try again.", 81 statusCode: 400, 82 cause: err, 83 } 84 } 85 86 func errInvalidDataSource(err error) *s3Error { 87 return &s3Error{ 88 code: "InvalidDataSource", 89 message: "Invalid data source type. Only CSV, JSON, and Parquet are supported.", 90 statusCode: 400, 91 cause: err, 92 } 93 } 94 95 func errInvalidRequestParameter(err error) *s3Error { 96 return &s3Error{ 97 code: "InvalidRequestParameter", 98 message: "The value of a parameter in SelectRequest element is invalid. Check the service API documentation and try again.", 99 statusCode: 400, 100 cause: err, 101 } 102 } 103 104 func errInvalidScanRangeParameter(err error) *s3Error { 105 return &s3Error{ 106 code: "InvalidRequestParameter", 107 message: "The value of a parameter in ScanRange element is invalid. Check the service API documentation and try again.", 108 statusCode: 400, 109 cause: err, 110 } 111 } 112 113 func errObjectSerializationConflict(err error) *s3Error { 114 return &s3Error{ 115 code: "ObjectSerializationConflict", 116 message: "InputSerialization specifies more than one format (CSV, JSON, or Parquet), or OutputSerialization specifies more than one format (CSV or JSON). InputSerialization and OutputSerialization can only specify one format each.", 117 statusCode: 400, 118 cause: err, 119 } 120 } 121 122 func errInvalidExpressionType(err error) *s3Error { 123 return &s3Error{ 124 code: "InvalidExpressionType", 125 message: "The ExpressionType is invalid. Only SQL expressions are supported.", 126 statusCode: 400, 127 cause: err, 128 } 129 } 130 131 func errMissingRequiredParameter(err error) *s3Error { 132 return &s3Error{ 133 code: "MissingRequiredParameter", 134 message: "The SelectRequest entity is missing a required parameter. Check the service documentation and try again.", 135 statusCode: 400, 136 cause: err, 137 } 138 } 139 140 func errTruncatedInput(err error) *s3Error { 141 return &s3Error{ 142 code: "TruncatedInput", 143 message: "Object decompression failed. Check that the object is properly compressed using the format specified in the request.", 144 statusCode: 400, 145 cause: err, 146 } 147 }