[VOL-2938]Failure seen when parsing adapter config

Change-Id: Ie044eb110c36fc4b7597457fa6b1f6c94cd1baff
diff --git a/VERSION b/VERSION
index 781dcb0..738a839 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.1.3
+1.1.4-dev
diff --git a/internal/pkg/commands/events.go b/internal/pkg/commands/events.go
index f237878..43bfe75 100644
--- a/internal/pkg/commands/events.go
+++ b/internal/pkg/commands/events.go
@@ -270,9 +270,24 @@
 		i++
 	}
 
-	evHeader := EventHeader{Category: model.GetEnumString(header, "category", cat),
-		SubCategory: model.GetEnumString(header, "sub_category", subCat),
-		Type:        model.GetEnumString(header, "type", evType),
+	header_category, err := model.GetEnumString(header, "category", cat)
+	if err != nil {
+		return nil, err
+	}
+
+	header_subcategory, err := model.GetEnumString(header, "sub_category", subCat)
+	if err != nil {
+		return nil, err
+	}
+
+	header_type, err := model.GetEnumString(header, "type", evType)
+	if err != nil {
+		return nil, err
+	}
+
+	evHeader := EventHeader{Category: header_category,
+		SubCategory: header_subcategory,
+		Type:        header_type,
 		Raised_ts:   raised,
 		Reported_ts: reported,
 		Device_ids:  device_id_keys,
diff --git a/internal/pkg/commands/message.go b/internal/pkg/commands/message.go
index ab0146f..0d9e2fb 100644
--- a/internal/pkg/commands/message.go
+++ b/internal/pkg/commands/message.go
@@ -257,7 +257,10 @@
 						return nil, err
 					}
 					iaMessageType := iaMessageTypeIntf.(int32)
-					iaMessageTypeStr = model.GetEnumString(iaHeader, "type", iaMessageType)
+					iaMessageTypeStr, err = model.GetEnumString(iaHeader, "type", iaMessageType)
+					if err != nil {
+						return nil, err
+					}
 
 					toDeviceIdIntf, err := iaHeader.TryGetFieldByName("to_device_id")
 					if err != nil {
@@ -274,9 +277,13 @@
 			}
 		}
 	}
+	messageHeaderType, err := model.GetEnumString(header, "type", msgType)
+	if err != nil {
+		return nil, err
+	}
 
 	icHeader := MessageHeader{Id: id,
-		Type:             model.GetEnumString(header, "type", msgType),
+		Type:             messageHeaderType,
 		FromTopic:        fromTopic,
 		ToTopic:          toTopic,
 		KeyTopic:         keyTopic,
diff --git a/pkg/model/device.go b/pkg/model/device.go
index 716cbc9..e307308 100644
--- a/pkg/model/device.go
+++ b/pkg/model/device.go
@@ -115,10 +115,23 @@
 			d.ProxyAddress.ChannelTermination = v.(string)
 		}
 	}
-	d.AdminState = GetEnumValue(val, "admin_state")
-	d.OperStatus = GetEnumValue(val, "oper_status")
+
+	var err error
+	d.AdminState, err = GetEnumValue(val, "admin_state")
+	if err != nil {
+		d.AdminState = "UNKNOWN"
+	}
+
+	d.OperStatus, err = GetEnumValue(val, "oper_status")
+	if err != nil {
+		d.OperStatus = "UNKNOWN"
+	}
+
 	d.Reason = val.GetFieldByName("reason").(string)
-	d.ConnectStatus = GetEnumValue(val, "connect_status")
+	d.ConnectStatus, err = GetEnumValue(val, "connect_status")
+	if err != nil {
+		d.ConnectStatus = "UNKNOWN"
+	}
 
 	ports := val.GetFieldByName("ports").([]interface{})
 	d.Ports = make([]DevicePort, len(ports))
