github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/s3select/csv/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 csv
    19  
    20  import "errors"
    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 errCSVParsingError(err error) *s3Error {
    50  	return &s3Error{
    51  		code:       "CSVParsingError",
    52  		message:    "Encountered an error parsing the CSV file. Check the file and try again.",
    53  		statusCode: 400,
    54  		cause:      err,
    55  	}
    56  }
    57  
    58  func errInvalidTextEncodingError() *s3Error {
    59  	return &s3Error{
    60  		code:       "InvalidTextEncoding",
    61  		message:    "UTF-8 encoding is required.",
    62  		statusCode: 400,
    63  		cause:      errors.New("invalid utf8 encoding"),
    64  	}
    65  }