XU XUv0.8.8
中文

API

#errors

import: #errors

counts: 6 fns, 4 methods, 3 types, 0 consts, 1 ifaces

Error values: StrErr / CodeErr / WrapErr and struct@ Error. Dynamic boxing is language syntax errors.Error(x), not a function here.

struct@ Error

XuAPI
struct@ Error {
    fn msg() string
}

Purpose

Error values: struct types + `struct@ Error` constraint. Dynamic boxing is language syntax: `errors.Error(concrete)` (not defined here). Scope: message text, typed error structs, wrap chain, is_err. wrap stores the inner message as text (not a boxed Error), so is_err walks that text chain: exact match, or a suffix ": " + target.msg. Not in this package: string join, logging, generic dynamic boxing. Typed tests use language `is`/`as`, not this package (`is` is a keyword).

Parameters

msg fn msg() string
Method on `Error`: return the message text.

(Error) msg

XuAPI
fn msg() string

Purpose

Method on `Error`: return the message text.

Parameters

self Self
receiver Self (value receiver)

Returns

string — result string

struct StrErr

XuAPI
pub struct StrErr {
    pub text string
}

Purpose

Public struct `StrErr`.

Parameters

text string
text

(StrErr) msg

XuAPI
pub fn (e StrErr) msg() string

Purpose

Method on `StrErr`: return the message text.

Parameters

e StrErr
receiver StrErr (value receiver)

Returns

string — result string

struct CodeErr

XuAPI
pub struct CodeErr {
    pub code int
    pub text string
}

Purpose

Public struct `CodeErr`.

Parameters

code int
code
text string
text

(CodeErr) msg

XuAPI
pub fn (e CodeErr) msg() string

Purpose

Method on `CodeErr`: return the message text.

Parameters

e CodeErr
receiver CodeErr (value receiver)

Returns

string — result string

code

XuAPI
pub fn code(code int, text string) CodeErr

Purpose

code; returns CodeErr.

Parameters

code int
code (int)
text string
text (string)

Returns

CodeErr — a value of this type

new

XuAPI
pub fn new(text string) StrErr

Purpose

Construct a new value of this type.

Parameters

text string
text (string)

Returns

StrErr — a value of this type

struct WrapErr

XuAPI
pub struct WrapErr {
    pub text string
    pub cause string
}

Purpose

Public struct `WrapErr`.

Parameters

text string
text
cause string
field (string)

(WrapErr) msg

XuAPI
pub fn (w WrapErr) msg() string

Purpose

Method on `WrapErr`: return the message text.

Parameters

w WrapErr
receiver WrapErr (value receiver)

Returns

string — result string

wrap

XuAPI
pub fn wrap(text string, err Error) WrapErr

Purpose

wrap; returns WrapErr.

Parameters

text string
text (string)
err Error
error (Error)

Returns

WrapErr — a value of this type

(WrapErr) cause

XuAPI
pub fn (w WrapErr) cause() string

Purpose

Method on `WrapErr`: return the wrapped cause text.

Parameters

w WrapErr
receiver WrapErr (value receiver)

Returns

string — result string

is_err

XuAPI
pub fn is_err(err Error, target Error) bool

Purpose

Whether it is err.

Parameters

err Error
error (Error)
target Error
target (Error)

Returns

bool — true or false

join

XuAPI
pub fn join(a Error, b Error) StrErr

Purpose

join is errors.Join for two errors (no variadic). Empty messages are dropped; both empty yields "".

Parameters

a Error
value (Error)
b Error
b (Error)

Returns

StrErr — a value of this type

unwrap

XuAPI
pub fn unwrap(err Error) string

Purpose

unwrap is errors.Unwrap on the message chain: the text after the last ": " (WrapErr.msg format). No wrap suffix yields "".

Parameters

err Error
error (Error)

Returns

string — result string