diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-07-17 19:15:48 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-07-17 19:42:13 +0200 |
commit | 10ddc2ef92476573ac7e44823ba9de4e09556d00 (patch) | |
tree | dd9b40c4f33532183d2e84b8ea09e7dc72cb1b4a /common/herrors/errors.go | |
parent | c406fd3a0e0efa17f69095ca6317ba1036fc8964 (diff) | |
download | hugo-fix/postcsserror-9730.tar.gz hugo-fix/postcsserror-9730.zip |
Improve error messages for PostCSS etc.fix/postcsserror-9730
Fixes #9730
Diffstat (limited to 'common/herrors/errors.go')
-rw-r--r-- | common/herrors/errors.go | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/common/herrors/errors.go b/common/herrors/errors.go index 4d8642362..598c50b32 100644 --- a/common/herrors/errors.go +++ b/common/herrors/errors.go @@ -59,11 +59,34 @@ func GetGID() uint64 { return n } +// IsFeatureNotAvailableError returns true if the given error is or contains a FeatureNotAvailableError. +func IsFeatureNotAvailableError(err error) bool { + return errors.Is(err, &FeatureNotAvailableError{}) +} + // ErrFeatureNotAvailable denotes that a feature is unavailable. // // We will, at least to begin with, make some Hugo features (SCSS with libsass) optional, // and this error is used to signal those situations. -var ErrFeatureNotAvailable = errors.New("this feature is not available in your current Hugo version, see https://goo.gl/YMrWcn for more information") +var ErrFeatureNotAvailable = &FeatureNotAvailableError{Cause: errors.New("this feature is not available in your current Hugo version, see https://goo.gl/YMrWcn for more information")} + +// FeatureNotAvailableError is an error type used to signal that a feature is not available. +type FeatureNotAvailableError struct { + Cause error +} + +func (e *FeatureNotAvailableError) Unwrap() error { + return e.Cause +} + +func (e *FeatureNotAvailableError) Error() string { + return e.Cause.Error() +} + +func (e *FeatureNotAvailableError) Is(target error) bool { + _, ok := target.(*FeatureNotAvailableError) + return ok +} // Must panics if err != nil. func Must(err error) { |