You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently I have to write something like this in order to provide to the user a better level of details about error:
vare=newList<string>();
csvReader.Configuration.ReadingExceptionCallback =(ex,row)=>{foreach(var error in ex.Data.Values){varinfo= error.ToString().Split(new[]{"\n","\r\n"}, StringSplitOptions.RemoveEmptyEntries);varvalue= info[4].Split(':')[1].Trim();varfield= info[3].Split(':')[1].Trim(); e.Add(string.Format("Could not read value {0} in row {1}, field {2}.", value, row.Row, field));}};// return e to the webpage (for example as JSON)
This is relatively ok. It gives information where exactly parsing error has occured. However, as you can see, digging this information is ugly since I have to parse string to get the value and the field name. It would be nice if this information could be exposed via properties so that I could write something like this:
csvReader.Configuration.ReadingExceptionCallback =(ex,row)=>{foreach(var error in row.Errors){ e.Add(string.Format("Could not read value {0} in row {1}, field {2}.", error.Value, error.Row, error.FieldName));}};
But above is ok... it works. What's more important is the following request.
It would also be nice to be able to provide information WHY parsing failed.
Let's say a field only accepts values "Red" or "Blue", but user types in "Yellow". We could solve this by:
// in the MyClassMap : CsvClassMap<MyClass> class
Map(x => x.Color).ErrorMessage("Accepted values are 'Red' and 'Blue'");
...// in the ReadingExceptionCallback
e.Add(string.Format("Could not read value {0} in row {1}, field {2}. {3}",
error.Value, error.Row, error.FieldName, error.Message));
This syntax would provide a lot of flexibility for developer and give clear feedback to the user.
Let me know your thoughts.
The text was updated successfully, but these errors were encountered:
In 3.0 the base CsvHelperException object has properties for all the value now. The callback will give back a CsvHelperException instead of Exception. 3.0 beta is on NuGet.
I saw a pull request that should address issue of clarifying error messages, but it still would not provide enough flexibility.
Currently I have to write something like this in order to provide to the user a better level of details about error:
This is relatively ok. It gives information where exactly parsing error has occured. However, as you can see, digging this information is ugly since I have to parse string to get the value and the field name. It would be nice if this information could be exposed via properties so that I could write something like this:
But above is ok... it works. What's more important is the following request.
It would also be nice to be able to provide information WHY parsing failed.
Let's say a field only accepts values "Red" or "Blue", but user types in "Yellow". We could solve this by:
This syntax would provide a lot of flexibility for developer and give clear feedback to the user.
Let me know your thoughts.
The text was updated successfully, but these errors were encountered: