mirror of
https://github.com/vbatts/go-mtree.git
synced 2025-10-04 04:31:00 +00:00
govis: modernise errors
This code was written before %w was added to Go, and there were a fair few mistakes in the copy-pasted error code. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
parent
3ce83fca15
commit
fbada2e081
4 changed files with 89 additions and 58 deletions
|
@ -19,6 +19,8 @@
|
|||
package govis
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
@ -44,6 +46,25 @@ const (
|
|||
VisWhite VisFlag = (VisSpace | VisTab | VisNewline)
|
||||
)
|
||||
|
||||
// errUnknownVisFlagsError is a special value that lets you use [errors.Is]
|
||||
// with [unknownVisFlagsError]. Don't actually return this value, use
|
||||
// [unknownVisFlagsError] instead!
|
||||
var errUnknownVisFlagsError = errors.New("unknown or unsupported vis flags")
|
||||
|
||||
// unknownVisFlagsError represents an error caused by unknown [VisFlag]s being
|
||||
// passed to [Vis] or [Unvis].
|
||||
type unknownVisFlagsError struct {
|
||||
flags VisFlag
|
||||
}
|
||||
|
||||
func (err unknownVisFlagsError) Is(target error) bool {
|
||||
return target == errUnknownVisFlagsError
|
||||
}
|
||||
|
||||
func (err unknownVisFlagsError) Error() string {
|
||||
return fmt.Sprintf("%s contains unknown or unsupported flags %s", err.flags, err.flags&^visMask)
|
||||
}
|
||||
|
||||
// String pretty-prints VisFlag.
|
||||
func (vflags VisFlag) String() string {
|
||||
flagNames := []struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue