<commit_before>package registry

import (
	"context"
	"encoding/json"
	"fmt"
	"net/http"
	"time"

	"github.com/go-kit/kit/log"
	dockerregistry "github.com/heroku/docker-registry-client/registry"
	"github.com/pkg/errors"

	"github.com/weaveworks/flux"
	"github.com/weaveworks/flux/registry/cache"
)

// A client represents an entity that returns manifest and tags
// information.  It might be a cache, it might be a real registry.
type Client interface {
	Tags(id flux.ImageID) ([]string, error)
	Manifest(id flux.ImageID) (flux.Image, error)
	Cancel()
}

// ---

// An implementation of Client that represents a Remote registry.
// E.g. docker hub.
type Remote struct {
	Registry   *herokuManifestAdaptor
	CancelFunc context.CancelFunc
}

// Return the tags for this repository.
func (a *Remote) Tags(id flux.ImageID) ([]string, error) {
	return a.Registry.Tags(id.NamespaceImage())
}

// We need to do some adapting here to convert from the return values
// from dockerregistry to our domain types.
func (a *Remote) Manifest(id flux.ImageID) (flux.Image, error) {
	manifestV2, err := a.Registry.ManifestV2(id.NamespaceImage(), id.Tag)
	if err != nil {
		if err, ok := err.(*dockerregistry.HttpStatusError); ok {
			if err.Response.StatusCode == http.StatusNotFound {
				return a.ManifestFromV1(id)
			}
		}
		return flux.Image{}, err
	}
	// The above request will happily return a bogus, empty manifest
	// if handed something other than a schema2 manifest.
	if manifestV2.Config.Digest == "" {
		return a.ManifestFromV1(id)
	}<commit_msg>Account for docker-registry-client errors accurately<commit_after>package registry

import (
	"context"
	"encoding/json"
	"fmt"
	"net/http"
	"net/url"
	"time"

	"github.com/go-kit/kit/log"
	dockerregistry "github.com/heroku/docker-registry-client/registry"
	"github.com/pkg/errors"

	"github.com/weaveworks/flux"
	"github.com/weaveworks/flux/registry/cache"
)

// A client represents an entity that returns manifest and tags
// information.  It might be a cache, it might be a real registry.
type Client interface {
	Tags(id flux.ImageID) ([]string, error)
	Manifest(id flux.ImageID) (flux.Image, error)
	Cancel()
}

// ---

// An implementation of Client that represents a Remote registry.
// E.g. docker hub.
type Remote struct {
	Registry   *herokuManifestAdaptor
	CancelFunc context.CancelFunc
}

// Return the tags for this repository.
func (a *Remote) Tags(id flux.ImageID) ([]string, error) {
	return a.Registry.Tags(id.NamespaceImage())
}

// We need to do some adapting here to convert from the return values
// from dockerregistry to our domain types.
func (a *Remote) Manifest(id flux.ImageID) (flux.Image, error) {
	manifestV2, err := a.Registry.ManifestV2(id.NamespaceImage(), id.Tag)
	if err != nil {
		if err, ok := err.(*url.Error); ok {
			if err, ok := (err.Err).(*dockerregistry.HttpStatusError); ok {
				if err.Response.StatusCode == http.StatusNotFound {
					return a.ManifestFromV1(id)
				}
			}
		}
		fmt.Printf("%#v\n", err)
		return flux.Image{}, err
	}
	// The above request will happily return a bogus, empty manifest
	// if handed something other than a schema2 manifest.
	if manifestV2.Config.Digest == "" {
		return a.ManifestFromV1(id)
	}
{'fraction_non_alphanumeric': 0.12636165577342048, 'fraction_numerical': 0.003734827264239029, 'mean_word_length': 3.825825825825826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7204569', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1058, 'n_words': 312}