better error handling

This commit is contained in:
rusefillc 2023-12-15 10:38:17 -05:00
parent aa5b1f2fea
commit f9cd363abf
6 changed files with 13 additions and 7 deletions

View File

@ -41,7 +41,11 @@ public interface CANLineReader {
return readLine(line, "no-file-name");
}
CANPacket readLine(String line, String fileName);
default CANPacket readLine(String line, String fileName) {
return readLine(line, fileName, -1);
}
CANPacket readLine(String line, String fileName, int lineIndex);
default List<CANPacket> readFile(String fileName) throws IOException {
return skipHeaderAndRead(fileName, 0);

View File

@ -10,7 +10,7 @@ public enum CANoeReader implements CANLineReader {
INSTANCE;
@Override
public CANPacket readLine(String line, String fileName) {
public CANPacket readLine(String line, String fileName, int lineIndex) {
if (line.contains("ErrorFrame"))
return null;
String[] tokens = line.trim().split("\\s+");

View File

@ -18,7 +18,7 @@ public enum CanHackerReader implements CANLineReader {
INSTANCE;
@Override
public CANPacket readLine(String line, String fileName) {
public CANPacket readLine(String line, String fileName, int lineIndex) {
line = line.trim();
if (line.startsWith("@"))
return null;

View File

@ -19,8 +19,8 @@ public class PcanAutoReader implements CANLineReader {
}
@Override
public CANPacket readLine(String line, String fileName) {
return delegate.readLine(line, fileName);
public CANPacket readLine(String line, String fileName, int lineIndex) {
return delegate.readLine(line, fileName, lineIndex);
}
@Override

View File

@ -13,13 +13,15 @@ public class PcanTrcReader1_1 implements CANLineReader {
public static final CANLineReader INSTANCE = new PcanTrcReader1_1();
@Override
public CANPacket readLine(String line, String fileName) {
public CANPacket readLine(String line, String fileName, int lineIndex) {
line = line.trim();
if (line.startsWith(FILEVERSION) && !line.startsWith(FILEVERSION + "=1.1"))
throw new IllegalStateException("Unexpected fileversion " + line);
if (line.startsWith(";"))
return null;
String[] tokens = line.split("\\s+");
if (tokens.length < 2)
throw new IllegalStateException("Unexpected token count in [" + line + "]@" + lineIndex);
double timeStamp = Double.parseDouble(tokens[1]);
int sid = Integer.parseInt(tokens[3], 16);

View File

@ -13,7 +13,7 @@ public enum PcanTrcReader2_0 implements CANLineReader {
public static final String FILEVERSION = ";$FILEVERSION";
@Override
public CANPacket readLine(String line, String fileName) {
public CANPacket readLine(String line, String fileName, int lineIndex) {
line = line.trim();
if (line.startsWith(FILEVERSION) && !line.startsWith(FILEVERSION + "=2.0"))
throw new IllegalStateException("Unexpected fileversion " + line + " in " + fileName);