From 97ea4ad3bb82ba9a75e6097ec7d0b072b42ca5ca Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Tue, 6 Jan 2026 14:46:31 +0000 Subject: [PATCH] Begin work on debugging user behavior in early setup --- arcgis.go | 5 +++-- auth/auth.go | 8 ++++---- errors.go => debug/errors.go | 2 +- endpoint.go | 6 ++++-- notification.go | 3 ++- 5 files changed, 14 insertions(+), 10 deletions(-) rename errors.go => debug/errors.go (97%) diff --git a/arcgis.go b/arcgis.go index 99b20a8a..0d9d5003 100644 --- a/arcgis.go +++ b/arcgis.go @@ -26,6 +26,7 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/db/sql" + "github.com/Gleipnir-Technology/nidus-sync/debug" "github.com/aarondl/opt/omit" "github.com/aarondl/opt/omitnull" "github.com/alitto/pond/v2" @@ -174,7 +175,7 @@ func updateArcgisUserData(ctx context.Context, user *models.User, access_token s } if err != nil { - LogErrorTypeInfo(err) + debug.LogErrorTypeInfo(err) if errors.Is(err, pgx.ErrNoRows) { } else { log.Error().Err(err).Msg("Failed to query for existing org") @@ -310,7 +311,7 @@ func refreshFieldseekerData(ctx context.Context, newOauthCh <-chan struct{}) { if errors.Is(err, arcgis.InvalidatedRefreshTokenError) { log.Info().Int("oauth_token.id", int(oauth.ID)).Msg("Marked invalid by the server") } else { - LogErrorTypeInfo(err) + debug.LogErrorTypeInfo(err) log.Error().Err(err).Msg("Crashed oauth maintenance goroutine") } } diff --git a/auth/auth.go b/auth/auth.go index 641a73cd..cee0fa71 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -11,6 +11,7 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/db/sql" + "github.com/Gleipnir-Technology/nidus-sync/debug" "github.com/aarondl/opt/omit" "github.com/rs/zerolog/log" "golang.org/x/crypto/bcrypt" @@ -141,16 +142,15 @@ func SignupUser(username string, name string, password string) (*models.User, er return u, nil } - // Helper function to translate strings into solid error types for operating on func findUser(ctx context.Context, user_id int) (*models.User, error) { user, err := models.FindUser(ctx, db.PGInstance.BobDB, int32(user_id)) if err != nil { - if err.Error() == "No such user" { + if err.Error() == "No such user" || err.Error() == "sql: no rows in result set" { return nil, &NoUserError{} } else { - //LogErrorTypeInfo(err) - //log.Error().Err(err).Msg("Unrecognized error. This should be updated in the findUser code") + debug.LogErrorTypeInfo(err) + log.Error().Err(err).Msg("Unrecognized error. This should be updated in the findUser code") return nil, err } } diff --git a/errors.go b/debug/errors.go similarity index 97% rename from errors.go rename to debug/errors.go index 075a4ec6..3a91742f 100644 --- a/errors.go +++ b/debug/errors.go @@ -1,4 +1,4 @@ -package main +package debug import ( "errors" diff --git a/endpoint.go b/endpoint.go index 48f7e874..ac748a58 100644 --- a/endpoint.go +++ b/endpoint.go @@ -247,9 +247,11 @@ func getVectorTiles(w http.ResponseWriter, r *http.Request, u *models.User) { log.Info().Str("org_id", org_id).Str("tileset_id", tileset_id).Str("zoom", zoom).Str("x", x).Str("y", y).Str("format", format).Msg("Get vector tiles") } + +// Respond with an error that is visible to the user func respondError(w http.ResponseWriter, m string, e error, s int) { - log.Warn().Int("status", s).Err(e).Msg("Responding with an error") - http.Error(w, m, http.StatusBadRequest) + log.Warn().Int("status", s).Err(e).Str("user message", m).Msg("Responding with an error") + http.Error(w, m, s) } func postSignin(w http.ResponseWriter, r *http.Request) { diff --git a/notification.go b/notification.go index 980bf7e6..9e7db8dc 100644 --- a/notification.go +++ b/notification.go @@ -9,6 +9,7 @@ import ( "github.com/Gleipnir-Technology/nidus-sync/db" enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/Gleipnir-Technology/nidus-sync/debug" "github.com/aarondl/opt/omit" "github.com/aarondl/opt/omitnull" "github.com/rs/zerolog/log" @@ -56,7 +57,7 @@ func notifyOauthInvalid(ctx context.Context, user *models.User) { log.Info().Str("msg", msg).Int("user_id", int(user.ID)).Msg("Refusing to add another notification with the same type") return } - LogErrorTypeInfo(err) + debug.LogErrorTypeInfo(err) log.Error().Err(err).Msg("Failed to insert new notification. This is a programmer bug.") return }