From: Matt Joiner Date: Thu, 11 Nov 2021 23:46:35 +0000 (+1100) Subject: Make TorrentSpecFromMetaInfoErr still usable on info error X-Git-Tag: v1.37.0~10 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=de95cf6db6b7900e387c185363f4d4d103ee578d;p=btrtrc.git Make TorrentSpecFromMetaInfoErr still usable on info error --- diff --git a/spec.go b/spec.go index 60c774cf..332ea139 100644 --- 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 {