Rework error messages

This commit reworks error messages for all commands and makes sure they
pass liniting.
This commit is contained in:
Tom Wiesing 2023-03-09 11:13:19 +01:00
parent d22784e6f5
commit c31c46ee44
No known key found for this signature in database
40 changed files with 249 additions and 110 deletions

View file

@ -28,7 +28,7 @@ func MetaConfigPath() (string, error) {
return filepath.Join(usr.HomeDir, metaConfigFile), nil
}
var errReadBaseDirectoryEmpty = errors.New("ReadBaseDirectory: Directory is empty")
var errReadBaseDirectoryEmpty = errors.New("`ReadBaseDirectory': directory is empty")
// ReadBaseDirectory reads the base deployment directory from the environment.
// Use [ParamsFromEnv] to initialize parameters completely.

View file

@ -66,7 +66,7 @@ func AllPermissions(clauses ...Permission) Permission {
}
}
var errPermissionPanic = errors.New("permission: panic()")
var errPermissionPanic = errors.New("permission: `panic()'")
// Permit checks if the given user has this permission.
func (perm Permission) Permit(user *AuthUser, r *http.Request) (ok Grant, err error) {

View file

@ -128,12 +128,7 @@ var loginTemplate = templating.ParseForm(
templating.Assets(assets.AssetsUser),
)
var loginResponse = httpx.Response{
ContentType: "text/plain",
Body: []byte("user is signed in"),
}
var errLoginFailed = errors.New("Login failed")
var errLoginFailed = errors.New("login failed")
// authLogin implements a view to login a user
func (auth *Auth) authLogin(ctx context.Context) http.Handler {

View file

@ -9,7 +9,7 @@ import (
"github.com/tkw1536/goprogram/stream"
)
var errSQLBackup = errors.New("SQLBackup: Mysqldump returned non-zero exit code")
var errSQLBackup = errors.New("`SQLBackup': mysqldump returned non-zero exit code")
func (*SQL) BackupName() string {
return "sql.sql"

View file

@ -9,8 +9,8 @@ import (
"github.com/tkw1536/pkglib/sqlx"
)
var errProvisionInvalidDatabaseParams = errors.New("Provision: Invalid parameters")
var errProvisionInvalidGrant = errors.New("Provision: Grant failed")
var errProvisionInvalidDatabaseParams = errors.New("`Provision': invalid parameters")
var errProvisionInvalidGrant = errors.New("`Provision': grant failed")
// Provision provisions sql-specific resource for the given instance
func (sql *SQL) Provision(ctx context.Context, instance models.Instance, domain string) error {
@ -58,7 +58,7 @@ func (sql *SQL) CreateDatabase(ctx context.Context, name, user, password string)
return nil
}
var errCreateSuperuserGrant = errors.New("CreateSuperUser: Grant failed")
var errCreateSuperuserGrant = errors.New("`CreateSuperUser': grant failed")
// CreateSuperuser createsa new user, with the name 'user' and the password 'password'.
// It then grants this user superuser status in the database.
@ -93,7 +93,7 @@ func (sql *SQL) CreateSuperuser(ctx context.Context, user, password string, allo
return nil
}
var errPurgeUser = errors.New("PurgeUser: Failed to drop user")
var errPurgeUser = errors.New("`PurgeUser': failed to drop user")
// SQLPurgeUser deletes the specified user from the database
func (sql *SQL) PurgeUser(ctx context.Context, user string) error {

View file

@ -60,7 +60,7 @@ func (sb SQLBit1) Value() (driver.Value, error) {
}
}
var errBadBool = errors.New("SQLBit1: Database does not contain Bit(1)")
var errBadBool = errors.New("`SQLBit1': database does not contain `Bit(1)'")
func (sb *SQLBit1) Scan(src interface{}) error {
if bytes, ok := src.([]byte); ok && len(bytes) == 1 {

View file

@ -46,7 +46,7 @@ func (b Boolean) MarshalJSON() ([]byte, error) {
return []byte("false"), nil
}
var errNotABoolean = errors.New("Boolean.UnmarshalJSON: Not an integer")
var errNotABoolean = errors.New("`Boolean': not an integer")
func (b *Boolean) UnmarshalJSON(data []byte) (err error) {
return UnmarshalIntermediate(b, func(a any) (Boolean, error) {
@ -100,7 +100,7 @@ func (s String) MarshalJSON() ([]byte, error) {
return json.Marshal(string(s))
}
var errNotAString = errors.New("String.UnmarshalJSON: Not a string")
var errNotAString = errors.New("`String': not a string")
func (s *String) UnmarshalJSON(data []byte) (err error) {
return UnmarshalIntermediate(s, func(a any) (String, error) {
@ -148,7 +148,7 @@ func (i Integer) MarshalJSON() ([]byte, error) {
return json.Marshal(int64(i))
}
var errNotAnInteger = errors.New("Integer.UnmarshalJSON: Not an integer")
var errNotAnInteger = errors.New("`Integer': not an integer")
func (i *Integer) UnmarshalJSON(data []byte) (err error) {
return UnmarshalIntermediate(i, func(a any) (Integer, error) {

View file

@ -14,6 +14,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/php"
"github.com/FAU-CDI/wisski-distillery/pkg/fsx"
"github.com/tkw1536/pkglib/collection"
"golang.org/x/exp/slices"
_ "embed"
)
@ -110,7 +111,7 @@ func (prefixes *Prefixes) blocked() ([]string, error) {
}
func hasAnyPrefix(candidate string, prefixes []string) bool {
return collection.Any(
return slices.ContainsFunc(
prefixes,
func(prefix string) bool {
return strings.HasPrefix(candidate, prefix)

View file

@ -11,7 +11,7 @@ import (
"github.com/tkw1536/pkglib/password"
)
var errGetValidator = errors.New("GetPasswordValidator: Unknown Error")
var errGetValidator = errors.New("`GetPasswordValidator': unknown error")
func (u *Users) GetPasswordValidator(ctx context.Context, username string) (pv PasswordValidator, err error) {
server := u.Dependencies.PHP.NewServer()
@ -53,7 +53,7 @@ func (pv PasswordValidator) Check(ctx context.Context, password string) bool {
return bool(result)
}
var errPasswordUsername = errors.New("username === password")
var errPasswordUsername = errors.New("username equals password")
func (pv PasswordValidator) CheckDictionary(ctx context.Context, writer io.Writer) error {
var counter int

View file

@ -32,7 +32,7 @@ func (u *Users) All(ctx context.Context, server *phpx.Server) (users []status.Dr
return
}
var errLoginUnknownError = errors.New("Login: Unknown Error")
var errLoginUnknownError = errors.New("`Login': unknown error")
// Login generates a login link for the user with the given username
func (u *Users) Login(ctx context.Context, server *phpx.Server, username string) (dest *url.URL, err error) {
@ -75,7 +75,7 @@ func (u *Users) LoginWithOpt(ctx context.Context, server *phpx.Server, username
return
}
var errSetPassword = errors.New("SetPassword: Unknown Error")
var errSetPassword = errors.New("`SetPassword': unknown error")
// SetPassword sets the password for a given user
func (u *Users) SetPassword(ctx context.Context, server *phpx.Server, username, password string) error {