• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

go-fuego / fuego / 13597338571

28 Feb 2025 10:09PM UTC coverage: 91.398% (+0.1%) from 91.255%
13597338571

Pull #427

github

web-flow
Merge branch 'main' into feature/sql-sqlite-error-mapping
Pull Request #427: feat(sql-sqlite): map SQL and SQLite errors to Fuego HTTP errors

88 of 92 new or added lines in 2 files covered. (95.65%)

2582 of 2825 relevant lines covered (91.4%)

1.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.83
/extra/sqlite3/sqlite_errors.go
1
package sqlite3
2

3
import (
4
        "github.com/mattn/go-sqlite3"
5

6
        "github.com/go-fuego/fuego"
7
)
8

9
// ErrorHandler maps sqlite3.Error errors to specific fuego errors.
10
// It returns a detailed fuego error including Title, Detail (the original error message),
11
// and Err (the original sqlite3.Error).
12
func ErrorHandler(err error) error {
1✔
13
        if err == nil {
1✔
NEW
14
                return nil
×
NEW
15
        }
×
16

17
        sqliteErr, ok := err.(*sqlite3.Error)
1✔
18
        if !ok {
2✔
19
                return err
1✔
20
        }
1✔
21

22
        switch sqliteErr.ExtendedCode {
1✔
23
        case sqlite3.ErrNoExtended(sqlite3.ErrConstraint):
1✔
24
                return fuego.ConflictError{
1✔
25
                        Title:  "Constraint Violation",
1✔
26
                        Detail: sqliteErr.Error(),
1✔
27
                        Err:    sqliteErr,
1✔
28
                }
1✔
29
        case sqlite3.ErrConstraintUnique, sqlite3.ErrConstraintPrimaryKey:
1✔
30
                return fuego.ConflictError{
1✔
31
                        Title:  "Duplicate",
1✔
32
                        Detail: sqliteErr.Error(),
1✔
33
                        Err:    sqliteErr,
1✔
34
                }
1✔
35
        case sqlite3.ErrConstraintForeignKey:
1✔
36
                return fuego.BadRequestError{
1✔
37
                        Title:  "Foreign Key Constraint Failed",
1✔
38
                        Detail: sqliteErr.Error(),
1✔
39
                        Err:    sqliteErr,
1✔
40
                }
1✔
41
        case sqlite3.ErrNoExtended(sqlite3.ErrNotFound):
1✔
42
                return fuego.NotFoundError{
1✔
43
                        Title:  "Record Not Found",
1✔
44
                        Detail: sqliteErr.Error(),
1✔
45
                        Err:    sqliteErr,
1✔
46
                }
1✔
47
        case sqlite3.ErrNoExtended(sqlite3.ErrPerm):
1✔
48
                return fuego.ForbiddenError{
1✔
49
                        Title:  "Permission Denied",
1✔
50
                        Detail: sqliteErr.Error(),
1✔
51
                        Err:    sqliteErr,
1✔
52
                }
1✔
53
        case sqlite3.ErrNoExtended(sqlite3.ErrAuth):
1✔
54
                return fuego.UnauthorizedError{
1✔
55
                        Title:  "Authentication Required",
1✔
56
                        Detail: sqliteErr.Error(),
1✔
57
                        Err:    sqliteErr,
1✔
58
                }
1✔
59
        case sqlite3.ErrNoExtended(sqlite3.ErrBusy), sqlite3.ErrNoExtended(sqlite3.ErrLocked):
1✔
60
                return fuego.InternalServerError{
1✔
61
                        Title:  "Database Locked",
1✔
62
                        Detail: sqliteErr.Error(),
1✔
63
                        Err:    sqliteErr,
1✔
64
                }
1✔
65
        case sqlite3.ErrNoExtended(sqlite3.ErrIoErr):
1✔
66
                return fuego.InternalServerError{
1✔
67
                        Title:  "I/O Error",
1✔
68
                        Detail: sqliteErr.Error(),
1✔
69
                        Err:    sqliteErr,
1✔
70
                }
1✔
71
        default:
1✔
72
                return fuego.InternalServerError{
1✔
73
                        Title:  "Internal Server Error",
1✔
74
                        Detail: sqliteErr.Error(),
1✔
75
                        Err:    sqliteErr,
1✔
76
                }
1✔
77
        }
78
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc