blob: 7f2fedb08e2fba940faf8eee81ed1820501fcfbd [file] [log] [blame]
Ben Claytona2a00e22019-02-16 01:05:23 +00001// Copyright 2019 The SwiftShader Authors. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Package cause provides functions for building wrapped errors.
16package cause
17
18import (
19 "fmt"
20)
21
22// errWithCause is an error that wrap an inner error with additional info.
23type errWithCause struct {
24 cause error
25 msg string
26}
27
28func (e errWithCause) Error() string { return fmt.Sprintf("%s. Cause: %v", e.msg, e.cause) }
29
30// Wrap returns a new error wrapping cause with the additional message.
31func Wrap(cause error, msg string, args ...interface{}) error {
32 return errWithCause{cause, fmt.Sprintf(msg, args...)}
33}