Browse Source

s3tables: add error handling for json.Marshal calls

- Add error handling in handler_namespace.go (metadata marshaling)
- Add error handling in handler_table.go (metadata and tags marshaling)
- Add error handling in handler_policy.go (tag marshaling in TagResource and UntagResource)
- Return proper errors with context instead of silently ignoring failures
pull/8147/head
Chris Lu 3 days ago
parent
commit
ef3873b616
  1. 6
      weed/s3api/s3tables/handler_namespace.go
  2. 12
      weed/s3api/s3tables/handler_policy.go
  3. 11
      weed/s3api/s3tables/handler_table.go

6
weed/s3api/s3tables/handler_namespace.go

@ -81,7 +81,11 @@ func (h *S3TablesHandler) handleCreateNamespace(w http.ResponseWriter, r *http.R
OwnerID: h.accountID,
}
metadataBytes, _ := json.Marshal(metadata)
metadataBytes, err := json.Marshal(metadata)
if err != nil {
h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, "failed to marshal namespace metadata")
return fmt.Errorf("failed to marshal metadata: %w", err)
}
err = filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
// Create namespace directory

12
weed/s3api/s3tables/handler_policy.go

@ -297,7 +297,11 @@ func (h *S3TablesHandler) handleTagResource(w http.ResponseWriter, r *http.Reque
}
// Write merged tags
tagsBytes, _ := json.Marshal(existingTags)
tagsBytes, err := json.Marshal(existingTags)
if err != nil {
h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, "failed to marshal tags")
return fmt.Errorf("failed to marshal tags: %w", err)
}
err = filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
return h.setExtendedAttribute(client, resourcePath, extendedKey, tagsBytes)
})
@ -387,7 +391,11 @@ func (h *S3TablesHandler) handleUntagResource(w http.ResponseWriter, r *http.Req
}
// Write updated tags
tagsBytes, _ := json.Marshal(tags)
tagsBytes, err := json.Marshal(tags)
if err != nil {
h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, "failed to marshal tags")
return fmt.Errorf("failed to marshal tags: %w", err)
}
err = filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
return h.setExtendedAttribute(client, resourcePath, extendedKey, tagsBytes)
})

11
weed/s3api/s3tables/handler_table.go

@ -101,7 +101,11 @@ func (h *S3TablesHandler) handleCreateTable(w http.ResponseWriter, r *http.Reque
Schema: req.Metadata,
}
metadataBytes, _ := json.Marshal(metadata)
metadataBytes, err := json.Marshal(metadata)
if err != nil {
h.writeError(w, http.StatusInternalServerError, ErrCodeInternalError, "failed to marshal table metadata")
return fmt.Errorf("failed to marshal metadata: %w", err)
}
err = filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
// Create table directory
@ -122,7 +126,10 @@ func (h *S3TablesHandler) handleCreateTable(w http.ResponseWriter, r *http.Reque
// Set tags if provided
if len(req.Tags) > 0 {
tagsBytes, _ := json.Marshal(req.Tags)
tagsBytes, err := json.Marshal(req.Tags)
if err != nil {
return fmt.Errorf("failed to marshal tags: %w", err)
}
if err := h.setExtendedAttribute(client, tablePath, ExtendedKeyTags, tagsBytes); err != nil {
return err
}

Loading…
Cancel
Save