reason

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package reason holds the explanations the server gives an administrator: why a capability is degraded, why a connection cannot run an action, what a configuration relies on. Each has a stable code the console translates (zh-CN, en), named parameters, and the English text logs, the CLI and MCP show.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Template

func Template(code Code) string

Template is the English template of code, with {placeholders}.

Types

type Code

type Code string

Code names an explanation; its English template is in templates.

const (
	// Capabilities of the dialects.
	ReturningInsert       Code = "returning.insertReturning"
	ReturningLastInsertID Code = "returning.lastInsertId"
	ExplainPostgresJSON   Code = "explain.postgresJson"
	ExplainMySQLJSON      Code = "explain.mysqlJson"
	ExplainPlanner        Code = "explain.plannerEstimates"
	ExplainCoarse         Code = "explain.coarseEstimates"
	ExplainAnalyze        Code = "explain.analyze"
	ExplainNoAnalyze      Code = "explain.noAnalyze"

	// Statement timeouts and the refusal of unkeyed writes, per connection.
	PostgresTimeout          Code = "timeout.postgresStatementTimeout"
	PostgresTimeoutPooled    Code = "timeout.postgresPooled"
	PostgresCancelOnly       Code = "timeout.postgresCancelOnly"
	NoQueryTimeout           Code = "timeout.none"
	SessionVariable          Code = "timeout.sessionVariable"
	SessionVariableReadsOnly Code = "timeout.sessionVariableSelectOnly"
	DSNSetsTimeout           Code = "timeout.dsnSetsVariable"
	MySQLWriteKilled         Code = "timeout.mysqlWriteKilled"
	MySQLWritePooled         Code = "timeout.mysqlWritePooled"
	SettingPooled            Code = "setting.pooled"
	UnkeyedGateOnly          Code = "unkeyedWrite.gateOnly"
	UnkeyedDSNOff            Code = "unkeyedWrite.dsnOff"
	UnkeyedDSNOn             Code = "unkeyedWrite.dsnOn"
	UnkeyedDSNUnclear        Code = "unkeyedWrite.dsnUnclear"
	UnkeyedSafeUpdates       Code = "unkeyedWrite.safeUpdates"
	LimitUnjudged            Code = "limit.unjudged"

	// The work relying on a limit.
	UseReads           Code = "limitUse.reads"
	UseWrites          Code = "limitUse.writes"
	UseReadsAfterWrite Code = "limitUse.readsAfterWrites"
	UseProcedures      Code = "limitUse.procedures"
	UseSQLEscape       Code = "limitUse.sqlEscape"

	// Whether a connection may run an action.
	PrivilegeReadOnlyServer    Code = "privilege.readOnlyServer"
	PrivilegeMissing           Code = "privilege.missing"
	PrivilegeFilterNeedsSelect Code = "privilege.filterNeedsSelect"
	PrivilegeReadsBack         Code = "privilege.readsBack"
	PrivilegeUncheckable       Code = "privilege.uncheckable"

	// How firmly a connection guarantees a capability.
	StrengthEnforced    Code = "strength.enforced"
	StrengthBestEffort  Code = "strength.bestEffort"
	StrengthUnsupported Code = "strength.unsupported"

	// What validating a configuration reports, without refusing it.
	CapabilityDenied Code = "validation.capabilityDenied"
	LimitNotEnforced Code = "validation.limitNotEnforced"
	// A plan grants an action the connection cannot run.
	PlanActionDenied Code = "plan.actionDenied"
)

The codes, one place for all: adding an explanation means a constant and its English template here, then the console's zh-CN and en messages under reasons.<code> (go test ./core/reason -update refreshes the fixture the console checks its messages against).

func Codes

func Codes() []Code

Codes lists every code, sorted.

type Reason

type Reason struct {
	Code   Code
	Params map[string]string
	Parts  map[string]Reason
	Text   string
}

Reason is one explanation: its code, the values of its template's {placeholders}, and its English text. A placeholder may name a part, an explanation of its own (the cause, the work affected) that the console translates by its own code; parts do not nest.

func Compose

func Compose(code Code, parts map[string]Reason, params ...string) Reason

Compose is New with parts, explanations filling placeholders of their own by their text.

func New

func New(code Code, params ...string) Reason

New is the explanation code gives with params, name and value pairs filling its template's {name} placeholders.

func (Reason) String

func (r Reason) String() string

String is the English text.

Jump to

Keyboard shortcuts

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