diff --git a/metainfo/magnet_test.go b/metainfo/magnet_test.go index 1ad4b170..c90713f3 100644 --- a/metainfo/magnet_test.go +++ b/metainfo/magnet_test.go @@ -74,7 +74,9 @@ func TestMagnetize(t *testing.T) { mi, err := LoadFromFile("../testdata/bootstrap.dat.torrent") require.NoError(t, err) - m := mi.Magnet(mi.UnmarshalInfo().Name, mi.HashInfoBytes()) + info, err := mi.UnmarshalInfo() + require.NoError(t, err) + m := mi.Magnet(info.Name, mi.HashInfoBytes()) assert.EqualValues(t, "bootstrap.dat", m.DisplayName) diff --git a/metainfo/metainfo.go b/metainfo/metainfo.go index 6d1d7e2e..96a64cbc 100644 --- a/metainfo/metainfo.go +++ b/metainfo/metainfo.go @@ -1,7 +1,6 @@ package metainfo import ( - "fmt" "io" "os" "time" @@ -49,11 +48,8 @@ func LoadFromFile(filename string) (*MetaInfo, error) { return Load(f) } -func (mi MetaInfo) UnmarshalInfo() (info Info) { - err := bencode.Unmarshal(mi.InfoBytes, &info) - if err != nil { - panic(fmt.Sprintf("bad info bytes: %s", err)) - } +func (mi MetaInfo) UnmarshalInfo() (info Info, err error) { + err = bencode.Unmarshal(mi.InfoBytes, &info) return } diff --git a/metainfo/metainfo_test.go b/metainfo/metainfo_test.go index de81b8da..037f8825 100644 --- a/metainfo/metainfo_test.go +++ b/metainfo/metainfo_test.go @@ -18,8 +18,9 @@ import ( func testFile(t *testing.T, filename string) { mi, err := LoadFromFile(filename) require.NoError(t, err) + info, err := mi.UnmarshalInfo() + require.NoError(t, err) - info := mi.UnmarshalInfo() if len(info.Files) == 1 { t.Logf("Single file: %s (length: %d)\n", info.Name, info.Files[0].Length) } else { diff --git a/spec.go b/spec.go index e6b58d8c..5dbd472b 100644 --- a/spec.go +++ b/spec.go @@ -34,7 +34,7 @@ func TorrentSpecFromMagnetURI(uri string) (spec *TorrentSpec, err error) { } func TorrentSpecFromMetaInfo(mi *metainfo.MetaInfo) (spec *TorrentSpec) { - info := mi.UnmarshalInfo() + info, _ := mi.UnmarshalInfo() spec = &TorrentSpec{ Trackers: mi.AnnounceList, InfoBytes: mi.InfoBytes,