fix(engine): truncate errorMessage before reporting status
A failed usenet extract sets task.ErrorMessage to the full unrar/par2 dump (multi-KB). Sent raw, the web /agent/status route rejected it and the terminal report failed, leaving the task stuck non-terminal. Cap the reported errorMessage at 2000 bytes (rune-safe) in the status snapshot, matching the server's stored length.
This commit is contained in:
parent
5d44ee704c
commit
0e8d9e87f6
1 changed files with 17 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/torrentclaw/unarr/internal/agent"
|
"github.com/torrentclaw/unarr/internal/agent"
|
||||||
)
|
)
|
||||||
|
|
@ -229,10 +230,25 @@ func (t *Task) ToStatusUpdate() agent.StatusUpdate {
|
||||||
FileName: t.FileName,
|
FileName: t.FileName,
|
||||||
FilePath: t.FilePath,
|
FilePath: t.FilePath,
|
||||||
StreamURL: t.StreamURL,
|
StreamURL: t.StreamURL,
|
||||||
ErrorMessage: t.ErrorMessage,
|
// Cap to the server's stored length. A failed extract can carry a
|
||||||
|
// multi-KB unrar/par2 dump; sending it raw made /agent/status 400
|
||||||
|
// the whole report, leaving the task stuck non-terminal.
|
||||||
|
ErrorMessage: truncateMsg(t.ErrorMessage, 2000),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// truncateMsg caps s to at most max bytes without splitting a UTF-8 rune.
|
||||||
|
func truncateMsg(s string, max int) string {
|
||||||
|
if len(s) <= max {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
cut := max
|
||||||
|
for cut > 0 && !utf8.RuneStart(s[cut]) {
|
||||||
|
cut--
|
||||||
|
}
|
||||||
|
return s[:cut]
|
||||||
|
}
|
||||||
|
|
||||||
// MagnetURI builds a magnet link from the info hash.
|
// MagnetURI builds a magnet link from the info hash.
|
||||||
func (t *Task) MagnetURI() string {
|
func (t *Task) MagnetURI() string {
|
||||||
return "magnet:?xt=urn:btih:" + t.InfoHash
|
return "magnet:?xt=urn:btih:" + t.InfoHash
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue