// TODO(jrick) add error correction.
352070
func verifyAndFix(b []byte, chk uint32) error {
	if walletHash(b) != chk {
		return ErrChecksumMismatch
	}
	return nil
}
990560
func Err(exit int, err error, format string, a ...interface{}) {
	format = fmt.Sprintf("[%s] %s", progname, format)
	format += ": %v\n"
	a = append(a, err)
	fmt.Fprintf(os.Stderr, format, a...)
	os.Exit(exit)
}
546608
func newTodo(raw string) *todo {
	result := &todo{
		name:    s5.NewStringSimple(raw),
		done:    s5.NewBooleanSimple(false),
		editing: s5.NewBooleanSimple(false),
	}
	result.modName = s5.NewModelName(result)
	return result
}
757176
func Append(errs error, err error) error {
	m, ok := errs.(Errors)
	if !ok {
		return New(errs, err)
	}
	return append(m, err)
}
713923
func (r Error) Error() string {
	s := "["
	for i, err := range r.ErrSet {
		if i != 0 {
			s = s + "; "
		}
		s = s + err.Error()
	}
	return s + "]"
}
190192
func (c *Client) Do(m encoding.Marshaler, opt ...RequestOpt) (res mesos.Response, err error) {
	return c.Send(client.RequestSingleton(m), client.ResponseClassAuto, opt...)
}
81604
func (d *ulReqDecoder) error(format string, a ...interface{}) {
	msg := fmt.Sprintf(
		"pkt-line %d: %s", d.nLine,
		fmt.Sprintf(format, a...),
	)

	d.err = NewErrUnexpectedData(msg, d.line)
}
434537
func (obj *Doc) Redo(ctx context.Context) (bool, error) {
	result := &struct {
		Success bool	`json:"qSuccess"`
	} {}
	err := obj.rpc(ctx, "Redo", result)
	return result.Success, err 
}
770668
func (c *Client) ErrorWithStackSkipWithExtras(level string, err error, skip int, extras map[string]interface{}) {
	c.ErrorWithStackSkipWithExtrasAndContext(context.TODO(), level, err, skip, extras)
}
943414
func ErrIfDone(ctx context.Context) error {
	select {
	case <-ctx.Done():
		return ctx.Err()
	default:
		return nil
	}
}
1163980
func (stack ErrorStack) Error() string {
	if len(stack.errors) == 0 {
		return ""
	}

	return stack.formatter(stack.errors)
}
1213439
func (ew *ErrorWaiter) Submit(f func() error) {
	ew.wait.Add(1)
	go func() {
		defer ew.wait.Done()
		if err := f(); err != nil {
			ew.lock.Lock()
			ew.errors = append(ew.errors, err)
			ew.lock.Unlock()
		}
	}()
}
496082
func formatError(err error) string {
	if err, ok := err.(kerrs.Aggregate); ok {
		var errorStrings []string
		for _, err := range err.Errors() {
			errorStrings = append(errorStrings, err.Error())
		}
		return strings.Join(errorStrings, "\n")
	}

	return err.Error()
}
291802
func (c *Client) Do(req *Request) (*http.Response, error) {
	hreq, err := req.HTTPRequest()
	if err != nil {
		return nil, &RestError{Req: hreq, err: fmt.Errorf("error preparing request: %s", err)}
	}

	if !c.KeepAlives {
		hreq.Close = true
	}

	// Internally, this uses c.Driver's CheckRedirect policy.
	resp, err := c.Driver.Do(hreq)
	if err != nil {
		if opErr, ok := err.(*net.OpError); ok {
			if opErr.Timeout() {
				return nil, &RestError{Req: hreq, err: fmt.Errorf("timed out making request")}
			}
		}
		return resp, &RestError{Req: hreq, Resp: resp, err: fmt.Errorf("error sending request: %s", err)}
	}
	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return resp, &RestError{Req: hreq, Resp: resp, err: fmt.Errorf("error in response: %s", resp.Status)}
	}
	return resp, nil
}
1142421
func Do(src, dst string) (diffs []diffmatchpatch.Diff) {
	// the default timeout is time.Second which may be too small under heavy load
	return DoWithTimeout(src, dst, time.Hour)
}
705656
func (m *MultiError) Error() string {
	var s string
	var n int
	for _, err := range *m {
		if err != nil {
			if n == 0 {
				s = err.Error()
			}
			n++
		}
	}
	switch n {
	case 0:
		return ""
	case 1:
		return s
	case 2:
		return s + " and 1 other error"
	}
	return fmt.Sprintf("%s (and %d other errors)", s, n-1)
}
977142
func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error) {
	var resp *http.Response
	var err error

	if c.Debug {
		fmt.Println(req.URL.String())
	}

	err = backoff.Retry(func() error {
		resp, err = c.client.Do(req)
		if err != nil {
			return err
		}
		if c := resp.StatusCode; c == 500 || c >= 502 && c <= 599 {
			// Avoid retry on 501: Not Implemented
			err = &status5xx{}
		}
		return err
	}, c.b)
	c.b.Reset()

	if err != nil {
		if _, ok := err.(*status5xx); !ok {
			return nil, err
		}
	}

	if c.Debug {
		dump, err := httputil.DumpResponse(resp, true)
		if err == nil {
			fmt.Println(string(dump))
		}
	}

	defer func() {
		if rerr := resp.Body.Close(); err == nil {
			err = rerr
		}
	}()

	err = checkResponse(resp)
	if err != nil {
		return resp, err
	}

	if v != nil {
		//bb, _ := ioutil.ReadAll(resp.Body)
		//fmt.Println(string(bb))
		//
		//err := json.Unmarshal(bb, v)
		//if err != nil {
		//	return nil, err
		//}

		err = json.NewDecoder(resp.Body).Decode(v)
		if err != nil {
			return nil, err
		}
	}
	return resp, err
}