spec.go | 7 +++++-- diff --git a/spec.go b/spec.go index 60c774cf7db9ad62d005b0ac384f6178aac24869..332ea139670f9d9f3a2564cde4205794a6f6d157 100644 --- a/spec.go +++ b/spec.go @@ -55,10 +55,12 @@ } 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 @@ ret = append(ret, string(node)) } 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 {