Documentation
¶
Overview ¶
Package problems keeps the log of real problems shown in Settings > System > Logs and errors: a download that failed, a Usenet provider that refused the login, a full disk. It is not a copy of the log file. Only things a person may want to act on are recorded, each under a stable code, and the same problem repeating within a few minutes is folded into one row with a count.
The package sits at the bottom of the dependency order (it imports only the log scrubber), so any part of the app can report a problem with Record without importing the API. Nothing is recorded until the API has attached the database with SetDefault, so tests of other packages are unaffected.
Index ¶
- Constants
- func Ago(now, t time.Time) string
- func AreaLabel(a Area) string
- func Clean(p Problem) (message, detail string)
- func Clip(s string, n int) string
- func CodeFor(err error, fallback string) string
- func Codes() []string
- func IndexerCode(err error) string
- func MediaServerCode(err error) string
- func Record(p Problem)
- func Saving() bool
- func SetDefault(l *Log)
- func Text(entries []Entry, now time.Time) string
- func Times(n int) string
- func UsenetCode(err error) string
- type Area
- type AreaInfo
- type Counts
- type Entry
- type Filter
- type Help
- type Level
- type Log
- func (l *Log) Counts(now time.Time) (Counts, error)
- func (l *Log) Dropped() int
- func (l *Log) Flush()
- func (l *Log) List(f Filter) ([]Entry, int, error)
- func (l *Log) MarkAllRead(f Filter) (int64, error)
- func (l *Log) MarkRead(ids []int64) (int64, error)
- func (l *Log) Prune(now time.Time, days int) (int64, error)
- func (l *Log) Record(p Problem)
- func (l *Log) SetClock(now func() time.Time)
- type Problem
Constants ¶
const ( CodeDownloadFailed = "download.failed" CodeDownloadFileFailed = "download.file_failed" // no longer produced (see CodeIndexerFetchFailed); older log rows still use it CodeUsenetTooMany = "usenet.too_many_connections" CodeUsenetAuthRefused = "usenet.auth_refused" CodeUsenetUnreachable = "usenet.unreachable" CodeUsenetQuota = "usenet.quota_reached" CodeUsenetMissingParts = "usenet.articles_missing" CodeUnpackFailed = "unpack.failed" CodeUnpackPassword = "unpack.password" CodeUnpackToolMissing = "unpack.tool_missing" CodePar2Failed = "par2.failed" CodeIndexerRateLimited = "indexer.rate_limited" CodeIndexerAuthRefused = "indexer.auth_refused" CodeIndexerUnreachable = "indexer.unreachable" CodeIndexerFailed = "indexer.failed" CodeIndexerFetchFailed = "indexer.fetch_failed" CodeMediaServerDown = "mediaserver.unreachable" CodeMediaServerAuth = "mediaserver.auth_refused" CodeMediaServerRefresh = "mediaserver.refresh_failed" CodeImportMoveFailed = "import.move_failed" CodeImportNoVideo = "import.no_video" CodeImportFileExists = "import.file_exists" CodeImportFailed = "import.failed" CodeDiskFull = "disk.full" CodeFolderPermission = "folder.permission_denied" CodeFolderMissing = "folder.missing" CodeDatabaseSlow = "database.slow" CodeTMDBRateLimited = "tmdb.rate_limited" CodeTMDBKeyRejected = "tmdb.key_rejected" CodeNotificationFailed = "notification.send_failed" CodeUpdateCheckFailed = "update.check_failed" CodeUpdateInstallFailed = "update.install_failed" CodeAppRestartedItself = "app.restarted_itself" CodeSubtitlesRateLimited = "subtitles.rate_limited" )
The codes. A code never changes once it has shipped, because the log stores it and the help below is looked up by it.
const ( // Window is how long after a problem the same one is folded into its row // instead of getting a new row. Window = 10 * time.Minute // TitleWindow is how long the same problem about the same movie, show or // album is folded into one row, even when it comes from a different // download. A title that keeps failing is one line with a count, not a // page of lines. TitleWindow = 24 * time.Hour // KeepDays is how long problems are kept. KeepDays = 30 // MaxRows is the most rows kept, whatever their age. MaxRows = 2000 )
Variables ¶
This section is empty.
Functions ¶
func Ago ¶
Ago says how long before now t was, in a few plain words: "just now", "2 minutes ago", "3 hours ago", "5 days ago".
func CodeFor ¶
CodeFor picks the code that describes err, judging by what it wraps and by the words in its message. The steps of the download pipeline wrap their errors with a fixed phrase ("couldn't unpack the download", "repairing the download failed"), which is what most of these match. When nothing fits it returns fallback.
func IndexerCode ¶
IndexerCode says why an indexer failed: it limited the requests, it refused the key, it could not be reached, or it gave some other error.
func MediaServerCode ¶
MediaServerCode says why a media server could not be asked to refresh.
func Record ¶
func Record(p Problem)
Record reports a problem to the default log. It does nothing until the API has set one, and it never blocks or fails.
func Saving ¶
func Saving() bool
Saving reports whether the log is writing a row right now. The database reports statements that take long to the log; the statements of the log's own write are left out, or a slow database would fill the log with the log's own trouble and keep writing.
func SetDefault ¶
func SetDefault(l *Log)
SetDefault chooses the log that Record writes to. Pass nil to switch recording off.
func Text ¶
Text writes the problems as a plain text file a person can attach to a support request. entries are written in the order given.
func UsenetCode ¶
UsenetCode says why a news server login could not be used: the provider refused it, the limit of connections was reached or the server could not be reached.
Types ¶
type Area ¶
type Area string
Area is the part of the app a problem belongs to.
const ( AreaDownloads Area = "downloads" AreaUsenet Area = "usenet" AreaSearch Area = "search" AreaMediaServers Area = "mediaservers" AreaImport Area = "import" AreaDisk Area = "disk" AreaDatabase Area = "database" AreaMetadata Area = "metadata" AreaUpdates Area = "updates" AreaNotifications Area = "notifications" AreaSystem Area = "system" )
type Counts ¶
type Counts struct {
ErrorsToday int `json:"errorsToday"`
WarningsToday int `json:"warningsToday"`
ErrorsWeek int `json:"errorsWeek"`
WarningsWeek int `json:"warningsWeek"`
Unread int `json:"unread"`
UnreadErrors24 int `json:"unreadErrors24h"` // unread errors from the last 24 hours: the red dot and the dashboard card
}
Counts are the numbers on the cards at the top of the page.
type Entry ¶
type Entry struct {
ID int64
FirstAt time.Time
LastAt time.Time
Level Level
Area Area
Code string
Subject string
Message string
Detail string
Title string
Link string
DownloadID int64
Count int
Read bool
}
Entry is one row of the log.
type Filter ¶
type Filter struct {
Level Level
Area Area
Code string
Since time.Time // last happened at or after this
Until time.Time // last happened before this
Text string // words to find in the message, detail, title or code
UnreadOnly bool
Limit int // default 50, at most 200
Offset int
}
Filter narrows a list of problems. The zero value matches everything.
type Help ¶
type Help struct {
Code string `json:"code"`
Level Level `json:"level"` // used when the caller does not say
Area Area `json:"area"`
Title string `json:"title"` // a short heading
Explain string `json:"explain"` // what happened, in a sentence
Try string `json:"try"` // what to try, in a sentence or two
LinkLabel string `json:"linkLabel,omitempty"`
LinkPath string `json:"linkPath,omitempty"` // the settings page where it can be fixed
}
Help is the plain-language help for one code.
type Log ¶
type Log struct {
// OnNew, when set, is told about every new error row (not about repeats
// folded into an existing one). It must not block.
OnNew func(Entry)
// contains filtered or unexported fields
}
Log is the stored problem log. Record is safe to call from anywhere and never blocks: the write happens on a short-lived goroutine of its own.
func (*Log) Counts ¶
Counts totals the log. Today runs from midnight in now's time zone; the week is the last seven days.
func (*Log) Dropped ¶
Dropped is how many reports were thrown away because too many arrived at once.
func (*Log) MarkAllRead ¶
MarkAllRead marks every problem matching f as read (only the filter's conditions are used, not its paging).
type Problem ¶
type Problem struct {
Code string // one of the Code constants (an unknown code is still kept)
Level Level // default: the level of the code
Subject string // what the problem is about when one code can happen to several things (a server, a source, a download): repeats fold together only for the same subject
Message string // a short plain sentence; default: the title of the code
Err error // the underlying error, kept as technical detail
Detail string // more technical detail
Title string // the movie, show or album it concerns, when known
Link string // page in the app for that title, for example /title/603
DownloadID int64 // the download it concerns, when known
Quiet bool // do not send a notification for it, even when those are switched on
}
Problem is what a caller reports. Only Code is needed; everything else has a sensible default.