diff --git a/torrent/session_healthcheck.go b/torrent/session_healthcheck.go index a2a3ab59..eeb4fe28 100644 --- a/torrent/session_healthcheck.go +++ b/torrent/session_healthcheck.go @@ -42,3 +42,7 @@ func crash(torrentID string, msg string) { } panic(msg) } + +func (t *torrent) crash(msg string) { + crash(t.id, msg) +} diff --git a/torrent/torrent_allocation.go b/torrent/torrent_allocation.go index 8ae40191..0f09e05e 100644 --- a/torrent/torrent_allocation.go +++ b/torrent/torrent_allocation.go @@ -11,7 +11,7 @@ import ( func (t *torrent) handleAllocationDone(al *allocator.Allocator) { if t.allocator != al { - panic("invalid allocator") + t.crash("invalid allocator") } t.allocator = nil @@ -21,12 +21,12 @@ func (t *torrent) handleAllocationDone(al *allocator.Allocator) { } if t.files != nil { - panic("files exist") + t.crash("files exist") } t.files = al.Files if t.pieces != nil { - panic("pieces exists") + t.crash("pieces exists") } pieces := piece.NewPieces(t.info, t.files) if len(pieces) == 0 { @@ -40,7 +40,7 @@ func (t *torrent) handleAllocationDone(al *allocator.Allocator) { } if t.piecePicker != nil { - panic("piece picker exists") + t.crash("piece picker exists") } t.piecePicker = piecepicker.New(t.pieces, t.session.config.EndgameMaxDuplicateDownloads, t.webseedSources) diff --git a/torrent/torrent_messagehandler.go b/torrent/torrent_messagehandler.go index 1fa45ae9..4293c2fb 100644 --- a/torrent/torrent_messagehandler.go +++ b/torrent/torrent_messagehandler.go @@ -102,7 +102,7 @@ func (t *torrent) handlePieceMessage(pm peer.PieceMessage) { pe.StopSnubTimer() if piece.Writing { - panic("piece is already writing") + t.crash("piece is already writing") } piece.Writing = true @@ -355,7 +355,7 @@ func (t *torrent) handlePeerMessage(pm peer.Message) { } t.handleNewPeers(addrs, peersource.PEX) default: - panic(fmt.Sprintf("unhandled peer message type: %T", msg)) + t.crash(fmt.Sprintf("unhandled peer message type: %T", msg)) } } diff --git a/torrent/torrent_start.go b/torrent/torrent_start.go index 55a27d24..99e8f96d 100644 --- a/torrent/torrent_start.go +++ b/torrent/torrent_start.go @@ -58,10 +58,10 @@ func (t *torrent) start() { func (t *torrent) startVerifier() { if t.verifier != nil { - panic("verifier exists") + t.crash("verifier exists") } if len(t.pieces) == 0 { - panic("zero length pieces") + t.crash("zero length pieces") } t.verifier = verifier.New() go t.verifier.Run(t.pieces, t.verifierProgressC, t.verifierResultC) @@ -69,7 +69,7 @@ func (t *torrent) startVerifier() { func (t *torrent) startAllocator() { if t.allocator != nil { - panic("allocator exists") + t.crash("allocator exists") } t.allocator = allocator.New() go t.allocator.Run(t.info, t.storage, t.allocatorProgressC, t.allocatorResultC) @@ -224,7 +224,7 @@ func (t *torrent) startSinglePieceDownloader(pe *peer.Peer) { } pd := piecedownloader.New(pi, pe, allowedFast, t.piecePool.Get(int(pi.Length))) if _, ok := t.pieceDownloaders[pe]; ok { - panic("peer already has a piece downloader") + t.crash("peer already has a piece downloader") } t.log.Debugf("requesting piece #%d from peer %s", pi.Index, pe.IP()) t.pieceDownloaders[pe] = pd diff --git a/torrent/torrent_stats.go b/torrent/torrent_stats.go index 9462dd1a..a0e67465 100644 --- a/torrent/torrent_stats.go +++ b/torrent/torrent_stats.go @@ -250,7 +250,7 @@ func (t *torrent) getPeers() []Peer { case peersource.Manual: source = SourceManual default: - panic("unhandled peer source") + t.crash("unhandled peer source") } p := Peer{ ID: pe.ID, diff --git a/torrent/torrent_stop.go b/torrent/torrent_stop.go index 90d58aaa..7f8169f7 100644 --- a/torrent/torrent_stop.go +++ b/torrent/torrent_stop.go @@ -88,7 +88,7 @@ func (t *torrent) stop(err error) { } } if t.stoppedEventAnnouncer != nil { - panic("stopped event announcer exists") + t.crash("stopped event announcer exists") } t.stoppedEventAnnouncer = announcer.NewStopAnnouncer(trackers, t.announcerFields(), t.session.config.TrackerStopTimeout, t.announcersStoppedC, t.log) diff --git a/torrent/torrent_verification.go b/torrent/torrent_verification.go index 3edf0825..05ac7ed4 100644 --- a/torrent/torrent_verification.go +++ b/torrent/torrent_verification.go @@ -20,7 +20,7 @@ func (t *torrent) handleVerifyCommand() { func (t *torrent) handleVerificationDone(ve *verifier.Verifier) { if t.verifier != ve { - panic("invalid verifier") + t.crash("invalid verifier") } t.verifier = nil diff --git a/torrent/torrent_webseed.go b/torrent/torrent_webseed.go index c13acac8..642d541f 100644 --- a/torrent/torrent_webseed.go +++ b/torrent/torrent_webseed.go @@ -35,7 +35,7 @@ func (t *torrent) handleWebseedPieceResult(msg *urldownloader.PieceResult) { } if piece.Writing { - panic("piece is already writing") + t.crash("piece is already writing") } piece.Writing = true diff --git a/torrent/torrent_write.go b/torrent/torrent_write.go index 35df9f01..19813a52 100644 --- a/torrent/torrent_write.go +++ b/torrent/torrent_write.go @@ -29,7 +29,7 @@ func (t *torrent) handlePieceWriteDone(pw *piecewriter.PieceWriter) { t.log.Debugln("received corrupt piece from webseed", src.URL) t.disableSource(src.URL, errors.New("corrupt piece"), false) default: - panic("unhandled piece source") + t.crash("unhandled piece source") } t.startPieceDownloaders() return @@ -41,7 +41,7 @@ func (t *torrent) handlePieceWriteDone(pw *piecewriter.PieceWriter) { pw.Piece.Done = true if t.bitfield.Test(pw.Piece.Index) { - panic(fmt.Sprintf("already have the piece #%d", pw.Piece.Index)) + t.crash(fmt.Sprintf("already have the piece #%d", pw.Piece.Index)) } t.mBitfield.Lock() t.bitfield.Set(pw.Piece.Index)