blob: c464e8ac08c878b5dfa4ed12e169a6aeac8d131a [file] [log] [blame]
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package zx
import "internal/oserror"
// Error is a Status with associated error text.
// It is used as a Go error.
type Error struct {
Status Status
Text string
}
var _ error = (*Error)(nil)
func (e *Error) Error() string {
if e.Text == "" {
return "zx.Status: " + e.Status.String()
}
return e.Status.String() + ": " + e.Text
}
func (e *Error) Is(target error) bool {
switch target {
case oserror.ErrPermission:
return e.Status == ErrAccessDenied
case oserror.ErrExist:
return e.Status == ErrAlreadyExists
case oserror.ErrNotExist:
return e.Status == ErrNotFound
}
return false
}