Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

errors.gno

2.25 Kb · 54 lines
 1package users
 2
 3import (
 4	"errors"
 5)
 6
 7const prefix = "r/sys/users: "
 8
 9var (
10	ErrAlreadyWhitelisted    = errors.New(prefix + "already whitelisted")
11	ErrWhitelistRemoveFailed = errors.New(prefix + "failed to remove address from whitelist")
12
13	ErrNameTaken          = errors.New(prefix + "name/Alias already taken")
14	ErrCanonicalCollision = errors.New(prefix + "name collides with a confusable variant of an existing name")
15	ErrInvalidAddress     = errors.New(prefix + "invalid address")
16
17	ErrEmptyUsername   = errors.New(prefix + "empty username provided")
18	ErrNameLikeAddress = errors.New(prefix + "username resembles a gno.land address")
19	ErrInvalidUsername = errors.New(prefix + "username must match ^[a-z][a-z0-9]*([_-][a-z0-9]+)*$ (max 64 chars)")
20
21	ErrAlreadyHasName = errors.New(prefix + "username for this address already registered - try creating an Alias")
22	ErrDeletedUser    = errors.New(prefix + "cannot register a new username after deleting")
23
24	ErrUserNotExistOrDeleted = errors.New(prefix + "this user does not exist or was deleted")
25
26	// ErrInvalidRealm is returned by controller-gated *UserData mutators
27	// when the supplied rlm is not the caller's live cur (i.e.
28	// rlm.IsCurrent() is false). Closes Class-2 designation forgery via
29	// a stored stale realm value whose .Address() resolves to a
30	// whitelisted controller. See docs/resources/gno-security.md.
31	ErrInvalidRealm = errors.New(prefix + "rlm is not the caller's live cur")
32)
33
34// ErrNotWhitelisted stores the failing caller's realm identity as a
35// plain string so the error is a pure data record (no live realm values
36// in its fields).
37type ErrNotWhitelisted struct {
38	Caller string // "CodeRealm{ <addr>, <pkgPath> }" or "UserRealm{ <addr> }" — failed the whitelist check
39}
40
41// NewErrNotWhitelisted constructs the error with the caller's realm
42// identity captured as a string at construction time. The _ int
43// discriminator keeps this non-crossing (a non-crossing function can't
44// take a `realm`-named-`cur` first param, so we use the standard
45// _ int, rlm realm shape).
46func NewErrNotWhitelisted(_ int, caller realm) ErrNotWhitelisted {
47	return ErrNotWhitelisted{
48		Caller: caller.String(),
49	}
50}
51
52func (e ErrNotWhitelisted) Error() string {
53	return prefix + "caller realm/user does not exist in whitelist: " + e.Caller
54}