Add structured error logging to OCI handlers
Every 500 response in the OCI package silently discarded the actual error, making production debugging impossible. Add slog.Error before each 500 response with the error and relevant context (repo, digest, tag, uuid). Add slog.Info for state-mutating successes (manifest push, blob upload complete, deletions). Logger is injected into the OCI Handler via constructor, falling back to slog.Default() if nil. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ func TestManifestDeleteByDigest(t *testing.T) {
|
||||
content := []byte(`{"schemaVersion":2}`)
|
||||
fdb.addManifest(1, "latest", "sha256:aaaa", "application/vnd.oci.image.manifest.v1+json", content)
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedRequest("DELETE", "/v2/myrepo/manifests/sha256:aaaa", nil)
|
||||
@@ -37,7 +37,7 @@ func TestManifestDeleteByTagUnsupported(t *testing.T) {
|
||||
content := []byte(`{"schemaVersion":2}`)
|
||||
fdb.addManifest(1, "latest", "sha256:aaaa", "application/vnd.oci.image.manifest.v1+json", content)
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedRequest("DELETE", "/v2/myrepo/manifests/latest", nil)
|
||||
@@ -62,7 +62,7 @@ func TestManifestDeleteNotFound(t *testing.T) {
|
||||
fdb.addRepo("myrepo", 1)
|
||||
// No manifests added.
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedRequest("DELETE", "/v2/myrepo/manifests/sha256:nonexistent", nil)
|
||||
@@ -85,7 +85,7 @@ func TestManifestDeleteNotFound(t *testing.T) {
|
||||
func TestManifestDeleteRepoNotFound(t *testing.T) {
|
||||
fdb := newFakeDB()
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedRequest("DELETE", "/v2/nosuchrepo/manifests/sha256:aaaa", nil)
|
||||
@@ -111,7 +111,7 @@ func TestManifestDeleteCascadesTag(t *testing.T) {
|
||||
content := []byte(`{"schemaVersion":2}`)
|
||||
fdb.addManifest(1, "latest", "sha256:aaaa", "application/vnd.oci.image.manifest.v1+json", content)
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedRequest("DELETE", "/v2/myrepo/manifests/sha256:aaaa", nil)
|
||||
@@ -134,7 +134,7 @@ func TestBlobDelete(t *testing.T) {
|
||||
fdb.addRepo("myrepo", 1)
|
||||
fdb.addBlob(1, "sha256:b1")
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedRequest("DELETE", "/v2/myrepo/blobs/sha256:b1", nil)
|
||||
@@ -157,7 +157,7 @@ func TestBlobDeleteNotInRepo(t *testing.T) {
|
||||
fdb.addRepo("myrepo", 1)
|
||||
// Blob not added to this repo.
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedRequest("DELETE", "/v2/myrepo/blobs/sha256:nonexistent", nil)
|
||||
@@ -180,7 +180,7 @@ func TestBlobDeleteNotInRepo(t *testing.T) {
|
||||
func TestBlobDeleteRepoNotFound(t *testing.T) {
|
||||
fdb := newFakeDB()
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedRequest("DELETE", "/v2/nosuchrepo/blobs/sha256:b1", nil)
|
||||
|
||||
Reference in New Issue
Block a user