platformerr

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: BSD-3-Clause Imports: 4 Imported by: ? 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 platformerr gives platform errors a code that survives wrapping and the p2p wire, and turns it into a public HTTP answer that never shows the internal error text.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(c Code, err error) error

New tags err with c, unless err already carries a code: the innermost code wins.

func Serve

Serve runs h and answers its error with Write. The full error chain goes to log only. If h already started the response, an error body would corrupt it, and ending it cleanly would show the client a short body as a whole one, so the connection is aborted: net/http closes it without logging the panic.

func Status

func Status(c Code) int

Status is the HTTP status for c; unknown and empty codes are 500.

func Write

func Write(w http.ResponseWriter, err error, requestID string)

Write answers with err's code as JSON. err's text is never written.

Types

type Code

type Code string
const (
	NotFound          Code = "not_found"
	NodeBusy          Code = "node_busy"
	ModuleUnavailable Code = "module_unavailable"
	FunctionError     Code = "function_error"
	FunctionTimeout   Code = "function_timeout"
	Internal          Code = "internal"
	OverQuota         Code = "over_quota"
	// Rejected is a request refused for what the caller sent (a bad signature):
	// logged as a warning, since anyone can send one.
	Rejected Code = "rejected"
)

func CodeOf

func CodeOf(err error) (c Code)

CodeOf returns the innermost code in err's chain, or "" if there is none.

type Error

type Error struct {
	Code Code
	Err  error
}

func (*Error) Error

func (e *Error) Error() string

Error returns the inner text so wrappers and log lines read as before.

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Logger

type Logger interface {
	Debugf(format string, args ...any)
	Errorf(format string, args ...any)
}

Logger is the part of a service logger Serve needs.

Jump to

Keyboard shortcuts

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