git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/client/status/object.go (about)

     1  package apistatus
     2  
     3  import (
     4  	"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
     5  	"git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/status"
     6  )
     7  
     8  // ObjectLocked describes status of the failure because of the locked object.
     9  // Instances provide Status and StatusV2 interfaces.
    10  type ObjectLocked struct {
    11  	v2 status.Status
    12  }
    13  
    14  const defaultObjectLockedMsg = "object is locked"
    15  
    16  func (x *ObjectLocked) Error() string {
    17  	msg := x.v2.Message()
    18  	if msg == "" {
    19  		msg = defaultObjectLockedMsg
    20  	}
    21  
    22  	return errMessageStatusV2(
    23  		globalizeCodeV2(object.StatusLocked, object.GlobalizeFail),
    24  		msg,
    25  	)
    26  }
    27  
    28  // implements local interface defined in FromStatusV2 func.
    29  func (x *ObjectLocked) fromStatusV2(st *status.Status) {
    30  	x.v2 = *st
    31  }
    32  
    33  // ToStatusV2 implements StatusV2 interface method.
    34  // If the value was returned by FromStatusV2, returns the source message.
    35  // Otherwise, returns message with
    36  //   - code: LOCKED;
    37  //   - string message: "object is locked";
    38  //   - details: empty.
    39  func (x ObjectLocked) ToStatusV2() *status.Status {
    40  	x.v2.SetCode(globalizeCodeV2(object.StatusLocked, object.GlobalizeFail))
    41  	x.v2.SetMessage(defaultObjectLockedMsg)
    42  	return &x.v2
    43  }
    44  
    45  // LockNonRegularObject describes status returned on locking the non-regular object.
    46  // Instances provide Status and StatusV2 interfaces.
    47  type LockNonRegularObject struct {
    48  	v2 status.Status
    49  }
    50  
    51  const defaultLockNonRegularObjectMsg = "locking non-regular object is forbidden"
    52  
    53  func (x *LockNonRegularObject) Error() string {
    54  	msg := x.v2.Message()
    55  	if msg == "" {
    56  		msg = defaultLockNonRegularObjectMsg
    57  	}
    58  
    59  	return errMessageStatusV2(
    60  		globalizeCodeV2(object.StatusLockNonRegularObject, object.GlobalizeFail),
    61  		msg,
    62  	)
    63  }
    64  
    65  // implements local interface defined in FromStatusV2 func.
    66  func (x *LockNonRegularObject) fromStatusV2(st *status.Status) {
    67  	x.v2 = *st
    68  }
    69  
    70  // ToStatusV2 implements StatusV2 interface method.
    71  // If the value was returned by FromStatusV2, returns the source message.
    72  // Otherwise, returns message with
    73  //   - code: LOCK_NON_REGULAR_OBJECT;
    74  //   - string message: "locking non-regular object is forbidden";
    75  //   - details: empty.
    76  func (x LockNonRegularObject) ToStatusV2() *status.Status {
    77  	x.v2.SetCode(globalizeCodeV2(object.StatusLockNonRegularObject, object.GlobalizeFail))
    78  	x.v2.SetMessage(defaultLockNonRegularObjectMsg)
    79  	return &x.v2
    80  }
    81  
    82  // ObjectAccessDenied describes status of the failure because of the access control violation.
    83  // Instances provide Status and StatusV2 interfaces.
    84  type ObjectAccessDenied struct {
    85  	v2 status.Status
    86  }
    87  
    88  const defaultObjectAccessDeniedMsg = "access to object operation denied"
    89  
    90  func (x *ObjectAccessDenied) Error() string {
    91  	msg := x.v2.Message()
    92  	if msg == "" {
    93  		msg = defaultObjectAccessDeniedMsg
    94  	}
    95  
    96  	return errMessageStatusV2(
    97  		globalizeCodeV2(object.StatusAccessDenied, object.GlobalizeFail),
    98  		msg,
    99  	)
   100  }
   101  
   102  // implements local interface defined in FromStatusV2 func.
   103  func (x *ObjectAccessDenied) fromStatusV2(st *status.Status) {
   104  	x.v2 = *st
   105  }
   106  
   107  // ToStatusV2 implements StatusV2 interface method.
   108  // If the value was returned by FromStatusV2, returns the source message.
   109  // Otherwise, returns message with
   110  //   - code: ACCESS_DENIED;
   111  //   - string message: "access to object operation denied";
   112  //   - details: empty.
   113  func (x ObjectAccessDenied) ToStatusV2() *status.Status {
   114  	x.v2.SetCode(globalizeCodeV2(object.StatusAccessDenied, object.GlobalizeFail))
   115  	x.v2.SetMessage(defaultObjectAccessDeniedMsg)
   116  	return &x.v2
   117  }
   118  
   119  // WriteReason writes human-readable access rejection reason.
   120  func (x *ObjectAccessDenied) WriteReason(reason string) {
   121  	object.WriteAccessDeniedDesc(&x.v2, reason)
   122  }
   123  
   124  // Reason returns human-readable access rejection reason returned by the server.
   125  // Returns empty value is reason is not presented.
   126  func (x ObjectAccessDenied) Reason() string {
   127  	return object.ReadAccessDeniedDesc(x.v2)
   128  }
   129  
   130  // ObjectNotFound describes status of the failure because of the missing object.
   131  // Instances provide Status and StatusV2 interfaces.
   132  type ObjectNotFound struct {
   133  	v2 status.Status
   134  }
   135  
   136  const defaultObjectNotFoundMsg = "object not found"
   137  
   138  func (x *ObjectNotFound) Error() string {
   139  	msg := x.v2.Message()
   140  	if msg == "" {
   141  		msg = defaultObjectNotFoundMsg
   142  	}
   143  
   144  	return errMessageStatusV2(
   145  		globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail),
   146  		msg,
   147  	)
   148  }
   149  
   150  // implements local interface defined in FromStatusV2 func.
   151  func (x *ObjectNotFound) fromStatusV2(st *status.Status) {
   152  	x.v2 = *st
   153  }
   154  
   155  // ToStatusV2 implements StatusV2 interface method.
   156  // If the value was returned by FromStatusV2, returns the source message.
   157  // Otherwise, returns message with
   158  //   - code: OBJECT_NOT_FOUND;
   159  //   - string message: "object not found";
   160  //   - details: empty.
   161  func (x ObjectNotFound) ToStatusV2() *status.Status {
   162  	x.v2.SetCode(globalizeCodeV2(object.StatusNotFound, object.GlobalizeFail))
   163  	x.v2.SetMessage(defaultObjectNotFoundMsg)
   164  	return &x.v2
   165  }
   166  
   167  // ObjectAlreadyRemoved describes status of the failure because object has been
   168  // already removed. Instances provide Status and StatusV2 interfaces.
   169  type ObjectAlreadyRemoved struct {
   170  	v2 status.Status
   171  }
   172  
   173  const defaultObjectAlreadyRemovedMsg = "object already removed"
   174  
   175  func (x *ObjectAlreadyRemoved) Error() string {
   176  	msg := x.v2.Message()
   177  	if msg == "" {
   178  		msg = defaultObjectAlreadyRemovedMsg
   179  	}
   180  
   181  	return errMessageStatusV2(
   182  		globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail),
   183  		msg,
   184  	)
   185  }
   186  
   187  // implements local interface defined in FromStatusV2 func.
   188  func (x *ObjectAlreadyRemoved) fromStatusV2(st *status.Status) {
   189  	x.v2 = *st
   190  }
   191  
   192  // ToStatusV2 implements StatusV2 interface method.
   193  // If the value was returned by FromStatusV2, returns the source message.
   194  // Otherwise, returns message with
   195  //   - code: OBJECT_ALREADY_REMOVED;
   196  //   - string message: "object already removed";
   197  //   - details: empty.
   198  func (x ObjectAlreadyRemoved) ToStatusV2() *status.Status {
   199  	x.v2.SetCode(globalizeCodeV2(object.StatusAlreadyRemoved, object.GlobalizeFail))
   200  	x.v2.SetMessage(defaultObjectAlreadyRemovedMsg)
   201  	return &x.v2
   202  }
   203  
   204  // ObjectOutOfRange describes status of the failure because of the incorrect
   205  // provided object ranges.
   206  // Instances provide Status and StatusV2 interfaces.
   207  type ObjectOutOfRange struct {
   208  	v2 status.Status
   209  }
   210  
   211  const defaultObjectOutOfRangeMsg = "out of range"
   212  
   213  func (x *ObjectOutOfRange) Error() string {
   214  	msg := x.v2.Message()
   215  	if msg == "" {
   216  		msg = defaultObjectOutOfRangeMsg
   217  	}
   218  
   219  	return errMessageStatusV2(
   220  		globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail),
   221  		msg,
   222  	)
   223  }
   224  
   225  // implements local interface defined in FromStatusV2 func.
   226  func (x *ObjectOutOfRange) fromStatusV2(st *status.Status) {
   227  	x.v2 = *st
   228  }
   229  
   230  // ToStatusV2 implements StatusV2 interface method.
   231  // If the value was returned by FromStatusV2, returns the source message.
   232  // Otherwise, returns message with
   233  //   - code: OUT_OF_RANGE;
   234  //   - string message: "out of range";
   235  //   - details: empty.
   236  func (x ObjectOutOfRange) ToStatusV2() *status.Status {
   237  	x.v2.SetCode(globalizeCodeV2(object.StatusOutOfRange, object.GlobalizeFail))
   238  	x.v2.SetMessage(defaultObjectOutOfRangeMsg)
   239  	return &x.v2
   240  }