adium 3175:d23b7f99e0d0: Catch and log exceptions when an error ...
commits at adium.im
commits at adium.im
Tue Apr 27 01:14:31 UTC 2010
details: http://hg.adium.im/adium/rev/d23b7f99e0d0
revision: 3175:d23b7f99e0d0
author: Evan Schoenberg
date: Mon Apr 26 20:14:11 2010 -0500
Catch and log exceptions when an error is encountered using LMX to parse a chat transcript. Fixes #13628 - the crash, at least. We'll now just skip messages from the error-causing transcript. The actual issue at hand is within LMX and is described in detail at [http://bitbucket.org/boredzo/lmx/issue/3/ LMX Issue #3].
diffs (126 lines):
diff -r 7e558d594125 -r d23b7f99e0d0 Source/DCMessageContextDisplayPlugin.m
--- a/Source/DCMessageContextDisplayPlugin.m Mon Apr 26 18:55:40 2010 -0500
+++ b/Source/DCMessageContextDisplayPlugin.m Mon Apr 26 20:14:11 2010 -0500
@@ -143,6 +143,7 @@
{
//If there's no log there, there's no message history. Bail out.
NSArray *logPaths = [AILoggerPlugin sortedArrayOfLogFilesForChat:chat];
+
if(!logPaths) return nil;
NSInteger linesLeftToFind = 0;
@@ -237,59 +238,67 @@
// These set of file's autorelease pool.
NSAutoreleasePool *parsingAutoreleasePool = [[NSAutoreleasePool alloc] init];
- do {
- // The location we're going to read for *this* set of reads.
- off_t readOffset = offset - readSize;
+ @try {
+ do {
+ // The location we're going to read for *this* set of reads.
+ off_t readOffset = offset - readSize;
+
+ if (readOffset < 0) {
+ // Decrease it by the amount we're over.
+ readSize += (NSInteger)readOffset;
+ // Start from the beginning.
+ readOffset = 0;
+ }
+
+ if (chunk.length != readSize) {
+ // In case we short-read last time, or we're reading a smaller amount this time.
+ [chunk setLength:readSize];
+ }
+
+ char *buf = [chunk mutableBytes];
+
+ //Seek to it and read greedily until we hit readSize or run out of file.
+ NSInteger idx = 0;
+ ssize_t amountRead = 0;
+ for (amountRead = 0; idx < readSize; idx += amountRead) {
+ amountRead = pread(fd, buf + idx, readSize, readOffset + idx);
+ if (amountRead <= 0) break;
+ }
+
+ if (idx != readSize) {
+ // If we short read, we don't want to read unknown buffer contents.
+ [chunk setLength:idx];
+ }
+
+ // Adjust the real offset
+ offset -= idx;
+
+ //Parse
+ result = [parser parseChunk:chunk];
+
+ //Continue to parse as long as we need more elements, we have data to read, and LMX doesn't think we're done.
+ } while ([foundMessages count] < linesLeftToFind && offset > 0 && result != LMXParsedCompletely);
- if (readOffset < 0) {
- // Decrease it by the amount we're over.
- readSize += (NSInteger)readOffset;
- // Start from the beginning.
- readOffset = 0;
- }
+ } @catch (id theException) {
+ AILogWithSignature(@"Error \"%@\" while parsing %@; foundMessages at that point was %@, and the chunk to be parsed was %@",
+ theException, logPath,
+ foundMessages, chunk);
+
+ } @finally {
+ //Drain our autorelease pool.
+ [parsingAutoreleasePool release];
- if (chunk.length != readSize) {
- // In case we short-read last time, or we're reading a smaller amount this time.
- [chunk setLength:readSize];
- }
+ //Be a good citizen and close the file
+ [file closeFile];
- char *buf = [chunk mutableBytes];
-
- //Seek to it and read greedily until we hit readSize or run out of file.
- NSInteger idx = 0;
- ssize_t amountRead = 0;
- for (amountRead = 0; idx < readSize; idx += amountRead) {
- amountRead = pread(fd, buf + idx, readSize, readOffset + idx);
- if (amountRead <= 0) break;
- }
-
- if (idx != readSize) {
- // If we short read, we don't want to read unknown buffer contents.
- [chunk setLength:idx];
- }
-
- // Adjust the real offset
- offset -= idx;
-
- //Parse
- result = [parser parseChunk:chunk];
-
- //Continue to parse as long as we need more elements, we have data to read, and LMX doesn't think we're done.
- } while ([foundMessages count] < linesLeftToFind && offset > 0 && result != LMXParsedCompletely);
-
- //Drain our autorelease pool.
- [parsingAutoreleasePool release];
-
- //Be a good citizen and close the file
- [file closeFile];
-
- //Add our locals to the outer array; we're probably looping again.
- [outerFoundContentContexts replaceObjectsInRange:NSMakeRange(0, 0) withObjectsFromArray:foundMessages];
- linesLeftToFind -= [outerFoundContentContexts count];
+ //Add our locals to the outer array; we're probably looping again.
+ [outerFoundContentContexts replaceObjectsInRange:NSMakeRange(0, 0) withObjectsFromArray:foundMessages];
+ linesLeftToFind -= [outerFoundContentContexts count];
+ }
}
if (linesLeftToFind > 0) {
- AILogWithSignature(@"Unable to find %d logs for %@", linesLeftToFind, chat);
+ AILogWithSignature(@"Unable to find %d logs for %@; we needed %d more", linesToDisplay, chat, linesLeftToFind);
}
return outerFoundContentContexts;
More information about the commits
mailing list