@@ -138,11 +151,22 @@
 }
 
 func (port *DevicePort) PopulateFrom(val *dynamic.Message) {
+	var err error
 	port.PortNo = val.GetFieldByName("port_no").(uint32)
-	port.Type = GetEnumValue(val, "type")
+	port.Type, err = GetEnumValue(val, "type")
+	if err != nil {
+		port.Type = "UNKNOWN"
+	}
 	port.Label = val.GetFieldByName("label").(string)
-	port.AdminState = GetEnumValue(val, "admin_state")
-	port.OperStatus = GetEnumValue(val, "oper_status")
+	port.AdminState, err = GetEnumValue(val, "admin_state")
+	if err != nil {
+		port.AdminState = "UNKNOWN"
+	}
+
+	port.OperStatus, err = GetEnumValue(val, "oper_status")
+	if err != nil {
+		port.OperStatus = "UNKNOWN"
+	}
 	port.DeviceId = val.GetFieldByName("device_id").(string)
 	peers := val.GetFieldByName("peers").([]interface{})
 	port.Peers = make([]PeerPort, len(peers))
diff --git a/pkg/model/utils.go b/pkg/model/utils.go
index 15ef51f..682b8d1 100644
--- a/pkg/model/utils.go
+++ b/pkg/model/utils.go
@@ -16,23 +16,68 @@
 package model
 
 import (
+	"errors"
 	"github.com/jhump/protoreflect/dynamic"
 )
 
-func GetEnumValue(val *dynamic.Message, name string) string {
-	return val.FindFieldDescriptorByName(name).GetEnumType().
-		FindValueByNumber(val.GetFieldByName(name).(int32)).GetName()
-}
-
-func SetEnumValue(msg *dynamic.Message, name string, value string) {
-	eValue := msg.FindFieldDescriptorByName(name).GetEnumType().FindValueByName(value)
-	msg.SetFieldByName(name, eValue.GetNumber())
-}
-
-func GetEnumString(msg *dynamic.Message, name string, value int32) string {
-	eValue := msg.FindFieldDescriptorByName(name).GetEnumType().FindValueByNumber(value)
-	if eValue == nil {
-		panic("eValue is nil")
+func GetEnumValue(val *dynamic.Message, name string) (string, error) {
+	fd := val.FindFieldDescriptorByName(name)
+	if fd == nil {
+		return "", errors.New("fieldDescriptor is nil for " + name)
 	}
-	return eValue.GetName()
+
+	enumType := fd.GetEnumType()
+	if enumType == nil {
+		return "", errors.New("enumType is nil for " + name)
+	}
+
+	field, ok := val.GetFieldByName(name).(int32)
+	if !ok {
+		return "", errors.New("Enum integer value not found for " + name)
+	}
+
+	eValue := enumType.FindValueByNumber(field)
+	if eValue == nil {
+		return "", errors.New("Value not found for " + name)
+	}
+
+	return eValue.GetName(), nil
+}
+
+func SetEnumValue(msg *dynamic.Message, name string, value string) error {
+	fd := msg.FindFieldDescriptorByName(name)
+	if fd == nil {
+		return errors.New("fieldDescriptor is nil for " + name)
+	}
+
+	enumType := fd.GetEnumType()
+	if enumType == nil {
+		return errors.New("enumType is nil for " + name)
+	}
+
+	eValue := enumType.FindValueByName(value)
+	if eValue == nil {
+		return errors.New("Value not found for " + name)
+	}
+
+	msg.SetFieldByName(name, eValue.GetNumber())
+	return nil
+}
+
+func GetEnumString(msg *dynamic.Message, name string, value int32) (string, error) {
+	fd := msg.FindFieldDescriptorByName(name)
+	if fd == nil {
+		return "", errors.New("fieldDescriptor is nil for " + name)
+	}
+
+	enumType := fd.GetEnumType()
+	if enumType == nil {
+		return "", errors.New("enumType is nil for " + name)
+	}
+
+	eValue := enumType.FindValueByNumber(value)
+	if eValue == nil {
+		return "", errors.New("Value not found for " + name)
+	}
+	return eValue.GetName(), nil
 }