main
1//go:build linux && !go1.20
2
3// Copyright (C) 2024 SUSE LLC. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7package securejoin
8
9import (
10 "fmt"
11)
12
13type wrappedError struct {
14 inner error
15 isError error
16}
17
18func (err wrappedError) Is(target error) bool {
19 return err.isError == target
20}
21
22func (err wrappedError) Unwrap() error {
23 return err.inner
24}
25
26func (err wrappedError) Error() string {
27 return fmt.Sprintf("%v: %v", err.isError, err.inner)
28}
29
30// wrapBaseError is a helper that is equivalent to fmt.Errorf("%w: %w"), except
31// that on pre-1.20 Go versions only errors.Is() works properly (errors.Unwrap)
32// is only guaranteed to give you baseErr.
33func wrapBaseError(baseErr, extraErr error) error {
34 return wrappedError{
35 inner: baseErr,
36 isError: extraErr,
37 }
38}