You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by jf...@apache.org on 2018/11/01 20:17:58 UTC
[incubator-plc4x] 28/35: Throw exception when retrieving
non-existing Field in response.
This is an automated email from the ASF dual-hosted git repository.
jfeinauer pushed a commit to branch add-simple-mock-driver
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit ed3e3aceebf97a5d2e867ae631e40a3356397244
Author: julian <j....@pragmaticminds.de>
AuthorDate: Thu Nov 1 12:37:01 2018 +0100
Throw exception when retrieving non-existing Field in response.
---
.../org/apache/plc4x/java/base/messages/DefaultPlcReadResponse.java | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/DefaultPlcReadResponse.java b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/DefaultPlcReadResponse.java
index 30f80de..65c51ca 100644
--- a/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/DefaultPlcReadResponse.java
+++ b/plc4j/protocols/driver-bases/base/src/main/java/org/apache/plc4x/java/base/messages/DefaultPlcReadResponse.java
@@ -19,6 +19,7 @@ under the License.
package org.apache.plc4x.java.base.messages;
import org.apache.commons.lang3.tuple.Pair;
+import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
import org.apache.plc4x.java.api.model.PlcField;
import org.apache.plc4x.java.api.types.PlcResponseCode;
import org.apache.plc4x.java.base.messages.items.BaseDefaultFieldItem;
@@ -699,10 +700,10 @@ public class DefaultPlcReadResponse implements InternalPlcReadResponse {
private BaseDefaultFieldItem getFieldInternal(String name) {
// If this field doesn't exist, ignore it.
if (values.get(name) == null) {
- return null;
+ throw new PlcRuntimeException("No field with name '" + name + "' present in the response");
}
if (values.get(name).getKey() != PlcResponseCode.OK) {
- return null;
+ throw new PlcRuntimeException("Field '" + name + "' could not be fetched, response was " + values.get(name).getKey());
}
return values.get(name).getValue();
}