8func xcheckf(err error, format string, args ...any) {
10 xserverErrorf("%s: %w", fmt.Sprintf(format, args...), err)
14type userError struct {
15 code string // Optional response code in brackets.
19func (e userError) Error() string { return e.err.Error() }
20func (e userError) Unwrap() error { return e.err }
22func xuserErrorf(format string, args ...any) {
23 panic(userError{err: fmt.Errorf(format, args...)})
26func xusercodeErrorf(code, format string, args ...any) {
27 panic(userError{code: code, err: fmt.Errorf(format, args...)})
30type serverError struct{ err error }
32func (e serverError) Error() string { return e.err.Error() }
33func (e serverError) Unwrap() error { return e.err }
35func xserverErrorf(format string, args ...any) {
36 panic(serverError{fmt.Errorf(format, args...)})
39type syntaxError struct {
40 line string // Optional line to write before BAD result. For untagged response. CRLF will be added.
41 code string // Optional result code (between []) to write in BAD result.
42 errmsg string // BAD response message.
43 err error // Typically with same info as errmsg, but sometimes more.
46func (e syntaxError) Error() string {
47 s := "bad syntax: " + e.errmsg
49 s += " [" + e.code + "]"
53func (e syntaxError) Unwrap() error { return e.err }
55func xsyntaxErrorf(format string, args ...any) {
56 errmsg := fmt.Sprintf(format, args...)
57 err := errors.New(errmsg)
58 panic(syntaxError{"", "", errmsg, err})