<commit_before>package torrent

import (
	"context"
	"net/http"

	"github.com/anacrolix/log"
	"github.com/anacrolix/torrent/bencode"
	"github.com/anacrolix/torrent/metainfo"
)

func (t *Torrent) useSources(sources []string) {
	select {
	case <-t.Closed():
		return
	case <-t.GotInfo():
		return
	default:
	}
	for _, s := range sources {
		_, loaded := t.activeSources.LoadOrStore(s, struct{}{})
		if loaded {
			continue
		}
		s := s
		go func() {
			err := t.useActiveTorrentSource(s)
			_, loaded := t.activeSources.LoadAndDelete(s)
			if !loaded {
				panic(s)
			}
			level := log.Debug
			if err != nil {
				level = log.Warning
			}
			t.logger.Levelf(level, "used torrent source %q [err=%q]", s, err)
		}()
	}
}

func (t *Torrent) useActiveTorrentSource(source string) error {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	go func() {
		select {
		case <-t.GotInfo():
		case <-t.Closed():
		case <-ctx.Done():
		}
		cancel()
	}()
	mi, err := getTorrentSource(ctx, source, t.cl.httpClient)
	if err != nil {
		return err
	}<commit_msg>Fix error quoting in log<commit_after>package torrent

import (
	"context"
	"net/http"

	"github.com/anacrolix/log"
	"github.com/anacrolix/torrent/bencode"
	"github.com/anacrolix/torrent/metainfo"
)

func (t *Torrent) useSources(sources []string) {
	select {
	case <-t.Closed():
		return
	case <-t.GotInfo():
		return
	default:
	}
	for _, s := range sources {
		_, loaded := t.activeSources.LoadOrStore(s, struct{}{})
		if loaded {
			continue
		}
		s := s
		go func() {
			err := t.useActiveTorrentSource(s)
			_, loaded := t.activeSources.LoadAndDelete(s)
			if !loaded {
				panic(s)
			}
			level := log.Debug
			if err != nil {
				level = log.Warning
			}
			t.logger.Levelf(level, "used torrent source %q [err=%v]", s, err)
		}()
	}
}

func (t *Torrent) useActiveTorrentSource(source string) error {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	go func() {
		select {
		case <-t.GotInfo():
		case <-t.Closed():
		case <-ctx.Done():
		}
		cancel()
	}()
	mi, err := getTorrentSource(ctx, source, t.cl.httpClient)
	if err != nil {
		return err
	}
{'fraction_non_alphanumeric': 0.1639496972519795, 'fraction_numerical': 0.0, 'mean_word_length': 3.3046092184368736, 'pattern_counts': {'":': 0, '<': 13, '<?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': '6454022', 'n_tokens_mistral': 922, 'n_tokens_neox': 815, 'n_words': 180}