github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/s3select/sql/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 sql 19 20 import "fmt" 21 22 type s3Error struct { 23 code string 24 message string 25 statusCode int 26 cause error 27 } 28 29 func (err *s3Error) Cause() error { 30 return err.cause 31 } 32 33 func (err *s3Error) ErrorCode() string { 34 return err.code 35 } 36 37 func (err *s3Error) ErrorMessage() string { 38 return err.message 39 } 40 41 func (err *s3Error) HTTPStatusCode() int { 42 return err.statusCode 43 } 44 45 func (err *s3Error) Error() string { 46 return err.message 47 } 48 49 func errInvalidDataType(err error) *s3Error { 50 return &s3Error{ 51 code: "InvalidDataType", 52 message: "The SQL expression contains an invalid data type.", 53 statusCode: 400, 54 cause: err, 55 } 56 } 57 58 func errIncorrectSQLFunctionArgumentType(err error) *s3Error { 59 return &s3Error{ 60 code: "IncorrectSqlFunctionArgumentType", 61 message: "Incorrect type of arguments in function call.", 62 statusCode: 400, 63 cause: err, 64 } 65 } 66 67 func errLikeInvalidInputs(err error) *s3Error { 68 return &s3Error{ 69 code: "LikeInvalidInputs", 70 message: "Invalid argument given to the LIKE clause in the SQL expression.", 71 statusCode: 400, 72 cause: err, 73 } 74 } 75 76 func errQueryParseFailure(err error) *s3Error { 77 return &s3Error{ 78 code: "ParseSelectFailure", 79 message: err.Error(), 80 statusCode: 400, 81 cause: err, 82 } 83 } 84 85 func errQueryAnalysisFailure(err error) *s3Error { 86 return &s3Error{ 87 code: "InvalidQuery", 88 message: err.Error(), 89 statusCode: 400, 90 cause: err, 91 } 92 } 93 94 func errBadTableName(err error) *s3Error { 95 return &s3Error{ 96 code: "BadTableName", 97 message: fmt.Sprintf("The table name is not supported: %v", err), 98 statusCode: 400, 99 cause: err, 100 } 101 } 102 103 func errDataSource(err error) *s3Error { 104 return &s3Error{ 105 code: "DataSourcePathUnsupported", 106 message: fmt.Sprintf("Data source: %v", err), 107 statusCode: 400, 108 cause: err, 109 } 110 }