mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-16 10:09:28 +02:00
Replaced ImportResult.ImportErrors with ImportResult.ImportLog
This commit is contained in:
parent
91f9b62db3
commit
8a2ddb7772
5 changed files with 55 additions and 13 deletions
|
@ -236,7 +236,7 @@ func (b *LastfmApiBackend) ImportListens(export models.ListensResult, importResu
|
|||
for _, s := range result.Scrobbles {
|
||||
ignoreMsg := s.IgnoredMessage.Body
|
||||
if ignoreMsg != "" {
|
||||
importResult.ImportErrors = append(importResult.ImportErrors, ignoreMsg)
|
||||
importResult.Log(models.Warning, ignoreMsg)
|
||||
}
|
||||
}
|
||||
err := fmt.Errorf("last.fm import ignored %v scrobbles", count-accepted)
|
||||
|
@ -335,7 +335,7 @@ func (b *LastfmApiBackend) ImportLoves(export models.LovesResult, importResult m
|
|||
} else {
|
||||
msg := fmt.Sprintf("Failed import of \"%s\" by %s: %v",
|
||||
love.TrackName, love.ArtistName(), err.Error())
|
||||
importResult.ImportErrors = append(importResult.ImportErrors, msg)
|
||||
importResult.Log(models.Error, msg)
|
||||
}
|
||||
|
||||
progress <- models.Progress{}.FromImportResult(importResult)
|
||||
|
|
|
@ -148,7 +148,7 @@ func (b *ListenBrainzApiBackend) ImportListens(export models.ListensResult, impo
|
|||
count -= 1
|
||||
msg := i18n.Tr("Ignored duplicate listen %v: \"%v\" by %v (%v)",
|
||||
l.ListenedAt, l.TrackName, l.ArtistName(), l.RecordingMbid)
|
||||
importResult.ImportErrors = append(importResult.ImportErrors, msg)
|
||||
importResult.Log(models.Info, msg)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ func (b *ListenBrainzApiBackend) ImportLoves(export models.LovesResult, importRe
|
|||
} else {
|
||||
msg := fmt.Sprintf("Failed import of \"%s\" by %s: %v",
|
||||
love.TrackName, love.ArtistName(), errMsg)
|
||||
importResult.ImportErrors = append(importResult.ImportErrors, msg)
|
||||
importResult.Log(models.Error, msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -143,11 +143,11 @@ func (c *TransferCmd[E, I, R]) Transfer(exp backends.ExportProcessor[R], imp bac
|
|||
}
|
||||
|
||||
// Print errors
|
||||
if len(result.ImportErrors) > 0 {
|
||||
if len(result.ImportLog) > 0 {
|
||||
fmt.Println()
|
||||
fmt.Println(i18n.Tr("During the import the following errors occurred:"))
|
||||
for _, err := range result.ImportErrors {
|
||||
fmt.Println(i18n.Tr("Error: %v", err))
|
||||
fmt.Println(i18n.Tr("Import log:"))
|
||||
for _, entry := range result.ImportLog {
|
||||
fmt.Println(i18n.Tr("%v: %v", entry.Type, entry.Message))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -164,11 +164,24 @@ type ListensResult ExportResult[ListensList]
|
|||
|
||||
type LovesResult ExportResult[LovesList]
|
||||
|
||||
type LogEntryType string
|
||||
|
||||
const (
|
||||
Info LogEntryType = "Info"
|
||||
Warning LogEntryType = "Warning"
|
||||
Error LogEntryType = "Error"
|
||||
)
|
||||
|
||||
type LogEntry struct {
|
||||
Type LogEntryType
|
||||
Message string
|
||||
}
|
||||
|
||||
type ImportResult struct {
|
||||
TotalCount int
|
||||
ImportCount int
|
||||
LastTimestamp time.Time
|
||||
ImportErrors []string
|
||||
ImportLog []LogEntry
|
||||
|
||||
// Error is only set if an unrecoverable import error occurred
|
||||
Error error
|
||||
|
@ -185,7 +198,14 @@ func (i *ImportResult) Update(from ImportResult) {
|
|||
i.TotalCount = from.TotalCount
|
||||
i.ImportCount = from.ImportCount
|
||||
i.UpdateTimestamp(from.LastTimestamp)
|
||||
i.ImportErrors = append(i.ImportErrors, from.ImportErrors...)
|
||||
i.ImportLog = append(i.ImportLog, from.ImportLog...)
|
||||
}
|
||||
|
||||
func (i *ImportResult) Log(t LogEntryType, msg string) {
|
||||
i.ImportLog = append(i.ImportLog, LogEntry{
|
||||
Type: t,
|
||||
Message: msg,
|
||||
})
|
||||
}
|
||||
|
||||
type Progress struct {
|
||||
|
|
|
@ -117,23 +117,45 @@ func TestLovesListSort(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestImportResultUpdate(t *testing.T) {
|
||||
logEntry1 := models.LogEntry{
|
||||
Type: models.Warning,
|
||||
Message: "foo",
|
||||
}
|
||||
logEntry2 := models.LogEntry{
|
||||
Type: models.Error,
|
||||
Message: "bar",
|
||||
}
|
||||
result := models.ImportResult{
|
||||
TotalCount: 100,
|
||||
ImportCount: 20,
|
||||
LastTimestamp: time.Now(),
|
||||
ImportErrors: []string{"foo"},
|
||||
ImportLog: []models.LogEntry{logEntry1},
|
||||
}
|
||||
newResult := models.ImportResult{
|
||||
TotalCount: 120,
|
||||
ImportCount: 50,
|
||||
LastTimestamp: time.Now().Add(1 * time.Hour),
|
||||
ImportErrors: []string{"bar"},
|
||||
ImportLog: []models.LogEntry{logEntry2},
|
||||
}
|
||||
result.Update(newResult)
|
||||
assert.Equal(t, 120, result.TotalCount)
|
||||
assert.Equal(t, 50, result.ImportCount)
|
||||
assert.Equal(t, newResult.LastTimestamp, result.LastTimestamp)
|
||||
assert.Equal(t, []string{"foo", "bar"}, result.ImportErrors)
|
||||
assert.Equal(t, []models.LogEntry{logEntry1, logEntry2}, result.ImportLog)
|
||||
}
|
||||
|
||||
func TestImportResultLog(t *testing.T) {
|
||||
result := models.ImportResult{}
|
||||
result.Log(models.Warning, "foo")
|
||||
result.Log(models.Error, "bar")
|
||||
expected := []models.LogEntry{{
|
||||
Type: models.Warning,
|
||||
Message: "foo",
|
||||
}, {
|
||||
Type: models.Error,
|
||||
Message: "bar",
|
||||
}}
|
||||
assert.Equal(t, expected, result.ImportLog)
|
||||
}
|
||||
|
||||
func TestImportResultUpdateTimestamp(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue