convert error fromating to %w everywhere (#6995)
This commit is contained in:
@@ -178,7 +178,7 @@ func (iam *IdentityAccessManagement) LoadS3ApiConfigurationFromBytes(content []b
|
||||
s3ApiConfiguration := &iam_pb.S3ApiConfiguration{}
|
||||
if err := filer.ParseS3ConfigurationFromBytes(content, s3ApiConfiguration); err != nil {
|
||||
glog.Warningf("unmarshal error: %v", err)
|
||||
return fmt.Errorf("unmarshal error: %v", err)
|
||||
return fmt.Errorf("unmarshal error: %w", err)
|
||||
}
|
||||
|
||||
if err := filer.CheckDuplicateAccessKey(s3ApiConfiguration); err != nil {
|
||||
@@ -534,7 +534,7 @@ func (iam *IdentityAccessManagement) GetCredentialManager() *credential.Credenti
|
||||
func (iam *IdentityAccessManagement) LoadS3ApiConfigurationFromCredentialManager() error {
|
||||
s3ApiConfiguration, err := iam.credentialManager.LoadConfiguration(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to load configuration from credential manager: %v", err)
|
||||
return fmt.Errorf("failed to load configuration from credential manager: %w", err)
|
||||
}
|
||||
|
||||
if len(s3ApiConfiguration.Identities) == 0 {
|
||||
|
||||
@@ -540,7 +540,7 @@ func (s *Storage) Store(bucket string, config *CORSConfiguration) error {
|
||||
|
||||
metadataBytes, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal bucket metadata: %v", err)
|
||||
return fmt.Errorf("failed to marshal bucket metadata: %w", err)
|
||||
}
|
||||
|
||||
// Store metadata
|
||||
@@ -579,7 +579,7 @@ func (s *Storage) Load(bucket string) (*CORSConfiguration, error) {
|
||||
|
||||
var metadata map[string]interface{}
|
||||
if err := json.Unmarshal(entry.Content, &metadata); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal metadata: %v", err)
|
||||
return nil, fmt.Errorf("failed to unmarshal metadata: %w", err)
|
||||
}
|
||||
|
||||
corsData, exists := metadata["cors"]
|
||||
@@ -590,12 +590,12 @@ func (s *Storage) Load(bucket string) (*CORSConfiguration, error) {
|
||||
// Convert back to CORSConfiguration
|
||||
corsBytes, err := json.Marshal(corsData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal CORS data: %v", err)
|
||||
return nil, fmt.Errorf("failed to marshal CORS data: %w", err)
|
||||
}
|
||||
|
||||
var config CORSConfiguration
|
||||
if err := json.Unmarshal(corsBytes, &config); err != nil {
|
||||
return nil, fmt.Errorf("failed to unmarshal CORS configuration: %v", err)
|
||||
return nil, fmt.Errorf("failed to unmarshal CORS configuration: %w", err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
@@ -613,7 +613,7 @@ func (s *Storage) Delete(bucket string) error {
|
||||
var metadata map[string]interface{}
|
||||
if len(entry.Content) > 0 {
|
||||
if err := json.Unmarshal(entry.Content, &metadata); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal metadata: %v", err)
|
||||
return fmt.Errorf("failed to unmarshal metadata: %w", err)
|
||||
}
|
||||
} else {
|
||||
return nil // No metadata to delete
|
||||
@@ -624,7 +624,7 @@ func (s *Storage) Delete(bucket string) error {
|
||||
|
||||
metadataBytes, err := json.Marshal(metadata)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal metadata: %v", err)
|
||||
return fmt.Errorf("failed to marshal metadata: %w", err)
|
||||
}
|
||||
|
||||
// Update metadata
|
||||
|
||||
@@ -46,12 +46,12 @@ func NewPolicyEngine() *PolicyEngine {
|
||||
func (engine *PolicyEngine) SetBucketPolicy(bucketName string, policyJSON string) error {
|
||||
policy, err := ParsePolicy(policyJSON)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid policy: %v", err)
|
||||
return fmt.Errorf("invalid policy: %w", err)
|
||||
}
|
||||
|
||||
compiled, err := CompilePolicy(policy)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to compile policy: %v", err)
|
||||
return fmt.Errorf("failed to compile policy: %w", err)
|
||||
}
|
||||
|
||||
engine.mutex.Lock()
|
||||
|
||||
@@ -179,11 +179,11 @@ func validateStatement(stmt *PolicyStatement) error {
|
||||
func ParsePolicy(policyJSON string) (*PolicyDocument, error) {
|
||||
var policy PolicyDocument
|
||||
if err := json.Unmarshal([]byte(policyJSON), &policy); err != nil {
|
||||
return nil, fmt.Errorf("failed to parse policy JSON: %v", err)
|
||||
return nil, fmt.Errorf("failed to parse policy JSON: %w", err)
|
||||
}
|
||||
|
||||
if err := ValidatePolicy(&policy); err != nil {
|
||||
return nil, fmt.Errorf("invalid policy: %v", err)
|
||||
return nil, fmt.Errorf("invalid policy: %w", err)
|
||||
}
|
||||
|
||||
return &policy, nil
|
||||
|
||||
@@ -274,7 +274,7 @@ func (s3a *S3ApiServer) loadCORSFromMetadata(bucket string) (*cors.CORSConfigura
|
||||
var metadata map[string]json.RawMessage
|
||||
if err := json.Unmarshal(entry.Content, &metadata); err != nil {
|
||||
glog.Errorf("loadCORSFromMetadata: failed to unmarshal metadata for bucket %s: %v", bucket, err)
|
||||
return nil, fmt.Errorf("failed to unmarshal metadata: %v", err)
|
||||
return nil, fmt.Errorf("failed to unmarshal metadata: %w", err)
|
||||
}
|
||||
|
||||
corsData, exists := metadata["cors"]
|
||||
@@ -287,7 +287,7 @@ func (s3a *S3ApiServer) loadCORSFromMetadata(bucket string) (*cors.CORSConfigura
|
||||
var config cors.CORSConfiguration
|
||||
if err := json.Unmarshal(corsData, &config); err != nil {
|
||||
glog.Errorf("loadCORSFromMetadata: failed to unmarshal CORS configuration for bucket %s: %v", bucket, err)
|
||||
return nil, fmt.Errorf("failed to unmarshal CORS configuration: %v", err)
|
||||
return nil, fmt.Errorf("failed to unmarshal CORS configuration: %w", err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
|
||||
@@ -99,7 +99,7 @@ func (s3a *S3ApiServer) PutBucketHandler(w http.ResponseWriter, r *http.Request)
|
||||
IncludeNormalVolumes: true,
|
||||
}); err != nil {
|
||||
glog.Errorf("list collection: %v", err)
|
||||
return fmt.Errorf("list collections: %v", err)
|
||||
return fmt.Errorf("list collections: %w", err)
|
||||
} else {
|
||||
for _, c := range resp.Collections {
|
||||
if s3a.getCollectionName(bucket) == c.Name {
|
||||
@@ -161,7 +161,7 @@ func (s3a *S3ApiServer) PutBucketHandler(w http.ResponseWriter, r *http.Request)
|
||||
// Store the configuration as XML in extended attributes
|
||||
configXML, err := xml.Marshal(objectLockConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to marshal Object Lock configuration to XML: %v", err)
|
||||
return fmt.Errorf("failed to marshal Object Lock configuration to XML: %w", err)
|
||||
}
|
||||
|
||||
bucketConfig.Entry.Extended[s3_constants.ExtObjectLockConfigKey] = configXML
|
||||
|
||||
@@ -36,7 +36,7 @@ func NewCircuitBreaker(option *S3ApiServerOption) *CircuitBreaker {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("read S3 circuit breaker config: %v", err)
|
||||
return fmt.Errorf("read S3 circuit breaker config: %w", err)
|
||||
}
|
||||
return cb.LoadS3ApiConfigurationFromBytes(content)
|
||||
})
|
||||
@@ -52,7 +52,7 @@ func (cb *CircuitBreaker) LoadS3ApiConfigurationFromBytes(content []byte) error
|
||||
cbCfg := &s3_pb.S3CircuitBreakerConfig{}
|
||||
if err := filer.ParseS3ConfigurationFromBytes(content, cbCfg); err != nil {
|
||||
glog.Warningf("unmarshal error: %v", err)
|
||||
return fmt.Errorf("unmarshal error: %v", err)
|
||||
return fmt.Errorf("unmarshal error: %w", err)
|
||||
}
|
||||
if err := cb.loadCircuitBreakerConfig(cbCfg); err != nil {
|
||||
return err
|
||||
|
||||
@@ -497,11 +497,11 @@ func (s3a *S3ApiServer) copySingleChunk(chunk *filer_pb.FileChunk, dstPath strin
|
||||
// Download and upload the chunk
|
||||
chunkData, err := s3a.downloadChunkData(srcUrl, 0, int64(chunk.Size))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("download chunk data: %v", err)
|
||||
return nil, fmt.Errorf("download chunk data: %w", err)
|
||||
}
|
||||
|
||||
if err := s3a.uploadChunkData(chunkData, assignResult); err != nil {
|
||||
return nil, fmt.Errorf("upload chunk data: %v", err)
|
||||
return nil, fmt.Errorf("upload chunk data: %w", err)
|
||||
}
|
||||
|
||||
return dstChunk, nil
|
||||
@@ -531,11 +531,11 @@ func (s3a *S3ApiServer) copySingleChunkForRange(originalChunk, rangeChunk *filer
|
||||
// Download and upload the chunk portion
|
||||
chunkData, err := s3a.downloadChunkData(srcUrl, offsetInChunk, int64(rangeChunk.Size))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("download chunk range data: %v", err)
|
||||
return nil, fmt.Errorf("download chunk range data: %w", err)
|
||||
}
|
||||
|
||||
if err := s3a.uploadChunkData(chunkData, assignResult); err != nil {
|
||||
return nil, fmt.Errorf("upload chunk range data: %v", err)
|
||||
return nil, fmt.Errorf("upload chunk range data: %w", err)
|
||||
}
|
||||
|
||||
return dstChunk, nil
|
||||
@@ -554,7 +554,7 @@ func (s3a *S3ApiServer) assignNewVolume(dstPath string) (*filer_pb.AssignVolumeR
|
||||
Path: dstPath,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("assign volume: %v", err)
|
||||
return fmt.Errorf("assign volume: %w", err)
|
||||
}
|
||||
if resp.Error != "" {
|
||||
return fmt.Errorf("assign volume: %v", resp.Error)
|
||||
@@ -595,12 +595,12 @@ func parseRangeHeader(rangeHeader string) (startOffset, endOffset int64, err err
|
||||
|
||||
startOffset, err = strconv.ParseInt(parts[0], 10, 64)
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("invalid start offset: %v", err)
|
||||
return 0, 0, fmt.Errorf("invalid start offset: %w", err)
|
||||
}
|
||||
|
||||
endOffset, err = strconv.ParseInt(parts[1], 10, 64)
|
||||
if err != nil {
|
||||
return 0, 0, fmt.Errorf("invalid end offset: %v", err)
|
||||
return 0, 0, fmt.Errorf("invalid end offset: %w", err)
|
||||
}
|
||||
|
||||
return startOffset, endOffset, nil
|
||||
@@ -768,14 +768,14 @@ func (s3a *S3ApiServer) lookupVolumeUrl(fileId string) (string, error) {
|
||||
err := s3a.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
||||
vid, _, err := operation.ParseFileId(fileId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse file ID: %v", err)
|
||||
return fmt.Errorf("parse file ID: %w", err)
|
||||
}
|
||||
|
||||
resp, err := client.LookupVolume(context.Background(), &filer_pb.LookupVolumeRequest{
|
||||
VolumeIds: []string{vid},
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("lookup volume: %v", err)
|
||||
return fmt.Errorf("lookup volume: %w", err)
|
||||
}
|
||||
|
||||
if locations, found := resp.LocationsMap[vid]; found && len(locations.Locations) > 0 {
|
||||
@@ -787,7 +787,7 @@ func (s3a *S3ApiServer) lookupVolumeUrl(fileId string) (string, error) {
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("lookup volume URL: %v", err)
|
||||
return "", fmt.Errorf("lookup volume URL: %w", err)
|
||||
}
|
||||
return srcUrl, nil
|
||||
}
|
||||
@@ -797,7 +797,7 @@ func (s3a *S3ApiServer) setChunkFileId(chunk *filer_pb.FileChunk, assignResult *
|
||||
chunk.FileId = assignResult.FileId
|
||||
fid, err := filer_pb.ToFileIdObject(assignResult.FileId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parse file ID: %v", err)
|
||||
return fmt.Errorf("parse file ID: %w", err)
|
||||
}
|
||||
chunk.Fid = fid
|
||||
return nil
|
||||
@@ -808,13 +808,13 @@ func (s3a *S3ApiServer) prepareChunkCopy(sourceFileId, dstPath string) (*filer_p
|
||||
// Assign new volume
|
||||
assignResult, err := s3a.assignNewVolume(dstPath)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("assign volume: %v", err)
|
||||
return nil, "", fmt.Errorf("assign volume: %w", err)
|
||||
}
|
||||
|
||||
// Look up source URL
|
||||
srcUrl, err := s3a.lookupVolumeUrl(sourceFileId)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("lookup source URL: %v", err)
|
||||
return nil, "", fmt.Errorf("lookup source URL: %w", err)
|
||||
}
|
||||
|
||||
return assignResult, srcUrl, nil
|
||||
@@ -834,11 +834,11 @@ func (s3a *S3ApiServer) uploadChunkData(chunkData []byte, assignResult *filer_pb
|
||||
}
|
||||
uploader, err := operation.NewUploader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("create uploader: %v", err)
|
||||
return fmt.Errorf("create uploader: %w", err)
|
||||
}
|
||||
_, err = uploader.UploadData(context.Background(), chunkData, uploadOption)
|
||||
if err != nil {
|
||||
return fmt.Errorf("upload chunk: %v", err)
|
||||
return fmt.Errorf("upload chunk: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -851,7 +851,7 @@ func (s3a *S3ApiServer) downloadChunkData(srcUrl string, offset, size int64) ([]
|
||||
chunkData = append(chunkData, data...)
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("download chunk: %v", err)
|
||||
return nil, fmt.Errorf("download chunk: %w", err)
|
||||
}
|
||||
if shouldRetry {
|
||||
return nil, fmt.Errorf("download chunk: retry needed")
|
||||
|
||||
@@ -397,7 +397,7 @@ func (s3a *S3ApiServer) doListFilerEntries(client filer_pb.SeaweedFilerClient, d
|
||||
}
|
||||
subNextMarker, subErr := s3a.doListFilerEntries(client, dir+"/"+entry.Name, "", cursor, "", delimiter, false, eachEntryFn)
|
||||
if subErr != nil {
|
||||
err = fmt.Errorf("doListFilerEntries2: %v", subErr)
|
||||
err = fmt.Errorf("doListFilerEntries2: %w", subErr)
|
||||
return
|
||||
}
|
||||
// println("doListFilerEntries2 dir", dir+"/"+entry.Name, "subNextMarker", subNextMarker)
|
||||
|
||||
@@ -349,7 +349,7 @@ func (s3a *S3ApiServer) updateLatestVersionInDirectory(bucket, object, versionId
|
||||
versionsEntry, err := s3a.getEntry(bucketDir, versionsObjectPath)
|
||||
if err != nil {
|
||||
glog.Errorf("updateLatestVersionInDirectory: failed to get .versions entry: %v", err)
|
||||
return fmt.Errorf("failed to get .versions entry: %v", err)
|
||||
return fmt.Errorf("failed to get .versions entry: %w", err)
|
||||
}
|
||||
|
||||
// Add or update the latest version metadata
|
||||
@@ -367,7 +367,7 @@ func (s3a *S3ApiServer) updateLatestVersionInDirectory(bucket, object, versionId
|
||||
})
|
||||
if err != nil {
|
||||
glog.Errorf("updateLatestVersionInDirectory: failed to update .versions directory metadata: %v", err)
|
||||
return fmt.Errorf("failed to update .versions directory metadata: %v", err)
|
||||
return fmt.Errorf("failed to update .versions directory metadata: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -118,7 +118,7 @@ func parseXML[T any](request *http.Request, result *T) error {
|
||||
|
||||
decoder := xml.NewDecoder(request.Body)
|
||||
if err := decoder.Decode(result); err != nil {
|
||||
return fmt.Errorf("error parsing XML: %v", err)
|
||||
return fmt.Errorf("error parsing XML: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -249,7 +249,7 @@ func (s3a *S3ApiServer) getObjectEntry(bucket, object, versionId string) (*filer
|
||||
// Check if versioning is enabled
|
||||
versioningEnabled, vErr := s3a.isVersioningEnabled(bucket)
|
||||
if vErr != nil {
|
||||
return nil, fmt.Errorf("error checking versioning: %v", vErr)
|
||||
return nil, fmt.Errorf("error checking versioning: %w", vErr)
|
||||
}
|
||||
|
||||
if versioningEnabled {
|
||||
@@ -316,7 +316,7 @@ func (s3a *S3ApiServer) setObjectRetention(bucket, object, versionId string, ret
|
||||
// Check if versioning is enabled
|
||||
versioningEnabled, vErr := s3a.isVersioningEnabled(bucket)
|
||||
if vErr != nil {
|
||||
return fmt.Errorf("error checking versioning: %v", vErr)
|
||||
return fmt.Errorf("error checking versioning: %w", vErr)
|
||||
}
|
||||
|
||||
if versioningEnabled {
|
||||
@@ -427,7 +427,7 @@ func (s3a *S3ApiServer) setObjectLegalHold(bucket, object, versionId string, leg
|
||||
// Check if versioning is enabled
|
||||
versioningEnabled, vErr := s3a.isVersioningEnabled(bucket)
|
||||
if vErr != nil {
|
||||
return fmt.Errorf("error checking versioning: %v", vErr)
|
||||
return fmt.Errorf("error checking versioning: %w", vErr)
|
||||
}
|
||||
|
||||
if versioningEnabled {
|
||||
@@ -601,7 +601,7 @@ func (s3a *S3ApiServer) isObjectLockAvailable(bucket string) error {
|
||||
if errors.Is(err, filer_pb.ErrNotFound) {
|
||||
return ErrBucketNotFound
|
||||
}
|
||||
return fmt.Errorf("error checking versioning status: %v", err)
|
||||
return fmt.Errorf("error checking versioning status: %w", err)
|
||||
}
|
||||
|
||||
if !versioningEnabled {
|
||||
|
||||
@@ -104,14 +104,14 @@ func (s3a *S3ApiServer) createDeleteMarker(bucket, object string) (string, error
|
||||
entry.Extended[s3_constants.ExtDeleteMarkerKey] = []byte("true")
|
||||
})
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to create delete marker in .versions directory: %v", err)
|
||||
return "", fmt.Errorf("failed to create delete marker in .versions directory: %w", err)
|
||||
}
|
||||
|
||||
// Update the .versions directory metadata to indicate this delete marker is the latest version
|
||||
err = s3a.updateLatestVersionInDirectory(bucket, cleanObject, versionId, versionFileName)
|
||||
if err != nil {
|
||||
glog.Errorf("createDeleteMarker: failed to update latest version in directory: %v", err)
|
||||
return "", fmt.Errorf("failed to update latest version in directory: %v", err)
|
||||
return "", fmt.Errorf("failed to update latest version in directory: %w", err)
|
||||
}
|
||||
|
||||
glog.V(2).Infof("createDeleteMarker: successfully created delete marker %s for %s/%s", versionId, bucket, object)
|
||||
@@ -455,7 +455,7 @@ func (s3a *S3ApiServer) getLatestObjectVersion(bucket, object string) (*filer_pb
|
||||
// Get the .versions directory entry to read latest version metadata
|
||||
versionsEntry, err := s3a.getEntry(bucketDir, versionsObjectPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get .versions directory: %v", err)
|
||||
return nil, fmt.Errorf("failed to get .versions directory: %w", err)
|
||||
}
|
||||
|
||||
// Check if directory has latest version metadata
|
||||
|
||||
Reference in New Issue
Block a user