adium-1.4 2924:90cc6e5031bb: Catch and log exceptions when an er...
commits at adium.im
commits at adium.im
Tue Apr 27 01:18:30 UTC 2010
details: http://hg.adium.im/adium-1.4/rev/90cc6e5031bb
revision: 2924:90cc6e5031bb
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].
(transplanted from d23b7f99e0d000237000577b2783cf9dc0e3ac9e)
diffs (122 lines):
diff -r d25486ea88cc -r 90cc6e5031bb 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
@@ -142,6 +142,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;
@@ -236,57 +237,63 @@
// 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 += 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 += 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];
+ } @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];
- //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;
+ //Be a good citizen and close the file
+ [file closeFile];
- //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];
+ //Add our locals to the outer array; we're probably looping again.
+ [outerFoundContentContexts replaceObjectsInRange:NSMakeRange(0, 0) withObjectsFromArray:foundMessages];
+ linesLeftToFind -= [outerFoundContentContexts count];
+ }
- //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];
- }
-
if (linesLeftToFind > 0) {
AILogWithSignature(@"Unable to find %d logs for %@", linesLeftToFind, chat);
}
More information about the commits
mailing list