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:
@@ -32,7 +32,7 @@ func TestManifestPushByTag(t *testing.T) {
|
||||
fdb.addGlobalBlob("sha256:config1")
|
||||
fdb.addGlobalBlob("sha256:layer1")
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
content := makeManifest("sha256:config1", []string{"sha256:layer1"})
|
||||
@@ -79,7 +79,7 @@ func TestManifestPushByDigest(t *testing.T) {
|
||||
fdb.addRepo("myrepo", 1)
|
||||
fdb.addGlobalBlob("sha256:config1")
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
content := makeManifest("sha256:config1", nil)
|
||||
@@ -107,7 +107,7 @@ func TestManifestPushDigestMismatch(t *testing.T) {
|
||||
fdb := newFakeDB()
|
||||
fdb.addRepo("myrepo", 1)
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
content := []byte(`{"schemaVersion":2}`)
|
||||
@@ -137,7 +137,7 @@ func TestManifestPushMissingBlob(t *testing.T) {
|
||||
// Config blob exists but layer blob does not.
|
||||
fdb.addGlobalBlob("sha256:config1")
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
content := makeManifest("sha256:config1", []string{"sha256:missing_layer"})
|
||||
@@ -164,7 +164,7 @@ func TestManifestPushMalformed(t *testing.T) {
|
||||
fdb := newFakeDB()
|
||||
fdb.addRepo("myrepo", 1)
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedPushRequest("PUT", "/v2/myrepo/manifests/latest", []byte("not valid json"))
|
||||
@@ -189,7 +189,7 @@ func TestManifestPushEmpty(t *testing.T) {
|
||||
fdb := newFakeDB()
|
||||
fdb.addRepo("myrepo", 1)
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
req := authedPushRequest("PUT", "/v2/myrepo/manifests/latest", nil)
|
||||
@@ -207,7 +207,7 @@ func TestManifestPushUpdatesTag(t *testing.T) {
|
||||
fdb.addRepo("myrepo", 1)
|
||||
fdb.addGlobalBlob("sha256:config1")
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
// First push with tag "latest".
|
||||
@@ -248,7 +248,7 @@ func TestManifestPushRepushIdempotent(t *testing.T) {
|
||||
fdb.addRepo("myrepo", 1)
|
||||
fdb.addGlobalBlob("sha256:config1")
|
||||
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil)
|
||||
h := NewHandler(fdb, newFakeBlobs(), allowAll(), nil, nil)
|
||||
router := testRouter(h)
|
||||
|
||||
content := makeManifest("sha256:config1", nil)
|
||||
|
||||
Reference in New Issue
Block a user