]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Make TorrentSpecFromMetaInfoErr still usable on info error
authorMatt Joiner <anacrolix@gmail.com>
Thu, 11 Nov 2021 23:46:35 +0000 (10:46 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 11 Nov 2021 23:46:35 +0000 (10:46 +1100)
spec.go

diff --git a/spec.go b/spec.go
index 60c774cf7db9ad62d005b0ac384f6178aac24869..332ea139670f9d9f3a2564cde4205794a6f6d157 100644 (file)
--- a/spec.go
+++ b/spec.go
@@ -55,10 +55,12 @@ func TorrentSpecFromMagnetUri(uri string) (spec *TorrentSpec, err error) {
        return
 }
 
+// The error will be from unmarshalling the info bytes. The TorrentSpec is still filled out as much
+// as possible in this case.
 func TorrentSpecFromMetaInfoErr(mi *metainfo.MetaInfo) (*TorrentSpec, error) {
        info, err := mi.UnmarshalInfo()
        if err != nil {
-               return nil, fmt.Errorf("unmarshalling info: %w", err)
+               err = fmt.Errorf("unmarshalling info: %w", err)
        }
        return &TorrentSpec{
                Trackers:    mi.UpvertedAnnounceList(),
@@ -73,9 +75,10 @@ func TorrentSpecFromMetaInfoErr(mi *metainfo.MetaInfo) (*TorrentSpec, error) {
                        }
                        return
                }(),
-       }, nil
+       }, err
 }
 
+// Panics if there was anything missing from the metainfo.
 func TorrentSpecFromMetaInfo(mi *metainfo.MetaInfo) *TorrentSpec {
        ts, err := TorrentSpecFromMetaInfoErr(mi)
        if err != nil {