problems

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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"
	CodeBackupFailed         = "backup.failed"
	CodeDiskLow              = "disk.low"
)

The codes. A code never changes once it has shipped, because the log stores it and the help below is looked up by it.

View Source
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

func Ago(now, t time.Time) string

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 AreaLabel

func AreaLabel(a Area) string

AreaLabel is the name shown for an area; an unknown area shows as it is.

func Clean

func Clean(p Problem) (message, detail string)

Clean turns a problem into what is stored: secrets taken out, long text cut.

func Clip

func Clip(s string, n int) string

Clip shortens s to at most about n bytes without cutting a character in half.

func CodeFor

func CodeFor(err error, fallback string) string

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 Codes

func Codes() []string

Codes lists every known code, in catalog order.

func IndexerCode

func IndexerCode(err error) string

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

func MediaServerCode(err error) string

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

func Text(entries []Entry, now time.Time) string

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 Times

func Times(n int) string

Times says how often something happened: "once", "3 times".

func UsenetCode

func UsenetCode(err error) string

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 AreaInfo

type AreaInfo struct {
	ID    Area   `json:"id"`
	Label string `json:"label"`
}

AreaInfo is an area with the name shown for it.

func Areas

func Areas() []AreaInfo

Areas lists every area in display order.

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.

func Catalog

func Catalog() []Help

Catalog returns the whole help table.

func Lookup

func Lookup(code string) (Help, bool)

Lookup finds the help for a code.

type Level

type Level string

Level says how serious a problem is.

const (
	LevelError   Level = "error"   // something failed and did not fix itself
	LevelWarning Level = "warning" // something went wrong but the app worked around it, or it may pass
)

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 Default

func Default() *Log

Default returns the log Record writes to, or nil.

func Open

func Open(db *sql.DB) *Log

Open returns a log stored in db, which must have the problems table.

func (*Log) Counts

func (l *Log) Counts(now time.Time) (Counts, error)

Counts totals the log. Today runs from midnight in now's time zone; the week is the last seven days.

func (*Log) Dropped

func (l *Log) Dropped() int

Dropped is how many reports were thrown away because too many arrived at once.

func (*Log) Flush

func (l *Log) Flush()

Flush waits until everything recorded so far is written.

func (*Log) List

func (l *Log) List(f Filter) ([]Entry, int, error)

List returns the problems matching f, newest first, and how many match in all.

func (*Log) MarkAllRead

func (l *Log) MarkAllRead(f Filter) (int64, error)

MarkAllRead marks every problem matching f as read (only the filter's conditions are used, not its paging).

func (*Log) MarkRead

func (l *Log) MarkRead(ids []int64) (int64, error)

MarkRead marks the given problems as read and returns how many changed.

func (*Log) Prune

func (l *Log) Prune(now time.Time, days int) (int64, error)

Prune removes problems older than the retention and anything beyond the row limit. days is how many days to keep; 0 or less means the default (30), and a longer time than that is never kept.

func (*Log) Record

func (l *Log) Record(p Problem)

Record queues the problem to be written.

func (*Log) SetClock

func (l *Log) SetClock(now func() time.Time)

SetClock replaces the clock (tests).

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL