// NewUploadWriteFailed returns a new UploadWriteFailed instance
18612
func NewUploadWriteFailed(Reason *WriteError, UploadSessionId string) *UploadWriteFailed {
	s := new(UploadWriteFailed)
	s.Reason = Reason
	s.UploadSessionId = UploadSessionId
	return s
}
449876
func NewWriteCloserOnError(w io.WriteCloser, notify func(error)) io.WriteCloser {
	return NewWriteCloser(NewWriterOnError(w, notify), w)
}
1350181
func (c *Peer) WriteError(e string) {
	c.Block(func(w *Writer) {
		w.WriteError(e)
	})
}
377690
func newfileUploadRequest(gr *GoReq, params map[string]string, paramName, filePath string) (*bytes.Buffer, error) {
	file, err := os.Open(filePath)
	if err != nil {
		return nil, err
	}
	fileContents, err := ioutil.ReadAll(file)
	if err != nil {
		return nil, err
	}
	fi, err := file.Stat()
	if err != nil {
		return nil, err
	}
	file.Close()

	body := new(bytes.Buffer)
	writer := multipart.NewWriter(body)
	part, err := writer.CreateFormFile(paramName, fi.Name())
	if err != nil {
		return nil, err
	}
	part.Write(fileContents)

	for key, val := range params {
		_ = writer.WriteField(key, val)
	}
	err = writer.Close()
	if err != nil {
		return nil, err
	}

	gr.Header["Content-Type"] = writer.FormDataContentType()
	return body, nil
}
567951
func ErrPUPolicyEnforcementFailed(puID string, err error) error {
	return &Error{
		puID:   puID,
		reason: PUPolicyEnforcementFailed,
		err:    err,
	}
}
30048
func NewWriteFlusher(w io.Writer) *WriteFlusher {
	var fl flusher
	if f, ok := w.(flusher); ok {
		fl = f
	} else {
		fl = &NopFlusher{}
	}
	return &WriteFlusher{w: w, flusher: fl, closed: make(chan struct{}), flushed: make(chan struct{})}
}
179421
func FatalFailed(fr FatalPrinter, msg string, v ...interface{}) {
	fr.Fatal(Failed(msg, v...))
}
630588
func (p *printer) cachedWriteError() error {
	_, err := p.Write(nil)
	return err
}
24890
func NewConsoleWithWriter(opts string, stdout, stderr io.Writer) logger.Provider {
	config := NewConsoleOpts()
	logger.UnmarshalOpts(opts, &config)
	return &Console{
		config: config,
		stdout: stdout,
		stderr: stderr,
	}
}
484358
func NewWriteAccessError(h *Handle, username kbname.NormalizedUsername, filename string) error {
	tlfName := tlf.CanonicalName("")
	t := tlf.Private
	if h != nil {
		tlfName = h.GetCanonicalName()
		t = h.Type()
	}
	return WriteAccessError{
		User:     username,
		Filename: filename,
		Tlf:      tlfName,
		Type:     t,
	}
}
736912
func ErrKubeConfigNotWriteable(file string, isExplicitFile bool, err error) error {
	return NewError("KUBECONFIG is set to a file that cannot be created or modified: %s", file).WithCause(err).WithSolution(kubeConfigSolution(isExplicitFile))
}
236968
func NewRequestFailure(err awserr.RequestFailure, hostID string) *RequestFailure {
	return &RequestFailure{RequestFailure: err, hostID: hostID}
}
777336
func writeError(c *routing.Context, err error) {
	if httpError, ok := err.(routing.HTTPError); ok {
		c.Response.WriteHeader(httpError.StatusCode())
	} else {
		c.Response.WriteHeader(http.StatusInternalServerError)
	}
	c.Write(err)
}
825438
func IsErrPUCreateFailed(err error) bool {
	switch t := err.(type) {
	case *Error:
		return t.reason == PUCreateFailed
	default:
		return false
	}
}
1182826
func makeFailedAlloc(add *structs.Allocation, err error) *structs.Allocation {
	stripped := new(structs.Allocation)
	stripped.ID = add.ID
	stripped.NodeID = add.NodeID
	stripped.ClientStatus = structs.AllocClientStatusFailed
	stripped.ClientDescription = fmt.Sprintf("Unable to add allocation due to error: %v", err)

	// Copy task states if it exists in the original allocation
	if add.TaskStates != nil {
		stripped.TaskStates = add.TaskStates
	} else {
		stripped.TaskStates = make(map[string]*structs.TaskState)
	}

	failTime := time.Now()
	if add.DeploymentStatus.HasHealth() {
		// Never change deployment health once it has been set
		stripped.DeploymentStatus = add.DeploymentStatus.Copy()
	} else {
		stripped.DeploymentStatus = &structs.AllocDeploymentStatus{
			Healthy:   helper.BoolToPtr(false),
			Timestamp: failTime,
		}
	}

	taskGroup := add.Job.LookupTaskGroup(add.TaskGroup)
	if taskGroup == nil {
		return stripped
	}
	for _, task := range taskGroup.Tasks {
		ts, ok := stripped.TaskStates[task.Name]
		if !ok {
			ts = &structs.TaskState{}
			stripped.TaskStates[task.Name] = ts
		}
		if ts.FinishedAt.IsZero() {
			ts.FinishedAt = failTime
		}
	}
	return stripped
}
1346833
func (client *Client) UploadCreate(project_id string, params *UploadParams) (*Upload, error) {
	retVal := new(Upload)
	err := func() error {

		url := fmt.Sprintf("/v2/projects/%s/uploads", url.QueryEscape(project_id))

		paramsBuf := bytes.NewBuffer(nil)
		writer := multipart.NewWriter(paramsBuf)
		ctype := writer.FormDataContentType()

		if params.Autotranslate != nil {
			err := writer.WriteField("autotranslate", strconv.FormatBool(*params.Autotranslate))
			if err != nil {
				return err
			}
		}

		if params.Branch != nil {
			err := writer.WriteField("branch", *params.Branch)
			if err != nil {
				return err
			}
		}

		if params.ConvertEmoji != nil {
			err := writer.WriteField("convert_emoji", strconv.FormatBool(*params.ConvertEmoji))
			if err != nil {
				return err
			}
		}

		if params.File != nil {
			part, err := writer.CreateFormFile("file", filepath.Base(*params.File))
			if err != nil {
				return err
			}
			file, err := os.Open(*params.File)
			if err != nil {
				return err
			}
			_, err = io.Copy(part, file)
			if err != nil {
				return err
			}
			err = file.Close()
			if err != nil {
				return err
			}
		}

		if params.FileEncoding != nil {
			err := writer.WriteField("file_encoding", *params.FileEncoding)
			if err != nil {
				return err
			}
		}

		if params.FileFormat != nil {
			err := writer.WriteField("file_format", *params.FileFormat)
			if err != nil {
				return err
			}
		}

		if params.FormatOptions != nil {
			for key, val := range params.FormatOptions {
				err := writer.WriteField("format_options["+key+"]", val)
				if err != nil {
					return err
				}
			}
		}

		if params.LocaleID != nil {
			err := writer.WriteField("locale_id", *params.LocaleID)
			if err != nil {
				return err
			}
		}

		if params.LocaleMapping != nil {
			for key, val := range params.LocaleMapping {
				err := writer.WriteField("locale_mapping["+key+"]", val)
				if err != nil {
					return err
				}
			}
		}

		if params.MarkReviewed != nil {
			err := writer.WriteField("mark_reviewed", strconv.FormatBool(*params.MarkReviewed))
			if err != nil {
				return err
			}
		}

		if params.SkipUnverification != nil {
			err := writer.WriteField("skip_unverification", strconv.FormatBool(*params.SkipUnverification))
			if err != nil {
				return err
			}
		}

		if params.SkipUploadTags != nil {
			err := writer.WriteField("skip_upload_tags", strconv.FormatBool(*params.SkipUploadTags))
			if err != nil {
				return err
			}
		}

		if params.Tags != nil {
			err := writer.WriteField("tags", *params.Tags)
			if err != nil {
				return err
			}
		}

		if params.UpdateDescriptions != nil {
			err := writer.WriteField("update_descriptions", strconv.FormatBool(*params.UpdateDescriptions))
			if err != nil {
				return err
			}
		}

		if params.UpdateTranslations != nil {
			err := writer.WriteField("update_translations", strconv.FormatBool(*params.UpdateTranslations))
			if err != nil {
				return err
			}
		}
		err := writer.WriteField("utf8", "✓")
		writer.Close()

		rc, err := client.sendRequest("POST", url, ctype, paramsBuf, 201)
		if err != nil {
			return err
		}
		defer rc.Close()

		var reader io.Reader
		if client.debug {
			reader = io.TeeReader(rc, os.Stderr)
		} else {
			reader = rc
		}

		return json.NewDecoder(reader).Decode(&retVal)

	}()
	return retVal, err
}
960385
func (h *JSONWriter) WriteError(w http.ResponseWriter, r *http.Request, err interface{}) {
	if s, ok := errors.Cause(toError(err)).(statusCodeCarrier); ok {
		h.WriteErrorCode(w, r, s.StatusCode(), err)
		return
	}

	h.WriteErrorCode(w, r, http.StatusInternalServerError, err)
	return
}