Explicitly ignore errors from writes to responses
Some checks failed
/ docker (push) Failing after 15m26s

This commit is contained in:
Melody Becker 2025-05-22 17:29:09 +02:00
parent ef95a0552d
commit 4a2462e24e
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
30 changed files with 280 additions and 237 deletions

View file

@ -42,7 +42,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
data := map[string]any{}
err = json.Unmarshal(body, &data)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -53,7 +53,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
return
}
if _, ok := data["@context"]; !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -65,7 +65,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
}
objectType, ok := data["type"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -77,7 +77,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
}
_, ok = data["id"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -104,7 +104,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
handleCreate(w, r, data)
default:
log.Warn().Str("object-type", objectType).Msg("Unknown message type")
webutils.ProblemDetailsStatusOnly(w, 500)
_ = webutils.ProblemDetailsStatusOnly(w, 500)
}
}
@ -113,7 +113,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
activityId := object["id"].(string)
likerUrl, ok := object["actor"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -126,7 +126,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
// TODO: Account for case where object is embedded in like
targetUrl, ok := object["object"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -142,7 +142,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
Strs("match-results", targetIdMatches).
Str("url", targetUrl).
Msg("Url didn't match id extractor regex")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
targetId := targetIdMatches[1]
@ -152,7 +152,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
switch err {
case nil:
case gorm.ErrRecordNotFound:
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -163,7 +163,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
return
default:
log.Error().Err(err).Str("note-id", targetId).Msg("Failed to get note from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
// Import liker after verifying that target note is correct
@ -173,7 +173,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
Err(err).
Str("liker-url", likerUrl).
Msg("Failed to import liking remote account")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
reaction := models.Reaction{
@ -190,7 +190,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
// TODO: Create corresponding activity too
activity := models.Activity{
@ -203,12 +203,12 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to commit reaction transaction to db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
}
@ -217,7 +217,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
log.Debug().Msg("Received follow request")
objectId, ok := object["id"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -229,7 +229,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
}
actorApId, ok := object["actor"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -241,7 +241,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
}
targetUrl, ok := object["object"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -253,7 +253,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
}
followedMatch := objectIdRegex.FindStringSubmatch(targetUrl)
if len(followedMatch) != 2 {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -267,18 +267,18 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
followed, err := dbgen.User.Where(dbgen.User.ID.Eq(followedId)).First()
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
log.Error().Err(err).Str("target-id", followedId).Msg("Failed to get account from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
follower, err := activitypub.ImportRemoteAccountByAPUrl(actorApId)
if err != nil {
log.Error().Err(err).Msg("Failed to import following account")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
u2u := dbgen.UserToUserRelation
@ -296,7 +296,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
Str("follower", follower.ID).
Str("followed", followedId).
Msg("Failed to count follow relations")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if followRelations > 0 {
@ -312,7 +312,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("follow-request", req).Msg("Failed to store follow request")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
activity := models.Activity{
@ -325,13 +325,13 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("activity", activity).Msg("Failed to store follow activity")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to commit follow activity transaction")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if !followed.RestrictedFollow {
@ -340,7 +340,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Msg("Failed to update follow to confirmed")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
acceptActivity := models.Activity{
@ -353,13 +353,13 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Msg("Failed to store accept activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to commit follow accept to db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
go func() {
@ -402,7 +402,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
log := hlog.FromRequest(r)
rawTarget, ok := object["object"]
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -422,7 +422,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
objType, ok := target["type"].(string)
// TODO: Ensure accept is only used for follows
if !ok || objType != "Follow" {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -434,7 +434,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
}
targetObjectId, ok = target["id"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -445,7 +445,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
return
}
default:
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -457,7 +457,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
}
internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId)
if len(internalIdMatch) != 2 {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -471,7 +471,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First()
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
@ -479,7 +479,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to get target follow activity from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64))
@ -490,7 +490,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
switch err {
case gorm.ErrRecordNotFound:
// No need to rollback, nothing was done
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
@ -499,7 +499,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to update follow status to confirmed follow")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
activity := models.Activity{
@ -515,7 +515,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to store accept activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
@ -524,7 +524,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to commit accept transaction")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}
@ -534,7 +534,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
log := hlog.FromRequest(r)
rawTarget, ok := object["object"]
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -554,7 +554,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
objType, ok := target["type"].(string)
// TODO: Ensure accept is only used for follows
if !ok || objType != "Follow" {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -566,7 +566,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
}
targetObjectId, ok = target["id"].(string)
if !ok {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -577,7 +577,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
return
}
default:
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -589,7 +589,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
}
internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId)
if len(internalIdMatch) != 2 {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -603,7 +603,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First()
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
@ -611,7 +611,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to get target follow activity from db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64))
@ -621,7 +621,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
switch err {
case gorm.ErrRecordNotFound:
// No need to rollback, nothing was done
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
@ -630,7 +630,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to delete follow status")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
_, err = tx.Activity.Where(
@ -641,7 +641,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Msg("Failed to delete accept for later rejected follow")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
activity := models.Activity{
@ -657,7 +657,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to store accept activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
@ -666,7 +666,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("target-id", internalId).
Msg("Failed to commit accept transaction")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}
@ -680,7 +680,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Any("raw", object).
Msg("Failed to marshal create activity to proper type")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
actingUser, err := activitypub.ImportRemoteAccountByAPUrl(activity.Actor)
@ -689,7 +689,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Str("actor", activity.Actor).
Msg("Failed to import remote actor for note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
switch val := activity.Object.(type) {
@ -697,18 +697,18 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
actor, err := dbgen.User.GetById(r.PathValue("id"))
if err != nil {
log.Error().Err(err).Msg("Failed to get local actor for importing targeted note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
_, err = activitypub.ImportRemoteNote(val, actor)
if err != nil {
log.Error().Err(err).Str("note-url", val).Msg("Failed to import remote note that landed as id in the inbox")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
return
case map[string]any:
default:
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -733,11 +733,11 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
Err(err).
Any("raw", activity.Object).
Msg("Failed to unmarshal create object into note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if objectNote.Type != "Note" {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -774,7 +774,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
createActivity := models.Activity{
@ -787,13 +787,13 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
if err != nil {
_ = tx.Rollback()
log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note create activity in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
err = tx.Commit()
if err != nil {
log.Error().Err(err).Any("note", dbNote).Msg("Failed to submit note creation in db")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}