1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
// Copyright 2010 Jonas mg
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package user
import (
"errors"
"fmt"
"strconv"
)
var (
ErrUserExist = errors.New("user already exists")
ErrGroupExist = errors.New("group already exists")
)
// IsExist returns whether the error is known to report that an user or group
// already exists. It is satisfied by ErrUserExist and ErrGroupExist.
func IsExist(err error) bool {
if err == ErrUserExist || err == ErrGroupExist {
return true
}
return false
}
// IdUsedError reports the presence of an identifier already used.
type IdUsedError int
func (e IdUsedError) Error() string { return "id used: " + strconv.Itoa(int(e)) }
// A NoFoundError reports the absence of a value.
type NoFoundError struct {
file string
field string
value interface{}
}
func (e NoFoundError) Error() string {
return fmt.Sprintf("entry \"%v\" not found: file '%s', field %q",
e.value, e.file, e.field)
}
// A RequiredError reports the name of a required field.
type RequiredError string
func (e RequiredError) Error() string { return "required field: " + string(e) }
// An atoiError records the file, row and field that caused the error at turning
// a field from string to int.
type atoiError struct {
file string
row string
field string
}
func (e atoiError) Error() string {
return fmt.Sprintf("field %q on '%s' could not be turned to int\n%s",
e.field, e.file, e.row)
}
// A rowError records the file and row for a format not valid.
type rowError struct {
file string
row string
}
func (e rowError) Error() string {
return fmt.Sprintf("format of row not valid on '%s'\n%s", e.file, e.row)
}
|