From de95cf6db6b7900e387c185363f4d4d103ee578d Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 12 Nov 2021 10:46:35 +1100 Subject: [PATCH] Make TorrentSpecFromMetaInfoErr still usable on info error --- spec.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 { -- 2.48.1