You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by fs...@apache.org on 2019/08/01 18:56:07 UTC
[jmeter] 01/02: Log more details on broken CSV files
This is an automated email from the ASF dual-hosted git repository.
fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git
commit 5f41f757ba6cfaee6d95892f1c15eff1d56d638b
Author: Felix Schumacher <fe...@internetallee.de>
AuthorDate: Thu Aug 1 20:49:56 2019 +0200
Log more details on broken CSV files
When corrupt CSV files are read by ReportGenerator it is often
not clear enough where the broken data in the file is. Give
more details in log messages and exceptions.
Inspired by Bugzilla Id: 63614
---
.../apache/jmeter/report/core/CsvSampleReader.java | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/src/core/org/apache/jmeter/report/core/CsvSampleReader.java b/src/core/org/apache/jmeter/report/core/CsvSampleReader.java
index 36cfe4e..fb889fe 100644
--- a/src/core/org/apache/jmeter/report/core/CsvSampleReader.java
+++ b/src/core/org/apache/jmeter/report/core/CsvSampleReader.java
@@ -140,6 +140,7 @@ public class CsvSampleReader implements Closeable{
SampleMetadata result;
// Read first line
String line = reader.readLine();
+ this.row++;
if (line == null) {
throw new IllegalArgumentException("File is empty");
}
@@ -185,10 +186,7 @@ public class CsvSampleReader implements Closeable{
data = CSVSaveService.csvReadFile(reader, separator);
Sample sample = null;
if (data.length > 0) {
- if (data.length != columnCount+numberOfSampleVariablesInCsv) {
- throw new SampleException("Mismatch between expected number of columns:"+columnCount+" and columns in CSV file:"+data.length+
- ", check your jmeter.save.saveservice.* configuration or check line is complete");
- }
+ assertCorrectColumns(data);
sample = new Sample(row++, metadata, data);
}
return sample;
@@ -197,6 +195,20 @@ public class CsvSampleReader implements Closeable{
}
}
+ private void assertCorrectColumns(String[] data) {
+ if (data.length != columnCount + numberOfSampleVariablesInCsv) {
+ if (log.isWarnEnabled()) {
+ log.warn("Short CSV read around line {} of file '{}'. Could only read {} elements of {} expected. Data is [{}]",
+ Long.valueOf(row + 2), file, Integer.valueOf(data.length), Integer.valueOf(columnCount),
+ String.join(", ", data));
+ }
+ throw new SampleException(
+ "Mismatch between expected number of columns:" + columnCount + " and columns in CSV file:"
+ + data.length + ", check your jmeter.save.saveservice.* configuration or check if line "
+ + (row + 2) + " in '" + file + "' is complete");
+ }
+ }
+
/**
* @return next sample from the file.
*/