aboutsummaryrefslogtreecommitdiff
path: root/pkg/database/error.go
blob: 0c19752e0d61c98d17e88621b6bf18d46c7ff41f (plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package database

import "fmt"

// database init error
type InitError struct {
	path string
	err  error
}

func (e *InitError) Error() string {
	return fmt.Sprintf("Failed to open database : %s", e.path)
}
func (e *InitError) Unwrap() error { return e.err }

func newInitError(path string, err error) error {
	return &InitError{
		path: path,
		err:  err,
	}
}

// database migration error
type MigrationError struct {
	version int
	err     error
}

func (e *MigrationError) Error() string {
	return fmt.Sprintf("Failed to migrate database to version %d : %s", e.version, e.err)
}
func (e *MigrationError) Unwrap() error { return e.err }

func newMigrationError(version int, err error) error {
	return &MigrationError{
		version: version,
		err:     err,
	}
}

// Password hash error
type PasswordError struct {
	err error
}

func (e *PasswordError) Error() string {
	return fmt.Sprintf("Failed to hash password : %+v", e.err)
}
func (e *PasswordError) Unwrap() error { return e.err }

func newPasswordError(err error) error {
	return &PasswordError{
		err: err,
	}
}

// database query error
type QueryError struct {
	msg string
	err error
}

func (e *QueryError) Error() string {
	return fmt.Sprintf("Failed to perform query : %s", e.msg)
}
func (e *QueryError) Unwrap() error { return e.err }

func newQueryError(msg string, err error) error {
	return &QueryError{
		msg: msg,
		err: err,
	}
}

// database transaction error
type TransactionError struct {
	msg string
	err error
}

func (e *TransactionError) Error() string {
	return fmt.Sprintf("Failed to perform query : %s", e.msg)
}
func (e *TransactionError) Unwrap() error { return e.err }

func newTransactionError(msg string, err error) error {
	return &TransactionError{
		msg: msg,
		err: err,
	}
}