Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EDX-4443 Improve error message for parsing xlsx row #214

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions central/xlsx/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func convertDTOStdTypeFields(rowElement *reflect.Value, xlsxRow []string, header

err := setStdStructFieldValue(fieldValue, field)
if err != nil {
return err
return fmt.Errorf("error occurred on '%s' column: %w", headerName, err)
cloudxxx8 marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
// field not found in the DTO struct, skip this column
Expand Down Expand Up @@ -165,7 +165,7 @@ func convertDeviceFields(rowElement *reflect.Value, xlsxRow []string, headerCol
// header matches the Device DTO field name (one of the Name, Description, AdminState, OperatingState, etc)
err := setStdStructFieldValue(fieldValue, field)
if err != nil {
return err
return fmt.Errorf("error occurred on '%s' column: %w", headerName, err)
}
} else {
// header not belongs to the above fields with standard types
Expand Down Expand Up @@ -236,7 +236,7 @@ func convertAutoEventFields(rowElement *reflect.Value, xlsxRow []string, headerC
// header matches the AutoEvent DTO field name (one of the Interval, OnChange, SourceName field)
err := setStdStructFieldValue(fieldValue, field)
if err != nil {
return nil, err
return nil, fmt.Errorf("error occurred on '%s' column: %w", headerName, err)
}
} else {
// the cell belongs to the "Reference Device Name" column, append it to deviceNames
Expand All @@ -253,14 +253,14 @@ func convertAutoEventFields(rowElement *reflect.Value, xlsxRow []string, headerC
func convertDeviceCommandFields(rowElement *reflect.Value, xlsxRow []string, headerCol []string) error {
var resOpSlice []dtos.ResourceOperation
for colIndex, cell := range xlsxRow {
_, field := getStructFieldByHeader(rowElement, colIndex, headerCol)
headerName, field := getStructFieldByHeader(rowElement, colIndex, headerCol)
cell = strings.TrimSpace(cell)

if field.Kind() != reflect.Invalid {
// header matches the DeviceCommand field name (one of the Name, IsHidden or ReadWrite field name)
err := setStdStructFieldValue(cell, field)
if err != nil {
return err
return fmt.Errorf("error occurred on '%s' column: %w", headerName, err)
}
} else {
// parse the rest ResourceName columns in the xlsx row and convert to the ResourceOperation DTO
Expand Down Expand Up @@ -302,15 +302,15 @@ func convertResourcesFields(rowElement *reflect.Value, xlsxRow []string, headerC
// header matches the DeviceResource field name (one of the Name, Description or IsHidden field name)
err := setStdStructFieldValue(fieldValue, field)
if err != nil {
return err
return fmt.Errorf("error occurred on '%s' column: %w", headerName, err)
}
} else {
resPropField := rowElement.FieldByName(properties).FieldByName(headerName)
if resPropField.Kind() != reflect.Invalid {
// header matches the ResourceProperties DTO field name (one of the ValueType, ReadWrite, Units, etc)
err := setStdStructFieldValue(fieldValue, resPropField)
if err != nil {
return err
return fmt.Errorf("error occurred on '%s' column: %w", headerName, err)
}
} else {
// set the cell to Attributes map if header not belongs to Properties field
Expand Down