<commit_before>package root

/* CHECKLIST
 * [ ] Uses interfaces as appropriate
 * [ ] Private package variables use underscore prefix
 * [ ] All parameters validated
 * [ ] All errors handled
 * [ ] Reviewed for concurrency safety
 * [ ] Code complete
 * [ ] Full test coverage
 */

import (
	"errors"

	"github.com/tidepool-org/platform/data/deduplicator"
	"github.com/tidepool-org/platform/data/deduplicator/truncate"
	"github.com/tidepool-org/platform/data/store"
	"github.com/tidepool-org/platform/data/types/base/upload"
	"github.com/tidepool-org/platform/log"
)

func NewFactory() deduplicator.Factory {
	return &Factory{
		[]deduplicator.Factory{
			truncate.NewFactory(),
		},
	}
}

type Factory struct {
	factories []deduplicator.Factory
}

func (f *Factory) CanDeduplicateDataset(dataset *upload.Upload) (bool, error) {
	for _, factory := range f.factories {
		if can, err := factory.CanDeduplicateDataset(dataset); err != nil {
			return false, err
		} else if can {
			return true, nil
		}
	}
	return false, nil
}

func (f *Factory) NewDeduplicator(logger log.Logger, dataStoreSession store.Session, dataset *upload.Upload) (deduplicator.Deduplicator, error) {
	for _, factory := range f.factories {
		if can, err := factory.CanDeduplicateDataset(dataset); err != nil {
			return nil, err
		} else if can {
			return factory.NewDeduplicator(logger, dataStoreSession, dataset)
		}
	}
	return nil, errors.New("Deduplicator not found")
}<commit_msg>Use correct error generation mechanism<commit_after>package root

/* CHECKLIST
 * [ ] Uses interfaces as appropriate
 * [ ] Private package variables use underscore prefix
 * [ ] All parameters validated
 * [ ] All errors handled
 * [ ] Reviewed for concurrency safety
 * [ ] Code complete
 * [ ] Full test coverage
 */

import (
	"github.com/tidepool-org/platform/app"
	"github.com/tidepool-org/platform/data/deduplicator"
	"github.com/tidepool-org/platform/data/deduplicator/truncate"
	"github.com/tidepool-org/platform/data/store"
	"github.com/tidepool-org/platform/data/types/base/upload"
	"github.com/tidepool-org/platform/log"
)

func NewFactory() deduplicator.Factory {
	return &Factory{
		[]deduplicator.Factory{
			truncate.NewFactory(),
		},
	}
}

type Factory struct {
	factories []deduplicator.Factory
}

func (f *Factory) CanDeduplicateDataset(dataset *upload.Upload) (bool, error) {
	for _, factory := range f.factories {
		if can, err := factory.CanDeduplicateDataset(dataset); err != nil {
			return false, err
		} else if can {
			return true, nil
		}
	}
	return false, nil
}

func (f *Factory) NewDeduplicator(logger log.Logger, dataStoreSession store.Session, dataset *upload.Upload) (deduplicator.Deduplicator, error) {
	for _, factory := range f.factories {
		if can, err := factory.CanDeduplicateDataset(dataset); err != nil {
			return nil, err
		} else if can {
			return factory.NewDeduplicator(logger, dataStoreSession, dataset)
		}
	}
	return nil, app.Error("root", "deduplicator not found")
}
{'fraction_non_alphanumeric': 0.1228600201409869, 'fraction_numerical': 0.0, 'mean_word_length': 4.302491103202847, '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': '5500466', 'n_tokens_mistral': 1029, 'n_tokens_neox': 986, 'n_words': 229}