You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/05/10 11:43:34 UTC

[plc4x] branch develop updated: refactor(plc4go): convert some panics to errors

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new 1eaa3d5897 refactor(plc4go): convert some panics to errors
1eaa3d5897 is described below

commit 1eaa3d5897af3c788a6827617aafd4520b84b767
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed May 10 13:43:26 2023 +0200

    refactor(plc4go): convert some panics to errors
---
 plc4go/internal/cbus/MessageCodec.go    | 4 ++--
 plc4go/spi/transports/pcap/Transport.go | 3 ++-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/plc4go/internal/cbus/MessageCodec.go b/plc4go/internal/cbus/MessageCodec.go
index 1085eb8ca1..3f10f43a0b 100644
--- a/plc4go/internal/cbus/MessageCodec.go
+++ b/plc4go/internal/cbus/MessageCodec.go
@@ -234,7 +234,7 @@ lookingForTheEnd:
 
 	// Sanity check
 	if pciResponse && requestToPci {
-		panic("Invalid state... Can not be response and request at the same time")
+		return nil, errors.New("Invalid state... Can not be response and request at the same time")
 	}
 
 	// We need to ensure that there is no ! till the first /r
@@ -271,7 +271,7 @@ lookingForTheEnd:
 		log.Trace().Msgf("Read packet length %d", packetLength)
 		read, err := ti.Read(uint32(packetLength))
 		if err != nil {
-			panic("Invalid state... If we have peeked that before we should be able to read that now")
+			return nil, errors.Wrap(err, "Invalid state... If we have peeked that before we should be able to read that now")
 		}
 		rawInput = read
 	}
diff --git a/plc4go/spi/transports/pcap/Transport.go b/plc4go/spi/transports/pcap/Transport.go
index fa36ec2e87..e1943e8a41 100644
--- a/plc4go/spi/transports/pcap/Transport.go
+++ b/plc4go/spi/transports/pcap/Transport.go
@@ -142,7 +142,8 @@ func (m *TransportInstance) Connect() error {
 					break
 				}
 				log.Warn().Err(err).Msg("Error reading")
-				panic(err)
+				m.connected = false
+				return
 			}
 			if lastPacketTime != nil && m.speedFactor != 0 {
 				timeToSleep := captureInfo.Timestamp.Sub(*lastPacketTime)