Skip to content

BadDataException thrown inside Read forcibly mangles the error message by passing it through "AddDetails" of CsvHelperException #2157

@ldeluigi

Description

@ldeluigi

Describe the bug
BadDataException is thrown from the Read function when "An inconsistent number of columns has been detected.". By passing this message to the base constructor, BadDataException forcibly replaces the exception message with the output of AddDetails, thus making it impossible to get the original "An inconsistent number of columns has been detected." message as string, for example inside a ReadingExceptionOccurred delegate implementation.

To Reproduce

  1. Use this setting:
  configuration.ReadingExceptionOccurred = args =>
      {
         Console.WriteLine(args.Exception.Message);
         return false;
      };
  1. Parse a CSV with inconsistent line columns.

Expected behavior
I'd like to be able to retrieve the simpler message string without internal details in some way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions