Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions pkg/catalog_next/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package catalognext

import (
"context"
"errors"
"fmt"
"time"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote/transport"

"github.com/docker/mcp-gateway/pkg/db"
"github.com/docker/mcp-gateway/pkg/oci"
Expand Down Expand Up @@ -41,6 +43,9 @@ func pullCatalog(ctx context.Context, dao db.DAO, ociService oci.Service, refStr

catalogArtifact, err := oci.ReadArtifact[CatalogArtifact](refStr, MCPCatalogArtifactType)
if err != nil {
if isNotFoundError(err) {
return nil, fmt.Errorf("catalog not found: %s", refStr)
}
return nil, fmt.Errorf("failed to read OCI catalog: %w", err)
}

Expand Down Expand Up @@ -88,3 +93,18 @@ func pullCatalog(ctx context.Context, dao db.DAO, ociService oci.Service, refStr

return &dbCatalog, nil
}

// isNotFoundError checks if the error is an OCI registry "not found" response
// (MANIFEST_UNKNOWN or NAME_UNKNOWN).
func isNotFoundError(err error) bool {
var transportErr *transport.Error
if !errors.As(err, &transportErr) {
return false
}
for _, diagnostic := range transportErr.Errors {
if diagnostic.Code == transport.ManifestUnknownErrorCode || diagnostic.Code == transport.NameUnknownErrorCode {
return true
}
}
return false
}
63 changes: 63 additions & 0 deletions pkg/catalog_next/pull_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package catalognext

import (
"fmt"
"net/http"
"testing"

"github.com/google/go-containerregistry/pkg/v1/remote/transport"
"github.com/stretchr/testify/assert"
)

func TestIsNotFoundError(t *testing.T) {
tests := []struct {
name string
err error
expected bool
}{
{
name: "manifest unknown",
err: &transport.Error{Errors: []transport.Diagnostic{{Code: transport.ManifestUnknownErrorCode}}},
expected: true,
},
{
name: "name unknown",
err: &transport.Error{Errors: []transport.Diagnostic{{Code: transport.NameUnknownErrorCode}}},
expected: true,
},
{
name: "wrapped manifest unknown",
err: fmt.Errorf("fetch failed: %w", &transport.Error{Errors: []transport.Diagnostic{{Code: transport.ManifestUnknownErrorCode}}}),
expected: true,
},
{
name: "unauthorized error",
err: &transport.Error{Errors: []transport.Diagnostic{{Code: transport.UnauthorizedErrorCode}}},
expected: false,
},
{
name: "non-transport error",
err: fmt.Errorf("network timeout"),
expected: false,
},
{
name: "transport error with no diagnostics",
err: &transport.Error{StatusCode: http.StatusNotFound},
expected: false,
},
{
name: "multiple diagnostics with one match",
err: &transport.Error{Errors: []transport.Diagnostic{
{Code: transport.UnauthorizedErrorCode},
{Code: transport.ManifestUnknownErrorCode},
}},
expected: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, isNotFoundError(tt.err))
})
}
}
Loading