This topic lists the causes and solutions for some common errors you may experience when you use the OSS Go SDK.

Client errors

Call errors in Go SDK are returned through a unified error interface. The error interface is defined as follows:

type error interface {
    Error() string

Other errors are also returned through this error interface. For example, HTTP request errors are returned as follows:

type Error interface {
    Timeout() bool   // Is the error a timeout
    Temporary() bool // Is the error temporary

Server errors

If the request errors occur when OSS Go SDK is used, corresponding errors are returned. In case of HTTP request errors and I/O errors, errors preset in Go are returned. In case of request processing errors of the OSS Server, the following error is returned through the error interface:

type ServiceError struct {
    Code       string    // Error code returned by OSS to a user
    Message    string    // Error details provided by OSS
    RequestId  string    // UUID that uniquely identifies the request
    HostId     string    // OSS cluster that identifies the access
    StatusCode int       // HTTP status code

If the HTTP status code returned by OSS is not as expected, the following error is returned, also through the error interface:

type UnexpectedStatusCodeError struct {
    allowed []int    // Expected HTTP status code returned by OSS
    got     int      // Actual HTTP status code returned by OSS

Example of error handling

The following code is used to demonstrate error handling:

package main
import (
// Error handling function
func HandleError(err error) {
    fmt.Println("Error:", err)
func main() {
    // Create an OSSClient instance.
    client, err := oss.New("<yourEndpoint>", "<yourAccessKeyId>", "<yourAccessKeySecret>")
    if err != nil {
    bucketName := "<yourBucketName>"
    objectName := "<yourObjectName>"
    // Obtain the bucket.
    bucket, err := client.Bucket(bucketName)
    if err != nil {
    // Simple upload: string upload
    err = bucket.PutObject(objectName, strings.NewReader("yourObjectValueContentString"))
    if err != nil {

OSS error codes

The following table lists the OSS error codes.

Error code Description HTTP status code
AccessDenied The access is denied. 403
BucketAlreadyExists The bucket already exists. 409
BucketNotEmpty The bucket is not empty. 409
EntityTooLarge The entity is too large. 400
EntityTooSmall The entity is too small. 400
FileGroupTooLarge The object group is too large. 400
InvalidLinkName The name of the object link is the same as the linked object. 400
LinkPartNotExist The object to which the object link is linked does not exist. 400
ObjectLinkTooLarge The object link has too many objects. 400
FieldItemTooLong The table field in the post request is too large. 400
FilePartInterity The object part has been changed. 400
FilePartNotExist The object part does not exist. 400
FilePartStale The object part has expired. 400
IncorrectNumberOfFilesInPOSTRequest The number of objects in the post request is incorrect. 400
InvalidArgument The parameter format is invalid. 400
InvalidAccessKeyId The AccessKeyId does not exist. 403
InvalidBucketName The bucket name is invalid. 400
InvalidDigest The digest is invalid. 400
InvalidEncryptionAlgorithmError The specified entropy encryption algorithm is invalid. 400
InvalidObjectName The object name is invalid. 400
InvalidPart The part is invalid. 400
InvalidPartOrder The part order is invalid. 400
InvalidPolicyDocument The policy document is invalid. 400
InvalidTargetBucketForLogging A target bucket for logging is invalid. 400
InternalError An error occurs in OSS. 500
MalformedXML The XML format is invalid. 400
MalformedPOSTRequest The format of the body in the post request is invalid. 400
MaxPOSTPreDataLengthExceededError The body, except the object content, uploaded in the post request is too large. 400
MethodNotAllowed The method is not supported. 405
MissingArgument A parameter is missing. 411
MissingContentLength The content length is missing. 411
NoSuchBucket The bucket does not exist. 404
NoSuchKey The object does not exist. 404
NoSuchUpload The multipart upload ID does not exist. 404
NotImplemented The method cannot be implemented. 501
PreconditionFailed The preconditioning fails. 412
RequestTimeTooSkewed Client local time and OSS server time differ by more than 15 minutes. 403
RequestTimeout The request times out. 400
RequestIsNotMultiPartContent The content type in the post request is invalid. 400
SignatureDoesNotMatch The signature is incorrect. 403
TooManyBuckets The number of the user's buckets exceeds the limit. 400
InvalidEncryptionAlgorithmError The specified entropy encryption algorithm is invalid. 400
Note In the preceding table, the Error code is OssServiceError.Code, and the HTTP status code is OssServiceError.StatusCode.