Skip to content

Commit

Permalink
Fix LogView staying empty on invalid log entry
Browse files Browse the repository at this point in the history
Logging something like the exception from the line below breaks Error
log view and it silently refuses loading log file (and will stay empty
forever):

`throw new CoreException(new Status(IStatus.ERROR, "Failed to read
file", PLUGIN_ID, e));`

Additionally fixed multiple log reads on startup.
  • Loading branch information
iloveeclipse committed Jan 11, 2024
1 parent 9872649 commit bb3e861
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.ParseException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
import org.eclipse.core.runtime.IStatus;

Expand Down Expand Up @@ -204,7 +202,7 @@ public String getLabel(Object obj) {
/**
* Processes a given line from the log file
*/
public void processEntry(String line) throws ParseException {
public void processEntry(String line) throws IllegalArgumentException {
//!ENTRY <pluginID> <severity> <code> <date>
//!ENTRY <pluginID> <date> if logged by the framework!!!
StringTokenizer stok = new StringTokenizer(line, SPACE);
Expand Down Expand Up @@ -251,10 +249,8 @@ public void processEntry(String line) throws ParseException {
fDate = date;
fDateString = LOCAL_SDF.format(fDate.toInstant());
}
} catch (DateTimeParseException e) {
ParseException parseException = new ParseException(e.getMessage(), e.getErrorIndex());
parseException.addSuppressed(e);
throw parseException;
} catch (Exception e) {
throw new IllegalArgumentException("Failed to parse '" + dateBuffer + "'", e); //$NON-NLS-1$//$NON-NLS-2$
}
}

Expand All @@ -275,7 +271,7 @@ void appendToken(StringBuilder buffer, String token) {
* Processes the given sub-entry from the log
* @return the depth of the sub-entry
*/
public int processSubEntry(String line) throws ParseException {
public int processSubEntry(String line) throws IllegalArgumentException {
//!SUBENTRY <depth> <pluginID> <severity> <code> <date>
//!SUBENTRY <depth> <pluginID> <date>if logged by the framework!!!
StringTokenizer stok = new StringTokenizer(line, SPACE);
Expand All @@ -290,7 +286,11 @@ public int processSubEntry(String line) throws ParseException {
break;
}
case 1 : {
depth = Integer.parseInt(token);
try {
depth = Integer.parseInt(token);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Failed to parse '" + token + "'", e); //$NON-NLS-1$//$NON-NLS-2$
}
break;
}
case 2 : {
Expand Down Expand Up @@ -318,10 +318,14 @@ public int processSubEntry(String line) throws ParseException {
}
}
}
Date date = Date.from(Instant.from(GREGORIAN_SDF.parse(dateBuffer.toString())));
if (date != null) {
fDate = date;
fDateString = LOCAL_SDF.format(fDate.toInstant());
try {
Date date = Date.from(Instant.from(GREGORIAN_SDF.parse(dateBuffer.toString())));
if (date != null) {
fDate = date;
fDateString = LOCAL_SDF.format(fDate.toInstant());
}
} catch (Exception e) {
throw new IllegalArgumentException("Failed to parse '" + dateBuffer + "'", e); //$NON-NLS-1$//$NON-NLS-2$
}
return depth;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.util.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
Expand Down Expand Up @@ -121,7 +120,7 @@ public static LogSession parseLogFile(File file, long maxLogTailSizeInMegaByte,
setNewParent(parents, entry, 0);
current = entry;
addEntry(current, entries, memento);
} catch (ParseException pe) {
} catch (IllegalArgumentException pe) {
//do nothing, just toss the entry
}
break;
Expand All @@ -135,7 +134,7 @@ public static LogSession parseLogFile(File file, long maxLogTailSizeInMegaByte,
current = entry;
LogEntry parent = parents.get(depth - 1);
parent.addChild(entry);
} catch (ParseException pe) {
} catch (IllegalArgumentException pe) {
//do nothing, just toss the bad entry
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public class LogView extends ViewPart implements LogListener {
private Text fTextLabel;
private Shell fTextShell;

private boolean fFirstEvent = true;
private volatile boolean fFirstEvent = true;

private TreeColumn fColumn1;
private TreeColumn fColumn2;
Expand Down Expand Up @@ -1092,11 +1092,17 @@ public void logged(org.osgi.service.log.LogEntry input) {
}
return;
}
boolean shouldReadLog;
synchronized (batchedEntries) {
shouldReadLog = fFirstEvent || (currentSession == null);
if (shouldReadLog) {
fFirstEvent = false;
}
}

if (fFirstEvent || (currentSession == null)) {
if (shouldReadLog) {
readLogFile();
asyncRefresh(true);
fFirstEvent = false;
} else {
LogEntry entry = betterInput != null ? createLogEntry(betterInput) : createLogEntry(input);

Expand Down

0 comments on commit bb3e861

Please sign in to comment.