~sircmpwn/sr.ht-dev

lists.sr.ht: api/graph: skip emails with decoding errors in threadResolver.Blocks v1 APPLIED

Simon Ser: 2
 api/graph: skip emails with decoding errors in threadResolver.Blocks
 Make thread block parsing errors non-fatal

 2 files changed, 32 insertions(+), 22 deletions(-)
#957086 alpine.yml success
#957087 archlinux.yml failed
#957088 debian.yml success
lists.sr.ht/patches: FAILED in 3m50s

[api/graph: skip emails with decoding errors in threadResolver.Blocks][0] from [Simon Ser][1]

[0]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/39710
[1]: mailto:contact@emersion.fr

✓ #957088 SUCCESS lists.sr.ht/patches/debian.yml    https://builds.sr.ht/~sircmpwn/job/957088
✗ #957087 FAILED  lists.sr.ht/patches/archlinux.yml https://builds.sr.ht/~sircmpwn/job/957087
✓ #957086 SUCCESS lists.sr.ht/patches/alpine.yml    https://builds.sr.ht/~sircmpwn/job/957086
Thanks!

To git@git.sr.ht:~sircmpwn/lists.sr.ht
   fdc1c4c..8aa7a45  master -> master
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/39710/mbox | git am -3
Learn more about email & git

[PATCH lists.sr.ht 1/2] api/graph: skip emails with decoding errors in threadResolver.Blocks Export this patch

Some emails can have a bad encoding, a bad charset, a bad header
field, etc. Skip these so that we can try to return a partial thread.

Ideally we'd return a list of errors alongside the partial thread,
but gqlgen doesn't support this yet.
---
 api/graph/schema.resolvers.go | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go
index 7d6692d16121..89f799c986bf 100644
--- a/api/graph/schema.resolvers.go
+++ b/api/graph/schema.resolvers.go
@@ -10,6 +10,7 @@ import (
	"errors"
	"fmt"
	"io"
	"log"
	"net/url"
	"strings"
	"time"
@@ -1827,12 +1828,14 @@ func (r *threadResolver) Blocks(ctx context.Context, obj *model.Thread) ([]*mode

			mr, err := mail.CreateReader(bytes.NewReader(email.RawEnvelope))
			if err != nil {
				return fmt.Errorf("failed to create mail reader: %v", err)
				log.Printf("Failed to create reader for email %v: %v", email.ID, err)
				continue
			}
			header := mr.Header
			text, err := getMailText(mr)
			if err != nil {
				return fmt.Errorf("failed to get mail text: %v", err)
				log.Printf("Failed to get mail text for email %v: %v", email.ID, err)
				continue
			}
			mr.Close()


base-commit: fdc1c4c7c546ed32e42c8f014873e94c2e7d91f1
-- 
2.39.2

[PATCH lists.sr.ht 2/2] Make thread block parsing errors non-fatal Export this patch

---
 listssrht/blueprints/patches.py | 47 +++++++++++++++++++--------------
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/listssrht/blueprints/patches.py b/listssrht/blueprints/patches.py
index cf6de0d428a5..bfb9aebe279d 100644
--- a/listssrht/blueprints/patches.py
+++ b/listssrht/blueprints/patches.py
@@ -13,7 +13,7 @@ from listssrht.types import Subscription, PatchsetTool, ToolIcon
from sqlalchemy import or_
from srht.database import db
from srht.flask import paginate_query
from srht.graphql import exec_gql
from srht.graphql import exec_gql, GraphQLError
from srht.markdown import markdown
from srht.oauth import current_user, loginrequired
from srht.validation import Validation
@@ -155,29 +155,36 @@ def patchset(owner_name, list_name, patchset_id):
        messages_by_id[msg.id] = msg

    feedback = dict()
    resp = exec_gql(current_app.site, """
        query GetPatchsetThreadBlocks($patchset: Int!) {
            patchset(id: $patchset) {
                thread {
                    blocks {
                        key
                        source {
                            id
                        }
                        sourceRange {
                            start
                            end
                        }
                        parentRange {
                            start
                            end
    try:
        resp = exec_gql(current_app.site, """
            query GetPatchsetThreadBlocks($patchset: Int!) {
                patchset(id: $patchset) {
                    thread {
                        blocks {
                            key
                            source {
                                id
                            }
                            sourceRange {
                                start
                                end
                            }
                            parentRange {
                                start
                                end
                            }
                        }
                    }
                }
            }
        }
    """, user=owner, patchset=patchset_id)
    blocks = resp["patchset"]["thread"]["blocks"]
        """, user=owner, patchset=patchset_id)
        blocks = resp["patchset"]["thread"]["blocks"]
    except GraphQLError as err:
        # Can happen when an email in the thread is a bad apple
        # TODO: grab partial result from GraphQLError.data (gqlgen doesn't
        # support this yet)
        print(f"Warning: failed to parse blocks from thread {thread.id}: {err.errors}")
        blocks = []
    for block in blocks:
        source_email = messages_by_id[block["source"]["id"]]

-- 
2.39.2
lists.sr.ht/patches: FAILED in 3m50s

[api/graph: skip emails with decoding errors in threadResolver.Blocks][0] from [Simon Ser][1]

[0]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/39710
[1]: mailto:contact@emersion.fr

✓ #957088 SUCCESS lists.sr.ht/patches/debian.yml    https://builds.sr.ht/~sircmpwn/job/957088
✗ #957087 FAILED  lists.sr.ht/patches/archlinux.yml https://builds.sr.ht/~sircmpwn/job/957087
✓ #957086 SUCCESS lists.sr.ht/patches/alpine.yml    https://builds.sr.ht/~sircmpwn/job/957086
Thanks!

To git@git.sr.ht:~sircmpwn/lists.sr.ht
   fdc1c4c..8aa7a45  master -> master