add more error hints

This commit is contained in:
MaysWind
2024-09-11 00:47:26 +08:00
parent 5d75629a73
commit 031209490f
6 changed files with 56 additions and 15 deletions
@@ -199,7 +199,7 @@ func (c *DataTableTransactionDataExporter) replaceDelimiters(text string) string
func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, user *models.User, dataTable ImportedDataTable, defaultTimezoneOffset int16, accountMap map[string]*models.Account, categoryMap map[string]*models.TransactionCategory, tagMap map[string]*models.TransactionTag) (models.ImportedTransactionSlice, []*models.Account, []*models.TransactionCategory, []*models.TransactionTag, error) {
if dataTable.DataRowCount() < 1 {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse import data for user \"uid:%d\", because data table row count is less 1", user.Uid)
return nil, nil, nil, nil, errs.ErrOperationFailed
return nil, nil, nil, nil, errs.ErrNotFoundTransactionDataInFile
}
headerLineItems := dataTable.HeaderLineColumnNames()
@@ -226,7 +226,7 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if !timeColumnExists || !typeColumnExists || !subCategoryColumnExists ||
!accountColumnExists || !amountColumnExists || !account2ColumnExists || !amount2ColumnExists {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse import data for user \"uid:%d\", because missing essential columns in header row", user.Uid)
return nil, nil, nil, nil, errs.ErrFormatInvalid
return nil, nil, nil, nil, errs.ErrMissingRequiredFieldInHeaderRow
}
if accountMap == nil {
@@ -260,7 +260,7 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if columnCount < len(headerLineItems) {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse data row \"index:%d\" for user \"uid:%d\", because may missing some columns (column count %d in data row is less than header column count %d)", dataRowIndex, user.Uid, columnCount, len(headerLineItems))
return nil, nil, nil, nil, errs.ErrFormatInvalid
return nil, nil, nil, nil, errs.ErrFewerFieldsInDataRowThanInHeaderRow
}
timezoneOffset := defaultTimezoneOffset
@@ -270,7 +270,7 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if err != nil {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse time zone \"%s\" in data row \"index:%d\" for user \"uid:%d\", because %s", dataRow.GetData(timezoneColumnIdx), dataRowIndex, user.Uid, err.Error())
return nil, nil, nil, nil, err
return nil, nil, nil, nil, errs.ErrTransactionTimeZoneInvalid
}
timezoneOffset = utils.GetTimezoneOffsetMinutes(transactionTimezone)
@@ -280,14 +280,14 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if err != nil {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse time \"%s\" in data row \"index:%d\" for user \"uid:%d\", because %s", dataRow.GetData(timeColumnIdx), dataRowIndex, user.Uid, err.Error())
return nil, nil, nil, nil, err
return nil, nil, nil, nil, errs.ErrTransactionTimeInvalid
}
transactionDbType, err := c.getTransactionDbType(dataRow.GetData(typeColumnIdx))
if err != nil {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse transaction type \"%s\" in data row \"index:%d\" for user \"uid:%d\", because %s", dataRow.GetData(typeColumnIdx), dataRowIndex, user.Uid, err.Error())
return nil, nil, nil, nil, err
return nil, nil, nil, nil, errs.Or(err, errs.ErrTransactionTypeInvalid)
}
categoryId := int64(0)
@@ -298,14 +298,14 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if err != nil {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse transaction category type in data row \"index:%d\" for user \"uid:%d\", because %s", dataRowIndex, user.Uid, err.Error())
return nil, nil, nil, nil, err
return nil, nil, nil, nil, errs.Or(err, errs.ErrTransactionTypeInvalid)
}
subCategoryName = dataRow.GetData(subCategoryColumnIdx)
if subCategoryName == "" {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] sub category type is empty in data row \"index:%d\" for user \"uid:%d\"", dataRowIndex, user.Uid)
return nil, nil, nil, nil, errs.ErrFormatInvalid
return nil, nil, nil, nil, errs.ErrSubCategoryNameCannotBeBlank
}
subCategory, exists := categoryMap[subCategoryName]
@@ -323,7 +323,7 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if accountName == "" {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] account name is empty in data row \"index:%d\" for user \"uid:%d\"", dataRowIndex, user.Uid)
return nil, nil, nil, nil, errs.ErrFormatInvalid
return nil, nil, nil, nil, errs.ErrAccountNameCannotBeBlank
}
accountCurrency := user.DefaultCurrency
@@ -358,7 +358,7 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if err != nil {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse acmount \"%s\" in data row \"index:%d\" for user \"uid:%d\", because %s", dataRow.GetData(amountColumnIdx), dataRowIndex, user.Uid, err.Error())
return nil, nil, nil, nil, err
return nil, nil, nil, nil, errs.ErrAmountInvalid
}
relatedAccountId := int64(0)
@@ -371,7 +371,7 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if account2Name == "" {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] account2 name is empty in data row \"index:%d\" for user \"uid:%d\"", dataRowIndex, user.Uid)
return nil, nil, nil, nil, errs.ErrFormatInvalid
return nil, nil, nil, nil, errs.ErrDestinationAccountNameCannotBeBlank
}
account2Currency = user.DefaultCurrency
@@ -407,7 +407,7 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if err != nil {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse acmount2 \"%s\" in data row \"index:%d\" for user \"uid:%d\", because %s", dataRow.GetData(amount2ColumnIdx), dataRowIndex, user.Uid, err.Error())
return nil, nil, nil, nil, err
return nil, nil, nil, nil, errs.ErrAmountInvalid
}
}
@@ -422,14 +422,14 @@ func (c *DataTableTransactionDataImporter) parseImportedData(ctx core.Context, u
if err != nil {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse geographic location \"%s\" in data row \"index:%d\" for user \"uid:%d\", because %s", dataRow.GetData(geoLocationIdx), dataRowIndex, user.Uid, err.Error())
return nil, nil, nil, nil, err
return nil, nil, nil, nil, errs.ErrGeographicLocationInvalid
}
geoLatitude, err = utils.StringToFloat64(geoLocationItems[1])
if err != nil {
log.Errorf(ctx, "[data_table_transaction_data_converter.parseImportedData] cannot parse geographic location \"%s\" in data row \"index:%d\" for user \"uid:%d\", because %s", dataRow.GetData(geoLocationIdx), dataRowIndex, user.Uid, err.Error())
return nil, nil, nil, nil, err
return nil, nil, nil, nil, errs.ErrGeographicLocationInvalid
}
}
}
@@ -144,7 +144,7 @@ func createNewezbookkeepingTransactionPlainTextDataTable(content string, columnS
allLines := strings.Split(content, lineSeparator)
if len(allLines) < 2 {
return nil, errs.ErrOperationFailed
return nil, errs.ErrNotFoundTransactionDataInFile
}
headerLine := allLines[0]