mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-26 10:36:23 -07:00
Use fmt.Errorf and %w for unwrappable errors
This commit is contained in:
parent
5d782c4eab
commit
442319e77a
14 changed files with 68 additions and 65 deletions
|
@ -21,7 +21,7 @@ import (
|
|||
|
||||
const (
|
||||
dirIsAFileStr = `unable to create %q, path exists and is a file`
|
||||
genericErrStr = `unable to create %q: %s`
|
||||
genericErrStr = `unable to create %q: %w`
|
||||
pathExistsStr = `unable to create %q, path already exists`
|
||||
)
|
||||
|
||||
|
@ -63,12 +63,12 @@ func BuildBoardPages(board *gcsql.Board, errEv *zerolog.Event) error {
|
|||
if err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Msg("Failed getting board threads")
|
||||
return fmt.Errorf("error getting threads for /%s/: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("error getting threads for /%s/: %w", board.Dir, err)
|
||||
}
|
||||
topPosts, err := getBoardTopPosts(board.Dir)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Failed getting board threads")
|
||||
return fmt.Errorf("error getting OP posts for /%s/: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("error getting OP posts for /%s/: %w", board.Dir, err)
|
||||
}
|
||||
opMap := make(map[int]*Post)
|
||||
for _, post := range topPosts {
|
||||
|
@ -102,13 +102,13 @@ func BuildBoardPages(board *gcsql.Board, errEv *zerolog.Event) error {
|
|||
catalogThread.Replies, err = thread.GetReplyCount()
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Failed getting reply count")
|
||||
return errors.New("Error getting reply count: " + err.Error())
|
||||
return fmt.Errorf("error getting reply count: %w", err)
|
||||
}
|
||||
|
||||
catalogThread.Posts, err = getThreadPosts(&thread)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Failed getting replies")
|
||||
return errors.New("Failed getting replies: " + err.Error())
|
||||
return fmt.Errorf("failed getting replies: %w", err)
|
||||
}
|
||||
if len(catalogThread.Posts) == 0 {
|
||||
continue
|
||||
|
@ -122,7 +122,7 @@ func BuildBoardPages(board *gcsql.Board, errEv *zerolog.Event) error {
|
|||
catalogThread.uploads, err = thread.GetUploads()
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Failed getting thread uploads")
|
||||
return errors.New("Failed getting thread uploads: " + err.Error())
|
||||
return fmt.Errorf("failed getting thread uploads: %w", err)
|
||||
}
|
||||
|
||||
var imagesOnBoardPage int
|
||||
|
@ -157,14 +157,14 @@ func BuildBoardPages(board *gcsql.Board, errEv *zerolog.Event) error {
|
|||
errEv.Err(err).Caller().
|
||||
Str("page", "board.html").
|
||||
Msg("Failed getting board page")
|
||||
return fmt.Errorf("failed opening /%s/board.html: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("failed opening /%s/board.html: %w", board.Dir, err)
|
||||
}
|
||||
defer boardPageFile.Close()
|
||||
|
||||
if err = config.TakeOwnershipOfFile(boardPageFile); err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Msg("Unable to take ownership of board.html")
|
||||
return fmt.Errorf("unable to take ownership of /%s/board.html: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("unable to take ownership of /%s/board.html: %w", board.Dir, err)
|
||||
}
|
||||
// Render board page template to the file,
|
||||
// packaging the board/section list, threads, and board info
|
||||
|
@ -183,7 +183,7 @@ func BuildBoardPages(board *gcsql.Board, errEv *zerolog.Event) error {
|
|||
errEv.Err(err).Caller().
|
||||
Str("page", "board.html").
|
||||
Msg("Failed building board")
|
||||
return fmt.Errorf("failed building /%s/: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("failed building /%s/: %w", board.Dir, err)
|
||||
}
|
||||
|
||||
if err = boardPageFile.Close(); err != nil {
|
||||
|
@ -207,14 +207,14 @@ func BuildBoardPages(board *gcsql.Board, errEv *zerolog.Event) error {
|
|||
if err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Msg("Failed opening catalog.json")
|
||||
return fmt.Errorf("failed opening /%s/catalog.json: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("failed opening /%s/catalog.json: %w", board.Dir, err)
|
||||
}
|
||||
defer catalogJSONFile.Close()
|
||||
|
||||
if err = config.TakeOwnershipOfFile(catalogJSONFile); err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Msg("Unable to take ownership of catalog.json")
|
||||
return fmt.Errorf("unable to take ownership of /%s/catalog.json: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("unable to take ownership of /%s/catalog.json: %w", board.Dir, err)
|
||||
}
|
||||
for _, page := range catalog.pages {
|
||||
catalog.currentPage++
|
||||
|
@ -262,7 +262,7 @@ func BuildBoardPages(board *gcsql.Board, errEv *zerolog.Event) error {
|
|||
}
|
||||
if err = serverutil.MinifyTemplate(gctemplates.BoardPage, data, currentPageFile, "text/html"); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return fmt.Errorf("failed building /%s/ boardpage: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("failed building /%s/ boardpage: %w", board.Dir, err)
|
||||
}
|
||||
if err = currentPageFile.Close(); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
|
@ -307,7 +307,7 @@ func BuildBoards(verbose bool, which ...int) error {
|
|||
errEv.Err(err).Caller().
|
||||
Int("boardid", boardID).
|
||||
Msg("Unable to get board information")
|
||||
return fmt.Errorf("unable to get board information (ID: %d): %s", boardID, err.Error())
|
||||
return fmt.Errorf("unable to get board information (ID: %d): %w", boardID, err)
|
||||
}
|
||||
boards = append(boards, *board)
|
||||
}
|
||||
|
@ -446,12 +446,12 @@ func buildBoard(board *gcsql.Board, force bool) error {
|
|||
} else if err = os.Mkdir(dirPath, config.DirFileMode); err != nil {
|
||||
errEv.Err(os.ErrExist).Caller().
|
||||
Str("dirPath", dirPath).Send()
|
||||
return fmt.Errorf(genericErrStr, dirPath, err.Error())
|
||||
return fmt.Errorf(genericErrStr, dirPath, err)
|
||||
}
|
||||
if err = config.TakeOwnership(dirPath); err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("dirPath", dirPath).Send()
|
||||
return fmt.Errorf(genericErrStr, dirPath, err.Error())
|
||||
return fmt.Errorf(genericErrStr, dirPath, err)
|
||||
}
|
||||
|
||||
if resInfo != nil {
|
||||
|
@ -468,15 +468,15 @@ func buildBoard(board *gcsql.Board, force bool) error {
|
|||
return err
|
||||
}
|
||||
} else if err = os.Mkdir(resPath, config.DirFileMode); err != nil {
|
||||
err = fmt.Errorf(genericErrStr, resPath, err.Error())
|
||||
err = fmt.Errorf(genericErrStr, resPath, err)
|
||||
errEv.Err(err).Caller().
|
||||
Str("resPath", resPath).Send()
|
||||
return fmt.Errorf(genericErrStr, resPath, err.Error())
|
||||
return fmt.Errorf(genericErrStr, resPath, err)
|
||||
}
|
||||
if err = config.TakeOwnership(resPath); err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("resPath", resPath).Send()
|
||||
return fmt.Errorf(genericErrStr, resPath, err.Error())
|
||||
return fmt.Errorf(genericErrStr, resPath, err)
|
||||
}
|
||||
|
||||
if srcInfo != nil {
|
||||
|
@ -493,7 +493,7 @@ func buildBoard(board *gcsql.Board, force bool) error {
|
|||
return err
|
||||
}
|
||||
} else if err = os.Mkdir(srcPath, config.DirFileMode); err != nil {
|
||||
err = fmt.Errorf(genericErrStr, srcPath, err.Error())
|
||||
err = fmt.Errorf(genericErrStr, srcPath, err)
|
||||
errEv.Err(err).Caller().
|
||||
Str("srcPath", srcPath).Send()
|
||||
return err
|
||||
|
@ -501,7 +501,7 @@ func buildBoard(board *gcsql.Board, force bool) error {
|
|||
if config.TakeOwnership(srcPath); err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("srcPath", srcPath).Send()
|
||||
return fmt.Errorf(genericErrStr, srcPath, err.Error())
|
||||
return fmt.Errorf(genericErrStr, srcPath, err)
|
||||
}
|
||||
|
||||
if thumbInfo != nil {
|
||||
|
@ -514,12 +514,12 @@ func buildBoard(board *gcsql.Board, force bool) error {
|
|||
} else if err = os.Mkdir(thumbPath, config.DirFileMode); err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("thumbPath", thumbPath).Send()
|
||||
return fmt.Errorf(genericErrStr, thumbPath, err.Error())
|
||||
return fmt.Errorf(genericErrStr, thumbPath, err)
|
||||
}
|
||||
if config.TakeOwnership(thumbPath); err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("thumbPath", thumbPath).Send()
|
||||
return fmt.Errorf(genericErrStr, thumbPath, err.Error())
|
||||
return fmt.Errorf(genericErrStr, thumbPath, err)
|
||||
}
|
||||
|
||||
if err = BuildBoardPages(board, errEv); err != nil {
|
||||
|
@ -562,12 +562,12 @@ func BuildBoardListJSON() error {
|
|||
defer errEv.Discard()
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return errors.New("unable to open boards.json for writing: " + err.Error())
|
||||
return fmt.Errorf("unable to open boards.json for writing: %w", err)
|
||||
}
|
||||
|
||||
if err = config.TakeOwnershipOfFile(boardListFile); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return errors.New("unable to update boards.json ownership: " + err.Error())
|
||||
return fmt.Errorf("unable to update boards.json ownership: %w", err)
|
||||
}
|
||||
|
||||
boardsListJSONData := boardsListJSON{
|
||||
|
@ -585,15 +585,15 @@ func BuildBoardListJSON() error {
|
|||
boardJSON, err := json.Marshal(boardsListJSONData)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return errors.New("Failed to create boards.json " + err.Error())
|
||||
return fmt.Errorf("failed to create boards.json: %w", err)
|
||||
}
|
||||
|
||||
if _, err = serverutil.MinifyWriter(boardListFile, boardJSON, "application/json"); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
errEv.Err(err).Caller().Msg("Failed writing to boards.json")
|
||||
return errors.New("failed writing boards.json file")
|
||||
}
|
||||
if err = boardListFile.Close(); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
errEv.Err(err).Caller().Msg("Failed closing boards.json")
|
||||
return errors.New("failed closing boards.json")
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package building
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
@ -84,18 +83,18 @@ func BuildFrontPage() error {
|
|||
err := gctemplates.InitTemplates(gctemplates.FrontPage)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return errors.New("Error loading front page template: " + err.Error())
|
||||
return fmt.Errorf("failed loading front page template: %w", err)
|
||||
}
|
||||
criticalCfg := config.GetSystemCriticalConfig()
|
||||
frontFile, err := os.OpenFile(path.Join(criticalCfg.DocumentRoot, "index.html"), os.O_CREATE|os.O_RDWR|os.O_TRUNC, config.NormalFileMode)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return errors.New("Failed opening front page for writing: " + err.Error())
|
||||
return fmt.Errorf("failed opening front page for writing: %w", err)
|
||||
}
|
||||
|
||||
if err = config.TakeOwnershipOfFile(frontFile); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return errors.New("Failed setting file ownership for front page: " + err.Error())
|
||||
return fmt.Errorf("failed setting file ownership for front page: %w", err)
|
||||
}
|
||||
|
||||
var recentPostsArr []frontPagePost
|
||||
|
@ -103,7 +102,7 @@ func BuildFrontPage() error {
|
|||
recentPostsArr, err = getFrontPagePosts()
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return errors.New("Failed loading recent posts: " + err.Error())
|
||||
return fmt.Errorf("failed loading recent posts: %w", err)
|
||||
}
|
||||
if err = serverutil.MinifyTemplate(gctemplates.FrontPage, map[string]interface{}{
|
||||
"siteConfig": siteCfg,
|
||||
|
@ -113,7 +112,7 @@ func BuildFrontPage() error {
|
|||
"recentPosts": recentPostsArr,
|
||||
}, frontFile, "text/html"); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return errors.New("Failed executing front page template: " + err.Error())
|
||||
return fmt.Errorf("failed executing front page template: %w", err)
|
||||
}
|
||||
return frontFile.Close()
|
||||
}
|
||||
|
@ -139,7 +138,7 @@ func BuildPageHeader(writer io.Writer, pageTitle string, board string, misc map[
|
|||
// of every normal HTML page
|
||||
func BuildPageFooter(writer io.Writer) (err error) {
|
||||
return serverutil.MinifyTemplate(gctemplates.PageFooter,
|
||||
map[string]interface{}{}, writer, "text/html")
|
||||
map[string]any{}, writer, "text/html")
|
||||
}
|
||||
|
||||
// BuildJS minifies (if enabled) consts.js, which is built from a template
|
||||
|
@ -150,7 +149,7 @@ func BuildJS() error {
|
|||
defer errEv.Discard()
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return errors.New("Error loading consts.js template:" + err.Error())
|
||||
return fmt.Errorf("failed loading consts.js template: %w", err)
|
||||
}
|
||||
|
||||
boardCfg := config.GetBoardConfig("")
|
||||
|
@ -159,12 +158,12 @@ func BuildJS() error {
|
|||
constsJSFile, err := os.OpenFile(constsJSPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, config.NormalFileMode)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return fmt.Errorf("error opening consts.js for writing: %s", err.Error())
|
||||
return fmt.Errorf("failed opening consts.js for writing: %w", err)
|
||||
}
|
||||
|
||||
if err = config.TakeOwnershipOfFile(constsJSFile); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return fmt.Errorf("unable to update file ownership for consts.js: %s", err.Error())
|
||||
return fmt.Errorf("unable to update file ownership for consts.js: %w", err)
|
||||
}
|
||||
|
||||
if err = serverutil.MinifyTemplate(gctemplates.JsConsts, map[string]any{
|
||||
|
@ -175,7 +174,7 @@ func BuildJS() error {
|
|||
"fileTypes": boardCfg.AllowOtherExtensions,
|
||||
}, constsJSFile, "text/javascript"); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return fmt.Errorf("error building consts.js: %s", err.Error())
|
||||
return fmt.Errorf("failed building consts.js: %w", err)
|
||||
}
|
||||
return constsJSFile.Close()
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ func BuildCatalog(boardID int) error {
|
|||
catalogFile, err := os.OpenFile(catalogPath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, config.NormalFileMode)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return fmt.Errorf("failed opening /%s/catalog.html: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("failed opening /%s/catalog.html: %w", board.Dir, err)
|
||||
}
|
||||
|
||||
if err = config.TakeOwnershipOfFile(catalogFile); err != nil {
|
||||
|
|
|
@ -84,12 +84,12 @@ func BuildThreadPages(op *gcsql.Post) error {
|
|||
threadPageFile, err = os.OpenFile(threadPageFilepath, os.O_CREATE|os.O_RDWR|os.O_TRUNC, config.NormalFileMode)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return fmt.Errorf("unable to open /%s/res/%d.html: %s", board.Dir, op.ID, err.Error())
|
||||
return fmt.Errorf("unable to open /%s/res/%d.html: %w", board.Dir, op.ID, err)
|
||||
}
|
||||
|
||||
if err = config.TakeOwnershipOfFile(threadPageFile); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return fmt.Errorf("unable to set file permissions for /%s/res/%d.html: %s", board.Dir, op.ID, err.Error())
|
||||
return fmt.Errorf("unable to set file permissions for /%s/res/%d.html: %w", board.Dir, op.ID, err)
|
||||
}
|
||||
errEv.Int("op", posts[0].ID)
|
||||
|
||||
|
@ -107,7 +107,7 @@ func BuildThreadPages(op *gcsql.Post) error {
|
|||
"captcha": captchaCfg,
|
||||
}, threadPageFile, "text/html"); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return fmt.Errorf("failed building /%s/res/%d threadpage: %s", board.Dir, posts[0].ID, err.Error())
|
||||
return fmt.Errorf("failed building /%s/res/%d threadpage: %w", board.Dir, posts[0].ID, err)
|
||||
}
|
||||
if err = threadPageFile.Close(); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
|
|
|
@ -176,7 +176,7 @@ func ResetBoardSectionArrays() error {
|
|||
AllBoards = append(AllBoards, allBoardsArr...)
|
||||
for _, board := range AllBoards {
|
||||
if err = config.UpdateBoardConfig(board.Dir); err != nil {
|
||||
return fmt.Errorf("unable to update board config for /%s/: %s", board.Dir, err.Error())
|
||||
return fmt.Errorf("unable to update board config for /%s/: %w", board.Dir, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -126,10 +126,10 @@ func buildNewDatabase(dbType string) error {
|
|||
return err
|
||||
}
|
||||
if err = createDefaultAdminIfNoStaff(); err != nil {
|
||||
return errors.New("failed creating default admin account: " + err.Error())
|
||||
return fmt.Errorf("failed creating default admin account: %w", err)
|
||||
}
|
||||
if err = createDefaultBoardIfNoneExist(); err != nil {
|
||||
return errors.New("failed creating default board if non already exists: " + err.Error())
|
||||
return fmt.Errorf("failed creating default board if non already exists: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ func EndStaffSession(writer http.ResponseWriter, request *http.Request) error {
|
|||
if err = QueryRowContextSQL(ctx, nil, `SELECT staff_id FROM DBPREFIXsessions WHERE data = ?`,
|
||||
[]any{session.Value}, []any{&staffID}); err != nil && err != sql.ErrNoRows {
|
||||
// something went wrong with the query and it's not caused by no rows being returned
|
||||
return errors.New("failed getting staff ID: " + err.Error())
|
||||
return fmt.Errorf("failed getting staff ID: %w", err)
|
||||
}
|
||||
|
||||
_, err = ExecContextSQL(ctx, nil, `DELETE FROM DBPREFIXsessions WHERE data = ?`, sessionVal)
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/gochan-org/gochan/pkg/events"
|
||||
)
|
||||
|
@ -61,7 +62,7 @@ func (p *Post) AttachFileTx(tx *sql.Tx, upload *Upload) error {
|
|||
return errors.New("recovered from a panic in an event handler (incoming-upload)")
|
||||
}
|
||||
if err != nil {
|
||||
return errors.New("unable to attach upload to post: " + err.Error())
|
||||
return fmt.Errorf("unable to attach upload to post: %w", err)
|
||||
}
|
||||
|
||||
const insertSQL = `INSERT INTO DBPREFIXfiles (
|
||||
|
|
|
@ -187,7 +187,7 @@ func boardsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.S
|
|||
return "", err
|
||||
}
|
||||
if err = board.ModifyInDB(); err != nil {
|
||||
return "", errors.New("Unable to apply changes: " + err.Error())
|
||||
return "", fmt.Errorf("unable to apply changes: %w", err)
|
||||
}
|
||||
case "cancel":
|
||||
// cancel button was clicked
|
||||
|
@ -201,7 +201,7 @@ func boardsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.S
|
|||
if requestType == "create" || requestType == "modify" || requestType == "delete" {
|
||||
if err = gcsql.ResetBoardSectionArrays(); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return "", errors.New("unable to reset board list: " + err.Error())
|
||||
return "", fmt.Errorf("unable to reset board list: %w", err)
|
||||
}
|
||||
if err = building.BuildBoardListJSON(); err != nil {
|
||||
return "", err
|
||||
|
@ -339,7 +339,7 @@ func cleanupCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.Staf
|
|||
if err != nil {
|
||||
errEv.Err(err).Caller().
|
||||
Str("sql", "optimization").Send()
|
||||
err = errors.New("Error optimizing SQL tables: " + err.Error())
|
||||
err = fmt.Errorf("failed optimizing SQL tables: %w", err)
|
||||
return outputStr + "<tr><td>" + err.Error() + "</td></tr></table>", err
|
||||
}
|
||||
outputStr += "Cleanup finished"
|
||||
|
|
|
@ -109,7 +109,7 @@ func recentPostsCallback(_ http.ResponseWriter, request *http.Request, _ *gcsql.
|
|||
"limit": limit,
|
||||
}, manageRecentsBuffer, "text/html"); err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return "", errors.New("Error executing ban management page template: " + err.Error())
|
||||
return "", fmt.Errorf("failed executing ban management page template: %w", err)
|
||||
}
|
||||
return manageRecentsBuffer.String(), nil
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ func staffCallback(writer http.ResponseWriter, request *http.Request, staff *gcs
|
|||
}
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Failed getting staff list")
|
||||
err = errors.New("Error getting staff list: " + err.Error())
|
||||
err = fmt.Errorf("failed getting staff list: %w", err)
|
||||
return "", err
|
||||
}
|
||||
warnEv := gcutil.LogWarning().
|
||||
|
@ -236,16 +236,17 @@ func staffCallback(writer http.ResponseWriter, request *http.Request, staff *gcs
|
|||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Error getting updated staff list")
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
err = errors.New("Unable to get updated staff list")
|
||||
err = errors.New("unable to get updated staff list")
|
||||
return "", err
|
||||
}
|
||||
data["allstaff"] = allStaff
|
||||
}
|
||||
|
||||
staffBuffer := bytes.NewBufferString("")
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageStaff, data, staffBuffer, "text/html"); err != nil {
|
||||
errEv.Err(err).Str("template", "manage_staff.html").Send()
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
return "", errors.New("Unable to execute staff management page template")
|
||||
return "", errors.New("unable to execute staff management page template")
|
||||
}
|
||||
return staffBuffer.String(), nil
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ func bansCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Sta
|
|||
banlist, err := gcsql.GetIPBans(filterBoardID, limit, true)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Msg("Error getting ban list")
|
||||
err = errors.New("Error getting ban list: " + err.Error())
|
||||
err = fmt.Errorf("failed getting ban list: %w", err)
|
||||
return "", err
|
||||
}
|
||||
manageBansBuffer := bytes.NewBufferString("")
|
||||
|
@ -115,7 +115,7 @@ func bansCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.Sta
|
|||
"filterboardid": filterBoardID,
|
||||
}, manageBansBuffer, "text/html"); err != nil {
|
||||
errEv.Err(err).Str("template", "manage_bans.html").Caller().Send()
|
||||
return "", errors.New("Error executing ban management page template: " + err.Error())
|
||||
return "", fmt.Errorf("failed executing ban management page template: %w", err)
|
||||
}
|
||||
outputStr += manageBansBuffer.String()
|
||||
return outputStr, nil
|
||||
|
@ -158,7 +158,7 @@ func appealsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
appeals, err := gcsql.GetAppeals(banID, limit)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return "", errors.New("Unable to get appeals: " + err.Error())
|
||||
return "", fmt.Errorf("failed to get appeals list: %w", err)
|
||||
}
|
||||
|
||||
if wantsJSON {
|
||||
|
@ -171,7 +171,7 @@ func appealsCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
}
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageAppeals, pageData, manageAppealsBuffer, "text/html"); err != nil {
|
||||
errEv.Err(err).Str("template", "manage_appeals.html").Caller().Send()
|
||||
return "", errors.New("Error executing appeal management page template: " + err.Error())
|
||||
return "", fmt.Errorf("failed executing appeal management page template: %w", err)
|
||||
}
|
||||
return manageAppealsBuffer.String(), err
|
||||
}
|
||||
|
@ -344,7 +344,7 @@ func filtersCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql.
|
|||
var buf bytes.Buffer
|
||||
if err = serverutil.MinifyTemplate(gctemplates.ManageFilters, data, &buf, "text/html"); err != nil {
|
||||
errEv.Err(err).Caller().Str("template", gctemplates.ManageFilters).Send()
|
||||
return "", errors.New("Unable to execute filter management template: " + err.Error())
|
||||
return "", fmt.Errorf("failed to execute filter management template: %w", err)
|
||||
}
|
||||
return buf.String(), nil
|
||||
}
|
||||
|
@ -376,7 +376,7 @@ func ipSearchCallback(_ http.ResponseWriter, request *http.Request, staff *gcsql
|
|||
Int("limit", limit).
|
||||
Bool("onlyNotDeleted", true).
|
||||
Send()
|
||||
return "", fmt.Errorf("Error getting list of posts from %q by staff %s: %s", ipQuery, staff.Username, err.Error())
|
||||
return "", fmt.Errorf("Error getting list of posts from %q by staff %s: %w", ipQuery, staff.Username, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package manage
|
|||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path"
|
||||
|
||||
|
@ -41,7 +42,7 @@ func loginCallback(writer http.ResponseWriter, request *http.Request, staff *gcs
|
|||
"redirect": redirectAction,
|
||||
}, manageLoginBuffer, "text/html"); err != nil {
|
||||
errEv.Err(err).Str("template", "manage_login.html").Send()
|
||||
return "", errors.New("Error executing staff login page template: " + err.Error())
|
||||
return "", fmt.Errorf("failed executing staff login page template: %w", err)
|
||||
}
|
||||
output = manageLoginBuffer.String()
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,7 @@ package manage
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -119,7 +120,7 @@ func submitFilterFormData(request *http.Request, staff *gcsql.Staff, infoEv, err
|
|||
Str("boardIDField", k).
|
||||
Str("boardIDStr", k[10:]).
|
||||
Msg("Unable to parse board ID")
|
||||
return errors.New("unable to parse board ID: " + err.Error())
|
||||
return fmt.Errorf("unable to parse board ID: %w", err)
|
||||
}
|
||||
boardIDLogArr.Int(boardID)
|
||||
boards = append(boards, boardID)
|
||||
|
@ -130,7 +131,7 @@ func submitFilterFormData(request *http.Request, staff *gcsql.Staff, infoEv, err
|
|||
fieldIDstr := k[5:]
|
||||
if _, err = strconv.Atoi(fieldIDstr); err != nil {
|
||||
errEv.Err(err).Caller().Str("fieldID", fieldIDstr).Send()
|
||||
return errors.New("failed to get field data: " + err.Error())
|
||||
return fmt.Errorf("failed to get field data: %w", err)
|
||||
}
|
||||
fc := gcsql.FilterCondition{
|
||||
Field: v[0],
|
||||
|
|
|
@ -97,7 +97,7 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
|
|||
data, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
errEv.Err(err).Caller().Send()
|
||||
return nil, errors.New("Error while trying to read file: " + err.Error())
|
||||
return nil, fmt.Errorf("got an error while trying to read file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
|
@ -152,7 +152,7 @@ func AttachUploadFromRequest(request *http.Request, writer http.ResponseWriter,
|
|||
|
||||
if err = uploadHandler(upload, post, postBoard.Dir, filePath, thumbPath, catalogThumbPath, infoEv, accessEv, errEv); err != nil {
|
||||
// uploadHandler is assumed to handle logging
|
||||
return nil, errors.New("error processing upload: " + err.Error())
|
||||
return nil, fmt.Errorf("error processing upload: %w", err)
|
||||
}
|
||||
|
||||
accessEv.Send()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue