// Preamble
// Example usage:
//   ctx, err, fin := c.Preamble(...)
//   defer fin()
//   if err != nil { return err }
519773
func (s *Server) Preamble(inCtx context.Context, opts preambleArg) (mctx libkb.MetaContext, fin func(), err error) {
	mctx = libkb.NewMetaContext(s.logTag(inCtx), s.G())
	getFinalErr := func() error {
		if opts.Err == nil {
			return nil
		}
		return *opts.Err
	}
	fin = mctx.TraceTimed("LRPC "+opts.RPCName, getFinalErr)
	if !opts.AllowLoggedOut {
		if err = s.assertLoggedIn(mctx); err != nil {
			return mctx, fin, err
		}
	}
	if opts.RequireWallet {
		cwg, err := stellar.CreateWalletGated(mctx)
		if err != nil {
			return mctx, fin, err
		}
		if !cwg.HasWallet {
			if !cwg.AcceptedDisclaimer {
				// Synthesize an AppStatusError so the CLI and GUI can match on these errors.
				err = libkb.NewAppStatusError(&libkb.AppStatus{
					Code: libkb.SCStellarNeedDisclaimer,
					Name: "STELLAR_NEED_DISCLAIMER",
					Desc: "user hasn't yet accepted the Stellar disclaimer",
				})
				return mctx, fin, err
			}
			return mctx, fin, errors.New("logged-in user does not have a wallet")
		}
	}
	return mctx, fin, nil
}
643526
func (e *Error) Error() string {
	loc := ""
	if e.Path != "" {
		line := ""
		if e.Line != 0 {
			line = fmt.Sprintf(":%d", e.Line)
		}
		loc = fmt.Sprintf("(in %s%s)", e.Path, line)
	}
	header := loc
	if e.Title != "" {
		if loc != "" {
			header = fmt.Sprintf("%s %s: ", e.Title, loc)
		} else {
			header = fmt.Sprintf("%s: ", e.Title)
		}
	}
	return fmt.Sprintf("%s%s Stack: %s", header, e.Description, e.Stack)
}
1229269
func (lx *lexer) errorf(format string, values ...interface{}) stateFn {
	lx.items <- item{
		itemError,
		fmt.Sprintf(format, values...),
		lx.line,
	}
	return nil
}
264597
func (p Pos) Before(u Pos) bool {
	return u.Offset > p.Offset || u.Line > p.Line
}
620532
func (d DoubleArray) CommonPrefixSearchCallback(input string, callback func(id, l int)) {
	var p, q int
	bufLen := len(d)
	for i := 0; i < len(input); i++ {
		if input[i] == terminator {
			return
		}
		p = q
		q = int(d[p].Base) + int(input[i])
		if q >= bufLen || int(d[q].Check) != p {
			break
		}
		ahead := int(d[q].Base) + int(terminator)
		if ahead < bufLen && int(d[ahead].Check) == q && int(d[ahead].Base) <= 0 {
			callback(int(-d[ahead].Base), i+1)
		}
	}
	return
}
91647
func (err *Error) Error() string {
	if err.Context == nil {
		return "ERROR " + err.Message
	}
	return "ERROR " + err.Context.Description() + " " + err.Message
}
106988
func (t *tFile) before(icmp *iComparer, ukey []byte) bool {
	return ukey != nil && icmp.uCompare(ukey, t.imin.ukey()) < 0
}
487733
func (err Error) Format() (string, error) {
	errlog := errorForLog{err.Code, err.Err, err.Msg, err.Data, err.Stack}
	res, e := json.Marshal(errlog)
	if e == nil {
		return string(res), nil
	}
	return "", e
}
1087583
func Param(ctx context.Context, p string) string {
	if v := ctx.Value(param(p)); v != nil {
		return v.(string)
	}
	return ""
}
1123462
func processPrelude(prelude io.Reader, crc hash.Hash32) (preludeInfo, error) {
	var err error
	var pInfo = preludeInfo{}

	// reads total length of the message (first 4 bytes)
	pInfo.totalLen, err = extractUint32(prelude)
	if err != nil {
		return pInfo, err
	}

	// reads total header length of the message (2nd 4 bytes)
	pInfo.headerLen, err = extractUint32(prelude)
	if err != nil {
		return pInfo, err
	}

	// checks that the CRC is correct (3rd 4 bytes)
	preCRC := crc.Sum32()
	if err := checkCRC(prelude, preCRC); err != nil {
		return pInfo, err
	}

	return pInfo, nil
}
953014
func (p *parser) errorf(format string, args ...interface{}) {
	p.config = nil
	format = fmt.Sprintf("%s:%d: %s", p.name, p.lex.lineNumber(), format)
	panic(fmt.Errorf(format, args...))
}
799163
func (e *Error) Error() string {
	var ret string
	ret = e.desc + "\n"

	// TODO: use github.com/pkg/errors
	for _, stack := range e.stack {
		ret += fmt.Sprintf("%s [%s %d]\n", stack.fun, stack.file, stack.line)
	}
	return ret
}
55228
func NotError(t testing.TB, expr interface{}, args ...interface{}) {
	if IsNil(expr) { // 空值必定没有错误
		assert(t, true, args, []interface{}{"NotError 失败，实际类型为[%T]", expr})
		return
	}
	err, ok := expr.(error)
	assert(t, !ok, args, []interface{}{"NotError 失败，错误信息为[%v]", err})
}
315428
func (c *context) Error(format string, args ...interface{}) {
	c.logger.Error(c.prefixFormat()+format, args...)
}
1341357
func PrependError(prepend string, err error) error {
	if t, ok := err.(TTransportException); ok {
		return NewTTransportException(t.TypeId(), prepend+t.Error())
	}
	if t, ok := err.(TProtocolException); ok {
		return NewTProtocolExceptionWithType(t.TypeId(), errors.New(prepend+err.Error()))
	}
	if t, ok := err.(TApplicationException); ok {
		return NewTApplicationException(t.TypeId(), prepend+t.Error())
	}

	return errors.New(prepend + err.Error())
}
1055225
func (e *Error) Error() string {
	msg := fmt.Sprintf("%d: %s - %s", e.Status, e.Title, e.Detail)
	if e.Source.Pointer != "" {
		msg += fmt.Sprintf("(Source.Pointer: %s)", e.Source.Pointer)
	}

	if e.ISE != "" {
		msg += fmt.Sprintf("\nInternal Error: %s", e.ISE)
	}

	return msg
}
420420
func OptionPrefix(x string) Option {
	return func(p *Prompt) error {
		p.renderer.prefix = x
		return nil
	}
}