Skip to content

Commit ff15248

Browse files
committed
Show column in csv parser exceptions
1 parent c6d8b51 commit ff15248

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Experimental/src/TableData/CsvFormat.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ private static string[] ParseCsv(TextReader reader, ref int lineNum, char separa
4444
var result = new List<string>();
4545
StringBuilder curField = null;
4646
var state = ParserState.ExpectField;
47+
var column = 1;
4748
while (true)
4849
{
4950
var skip = false;
@@ -98,7 +99,7 @@ private static string[] ParseCsv(TextReader reader, ref int lineNum, char separa
9899
case ParserState.QuotedField:
99100
Debug.Assert(curField != null, "curField != null");
100101
if (curChar.IsEof)
101-
throw new FormatException("Unexpected EOF");
102+
throw new FormatException($"Unexpected EOF at line {lineNum} column {column}");
102103

103104
skip = true;
104105
if (curChar.IsEol)
@@ -135,15 +136,19 @@ private static string[] ParseCsv(TextReader reader, ref int lineNum, char separa
135136
state = ParserState.ExpectField;
136137
break;
137138
}
138-
throw new FormatException($"Unexpected char '{curChar.Char}' at line {lineNum}");
139+
throw new FormatException($"Unexpected char '{curChar.Char}' at line {lineNum} column {column}");
139140

140141
default:
141142
throw new ArgumentOutOfRangeException();
142143
}
143144

144145
curChar = curChar.Next();
146+
column++;
145147
if (curChar.IsEol)
148+
{
146149
lineNum++;
150+
column = 1;
151+
}
147152
}
148153
}
149154

0 commit comments

Comments
 (0)