From e93e4cc11523657a6cd440f0ca3986fa71918219 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Tue, 24 Feb 2026 16:00:21 +0000 Subject: [PATCH] Add function for avoiding 'if err != nil' constructs everywhere. --- sync/routes.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sync/routes.go b/sync/routes.go index 1978fa43..ddaf1a63 100644 --- a/sync/routes.go +++ b/sync/routes.go @@ -94,6 +94,13 @@ func (e *errorWithStatus) Error() string { func newError(mesg_format string, args ...interface{}) *errorWithStatus { return newErrorStatus(http.StatusInternalServerError, mesg_format, args...) } +func newErrorMaybe(mesg_format string, err error, args ...interface{}) *errorWithStatus { + if err == nil { + return nil + } + allArgs := append([]interface{}{err}, args...) + return newErrorStatus(http.StatusInternalServerError, mesg_format, allArgs...) +} func newErrorStatus(status int, mesg_format string, args ...interface{}) *errorWithStatus { w := fmt.Errorf(mesg_format, args...) return &errorWithStatus{