tangled
alpha
login
or
join now
stream.place
/
streamplace
Live video on the AT Protocol
74
fork
atom
overview
issues
1
pulls
pipelines
wip: generate list of cbor troublemakers
Eli Mallon
4 months ago
bbc01d2e
d23faa9a
+39
-2
1 changed file
expand all
collapse all
unified
split
pkg
atproto
sync.go
+39
-2
pkg/atproto/sync.go
···
4
4
"context"
5
5
"errors"
6
6
"fmt"
7
7
+
"os"
7
8
"reflect"
9
9
+
"sync"
8
10
"time"
9
11
10
12
"github.com/bluesky-social/indigo/api/bsky"
···
19
21
lexutil "github.com/bluesky-social/indigo/lex/util"
20
22
)
21
23
24
24
+
var writeMutex = sync.Mutex{}
25
25
+
var writeFile *os.File
26
26
+
var writeErrs *os.File
27
27
+
28
28
+
func writeProblematic(recCBOR *[]byte, errMsg error) {
29
29
+
writeMutex.Lock()
30
30
+
defer writeMutex.Unlock()
31
31
+
if writeFile == nil {
32
32
+
var err error
33
33
+
writeFile, err = os.Create("problematic.cbor")
34
34
+
if err != nil {
35
35
+
panic(err)
36
36
+
}
37
37
+
}
38
38
+
if writeErrs == nil {
39
39
+
var err error
40
40
+
writeErrs, err = os.Create("problematic.txt")
41
41
+
if err != nil {
42
42
+
panic(err)
43
43
+
}
44
44
+
}
45
45
+
_, err := writeFile.Write(*recCBOR)
46
46
+
if err != nil {
47
47
+
panic(fmt.Sprintf("failed to write to problematic.cbor: %s", err))
48
48
+
}
49
49
+
_, err = writeErrs.WriteString(errMsg.Error() + "\n")
50
50
+
if err != nil {
51
51
+
panic(fmt.Sprintf("failed to write to problematic.txt: %s", err))
52
52
+
}
53
53
+
}
54
54
+
22
55
func (atsync *ATProtoSynchronizer) handleCreateUpdate(ctx context.Context, userDID string, rkey syntax.RecordKey, recCBOR *[]byte, cid string, collection syntax.NSID, isUpdate bool, isFirstSync bool) error {
23
56
ctx = log.WithLogValues(ctx, "func", "handleCreateUpdate", "userDID", userDID, "rkey", rkey.String(), "cid", cid, "collection", collection.String())
24
57
now := time.Now()
···
33
66
}
34
67
d, err := data.UnmarshalCBOR(*recCBOR)
35
68
if err != nil {
36
36
-
return fmt.Errorf("failed to unmarhsal record CBOR: %w", err)
69
69
+
ret := fmt.Errorf("failed to unmarshal record CBOR: %w aturi=%s cid=%s handle=%s", err, aturi.String(), cid, r.Handle)
70
70
+
go writeProblematic(recCBOR, ret)
71
71
+
return ret
37
72
}
38
73
cb, err := lexutil.CborDecodeValue(*recCBOR)
39
74
if errors.Is(err, lexutil.ErrUnrecognizedType) {
40
75
log.Debug(ctx, "unrecognized record type", "key", rkey.String(), "type", err)
41
76
return nil
42
77
} else if err != nil {
43
43
-
return fmt.Errorf("failed to decode record CBOR: %w", err)
78
78
+
ret := fmt.Errorf("failed to decode record CBOR: %w aturi=%s cid=%s handle=%s", err, aturi.String(), cid, r.Handle)
79
79
+
go writeProblematic(recCBOR, ret)
80
80
+
return ret
44
81
}
45
82
switch rec := cb.(type) {
46
83
case *bsky.GraphFollow: