{"record":{"id":"8b8391d078290d91","repo":"syncthing/syncthing","slug":"handling-v-w","errorCode":null,"errorMessage":"handling %v: %w","messagePattern":"handling (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/protocol/protocol.go","lineNumber":1119,"sourceCode":"\t\treturn nil, fmt.Errorf(\"decompressed message len %d is too large\", size)\n\t}\n\tbuf := BufferPool.Get(int(size))\n\n\tn, err := lz4.UncompressBlock(src[4:], buf)\n\tif err != nil {\n\t\tBufferPool.Put(buf)\n\t\treturn nil, err\n\t}\n\n\treturn buf[:n], nil\n}\n\nfunc newProtocolError(err error, msgContext string) error {\n\treturn fmt.Errorf(\"protocol error on %v: %w\", msgContext, err)\n}\n\nfunc newHandleError(err error, msgContext string) error {\n\treturn fmt.Errorf(\"handling %v: %w\", msgContext, err)\n}\n\nfunc messageContext(msg proto.Message) (string, error) {\n\tswitch msg := msg.(type) {\n\tcase *bep.ClusterConfig:\n\t\treturn \"cluster-config\", nil\n\tcase *bep.Index:\n\t\treturn fmt.Sprintf(\"index for %v\", msg.Folder), nil\n\tcase *bep.IndexUpdate:\n\t\treturn fmt.Sprintf(\"index-update for %v\", msg.Folder), nil\n\tcase *bep.Request:\n\t\treturn fmt.Sprintf(`request for \"%v\" in %v`, msg.Name, msg.Folder), nil\n\tcase *bep.Response:\n\t\treturn \"response\", nil\n\tcase *bep.DownloadProgress:\n\t\treturn fmt.Sprintf(\"download-progress for %v\", msg.Folder), nil\n\tcase *bep.Ping:\n\t\treturn \"ping\", nil","sourceCodeStart":1101,"sourceCodeEnd":1137,"githubUrl":"https://github.com/syncthing/syncthing/blob/058bcd7334839663cf569501d3ac539034d45cb5/lib/protocol/protocol.go#L1101-L1137","documentation":"Wraps an error that occurred while processing (not decoding) an already-parsed BEP message, such as applying an index or dispatching a Request to a handler. The %v names the message context and %w the handler failure. It is produced by newHandleError at the dispatch point in the message loop (protocol.go:509), distinguishing downstream handler failures from wire-format errors.","triggerScenarios":"The messageLoop dispatches a decoded message to its handler (index processing, request handling, cluster-config processing) and the handler returns a non-nil error; e.g. an index for an unknown folder or a request for a file that cannot be opened.","commonSituations":"Folder removed from config on one side while the other still sends index updates; disk full or file locked when serving a Request; database errors in the folder while applying an index; partial config propagation in a cluster.","solutions":["Check which message context appears in the error text (e.g. 'index for X') and verify that folder is shared and configured on both devices","Inspect the wrapped %w error — it names the real handler failure (disk, database, unknown folder)","Sync folder configs across devices and restart the connection so a fresh ClusterConfig is exchanged","If persistent, rescan or reset the folder index database on the affected device"],"exampleFix":"// before: handler error surfaces opaquely\ncase errors.As(err, &e):\n    log.Printf(\"sync failed: %v\", err)\n// after: unwrap to distinguish handle vs protocol errors via error text\nif strings.HasPrefix(err.Error(), \"handling \") {\n    log.Printf(\"handler failure on message: %v\", errors.Unwrap(err))\n}","handlingStrategy":"try-catch","validationCode":"// before exchanging indexes, confirm the folder is actually shared both ways\nfor _, folder := range myFolders {\n    if !peerSharesFolder(peerID, folder.ID) {\n        return fmt.Errorf(\"folder %s not shared with peer\", folder.ID)\n    }\n}","typeGuard":"func isHandleError(err error) bool {\n    return err != nil && strings.HasPrefix(err.Error(), \"handling \")\n}","tryCatchPattern":"if err := msgLoop(); err != nil {\n    if isHandleError(err) {\n        // inspect errors.Unwrap(err) for the real cause; may be per-folder and non-fatal\n        l.Warnf(\"message handler failed: %v\", errors.Unwrap(err))\n    }\n}","preventionTips":["Apply folder config changes on all devices before reconnecting","Keep folders shared symmetrically between peers","Monitor wrapped causes: unknown-folder and disk errors point to config/storage, not protocol"],"tags":["protocol","bep","go","dispatch"],"backgroundTag":null,"analyzedSha":"058bcd7334839663cf569501d3ac539034d45cb5","analyzedAt":"2026-08-15T07:53:43.174Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}