Permalink
Browse files

Updated logging handling in case of errors by first emmiting context …

…based error message and only then throwing the error.

In most cases the error is not directly related to the context, so it's message is confusing as to where the error happened and what the utility was doing. The new messages should handle this better.
  • Loading branch information...
1 parent c4cf7ba commit fe4e0235884c2c94aa0eceadc8af104f29fdee89 @tomaz committed Jun 5, 2009
Showing with 34 additions and 37 deletions.
  1. +2 −2 CommandLineParser.m
  2. +1 −0 DoxygenConverter+CleanOutput.m
  3. +4 −0 DoxygenConverter+CleanXML.m
  4. +8 −27 DoxygenConverter+DocSet.m
  5. +1 −0 DoxygenConverter.m
  6. +3 −3 GeneratorBase.m
  7. +15 −5 Systemator.m
View
@@ -328,8 +328,8 @@ - (void) parseCommandLineArguments:(const char**) argv
NSString* message = [NSString stringWithFormat:
@"Custom templates path '%@' doesn't contain all required files!",
self.templatesPath];
- [Systemator throwExceptionWithName:kTKCommandLineException
- withDescription:message];
+ logError(@"Failed parsing custom templates path at '%@'!", self.templatesPath);
+ [Systemator throwExceptionWithName:kTKCommandLineException withDescription:message];
}
}
@@ -63,6 +63,7 @@ - (void) createCleanOutputDocumentation
NSError* error = nil;
if (![manager removeItemAtPath:cmd.outputCleanXMLPath error:&error])
{
+ logError(@"Failed removing temporary clean XML files at '%@'!", cmd.outputCleanXMLPath);
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
}
@@ -439,6 +439,7 @@ - (void) createCleanIndexDocumentationFile
NSString* filename = [cmd.outputCleanXMLPath stringByAppendingPathComponent:@"Index.xml"];
if (![markupData writeToFile:filename options:0 error:&error])
{
+ logError(@"Failed writting clean Index.xml to '%@'!", filename);
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
@@ -558,6 +559,7 @@ - (void) createCleanHierarchyDocumentationFile
NSString* filename = [cmd.outputCleanXMLPath stringByAppendingPathComponent:@"Hierarchy.xml"];
if (![markupData writeToFile:filename options:0 error:&error])
{
+ logError(@"Failed writting clean Hierarchy.xml to '%@'!", filename);
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
@@ -637,6 +639,7 @@ - (void) saveCleanObjectDocumentationFiles
NSError* error = nil;
if (![manager removeItemAtPath:doxygenXMLOutputPath error:&error])
{
+ logError(@"Failed removing temporary doxygen files at '%@'!", doxygenXMLOutputPath);
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
}
@@ -1169,6 +1172,7 @@ - (void) fixParaLinksForObject:(NSString*) objectName
error:&error];
if (!cleanDocument)
{
+ logError(@"Failed reloading clean XML document!");
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
[objectData setObject:cleanDocument forKey:kTKDataObjectMarkupKey];
View
@@ -152,6 +152,7 @@ - (void) createDocSetNodesFile
if (![documentData writeToFile:filename options:0 error:&error])
{
[loopAutoreleasePool drain];
+ logError(@"Failed saving DocSet Nodes.xml to '%@'!", filename);
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
@@ -274,6 +275,7 @@ - (void) createDocSetTokesFile
if (![documentData writeToFile:filename options:0 error:&error])
{
[loopAutoreleasePool drain];
+ logError(@"Failed saving DocSet Tokens.xml to '%@'!", filename);
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
@@ -285,26 +287,15 @@ - (void) createDocSetTokesFile
- (void) createDocSetBundle
{
logNormal(@"Creating DocSet bundle...");
- NSError* error = nil;
// First copy the info plist file into the contents output.
NSString* plistDestPath = [cmd.outputDocSetContentsPath stringByAppendingPathComponent:@"Info.plist"];
logVerbose(@"Copying info plist file to '%@'...", plistDestPath);
- if (![manager copyItemAtPath:cmd.docsetSourcePlistPath
- toPath:plistDestPath
- error:&error])
- {
- [Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
- }
+ [Systemator copyItemAtPath:cmd.docsetSourcePlistPath toPath:plistDestPath];
// Copy all html files to the bundle structure.
logVerbose(@"Copying clean XHTML to '%@'...", cmd.outputDocSetDocumentsPath);
- if (![manager copyItemAtPath:cmd.outputCleanXHTMLPath
- toPath:cmd.outputDocSetDocumentsPath
- error:&error])
- {
- [Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
- }
+ [Systemator copyItemAtPath:cmd.outputCleanXHTMLPath toPath:cmd.outputDocSetDocumentsPath];
// Index the documentation set.
logVerbose(@"Indexing DocSet...");
@@ -313,21 +304,8 @@ - (void) createDocSetBundle
// Copy the documentation set to the proper directory. First we need to remove
// previous files otherwise copying will fail.
NSString* docsetInstallPath = [cmd.docsetInstallPath stringByAppendingPathComponent:cmd.docsetBundleID];
- if ([manager fileExistsAtPath:docsetInstallPath])
- {
- logVerbose(@"Removing existing DocSet bundle at '%@'", docsetInstallPath);
- if (![manager removeItemAtPath:docsetInstallPath error:&error])
- {
- [Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
- }
- }
logVerbose(@"Copying DocSet bundle to '%@'...", docsetInstallPath);
- if (![manager copyItemAtPath:cmd.outputDocSetPath
- toPath:docsetInstallPath
- error:&error])
- {
- [Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
- }
+ [Systemator copyItemAtPath:cmd.outputDocSetPath toPath:docsetInstallPath];
// Install the script to the Xcode.
logVerbose(@"Installing DocSet to Xcode...");
@@ -343,6 +321,7 @@ - (void) createDocSetBundle
[installScript release];
NSString* message = [NSString stringWithFormat:@"Installation of DocSet failed with message:\n'%@'!",
[errorDict objectForKey:NSAppleScriptErrorMessage]];
+ logError(@"Failed installing DocSet to Xcode documentation!");
[Systemator throwExceptionWithName:kTKConverterException
withDescription:message];
}
@@ -355,6 +334,7 @@ - (void) createDocSetBundle
NSError* error = nil;
if (![manager removeItemAtPath:cmd.outputCleanXHTMLPath error:&error])
{
+ logError(@"Failed removing temporary XHTML files at '%@'!", cmd.outputCleanXHTMLPath);
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
}
@@ -366,6 +346,7 @@ - (void) createDocSetBundle
NSError* error = nil;
if (![manager removeItemAtPath:cmd.outputDocSetPath error:&error])
{
+ logError(@"Failed removing temporary DocSet files at '%@'!", cmd.outputDocSetPath);
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
}
View
@@ -133,6 +133,7 @@ - (void) createOutputDirectoriesAndRemovePreviousOutputFiles
// Remove previous directory.
if (![manager removeItemAtPath:cmd.outputPath error:&error])
{
+ logError(@"Failed removing previous output files at '%@'!", cmd.outputPath);
[Systemator throwExceptionWithName:kTKConverterException basedOnError:error];
}
View
@@ -243,7 +243,7 @@ - (void) generateOutputForObject:(NSDictionary*) data
if (![result writeToFile:filename atomically:NO])
{
NSString* message = [NSString stringWithFormat:@"Failed saving object output to '%@'!", filename];
- logError(message);
+ logError(@"Failed saving clean object output!");
[Systemator throwExceptionWithName:kTKConverterException withDescription:message];
}
wasFileCreated = YES;
@@ -271,7 +271,7 @@ - (void) generateOutputForIndex:(NSDictionary*) data
if (![result writeToFile:filename atomically:NO])
{
NSString* message = [NSString stringWithFormat:@"Failed saving index output to '%@'!", filename];
- logError(message);
+ logError(@"Failed saving clean index output!");
[Systemator throwExceptionWithName:kTKConverterException withDescription:message];
}
wasFileCreated = YES;
@@ -299,7 +299,7 @@ - (void) generateOutputForHierarchy:(NSDictionary*) data
if (![result writeToFile:filename atomically:NO])
{
NSString* message = [NSString stringWithFormat:@"Failed saving hierarchy output to '%@'!", filename];
- logError(message);
+ logError(@"Failed saving clean hierarchy output!");
[Systemator throwExceptionWithName:kTKConverterException withDescription:message];
}
wasFileCreated = YES;
View
@@ -190,6 +190,7 @@ + (void) copyItemAtPath:(NSString*) source
}
}
+ logDebug(@"- Copying '%@' to '%@'...", source, destination);
if (![manager copyItemAtPath:source
toPath:destination
error:&error])
@@ -210,7 +211,11 @@ + (NSMutableArray*) linesFromContentsOfFile:(NSString*) filename
NSString* contents = [[NSString alloc] initWithContentsOfFile:filename
encoding:NSASCIIStringEncoding
error:&error];
- if (!contents) [self throwExceptionWithName:kTKSystemError basedOnError:error];
+ if (!contents)
+ {
+ logError(@"Failed reading data from '%@'!", filename);
+ [self throwExceptionWithName:kTKSystemError basedOnError:error];
+ }
return [self linesFromString:contents];
}
@@ -232,6 +237,7 @@ + (void) writeLines:(NSArray*) lines toFile:(NSString*) filename
encoding:NSASCIIStringEncoding
error:&error])
{
+ logError(@"Failed writting data to file '%@'!", filename);
[self throwExceptionWithName:kTKSystemError basedOnError:error];
}
}
@@ -246,7 +252,8 @@ + (id) readPropertyListFromFile:(NSString*) filename
error:&error];
if (!infoPlistData)
{
- [Systemator throwExceptionWithName:kTKSystemError basedOnError:error];
+ logError(@"Failed reading property list data from '%@'!", filename);
+ [self throwExceptionWithName:kTKSystemError basedOnError:error];
}
// Convert the data into the object that will represent the property list.
@@ -257,7 +264,8 @@ + (id) readPropertyListFromFile:(NSString*) filename
errorDescription:&errorDescription];
if (!docsetInfo)
{
- [Systemator throwExceptionWithName:kTKSystemError withDescription:errorDescription];
+ logError(@"Failed parsing property list data from '%@'!", filename);
+ [self throwExceptionWithName:kTKSystemError withDescription:errorDescription];
}
return docsetInfo;
@@ -273,8 +281,9 @@ + (void) writePropertyList:(id) plist toFile:(NSString*) filename
errorDescription:&errorDescription];
if (!infoPlistData)
{
+ logError(@"Failed extracting property list data for '%@'!", filename);
[errorDescription autorelease];
- [Systemator throwExceptionWithName:kTKSystemError withDescription:errorDescription];
+ [self throwExceptionWithName:kTKSystemError withDescription:errorDescription];
}
// Save the data to the file.
@@ -283,7 +292,8 @@ + (void) writePropertyList:(id) plist toFile:(NSString*) filename
options:0
error:&error])
{
- [Systemator throwExceptionWithName:kTKSystemError basedOnError:error];
+ logError(@"Failed writting property list data to '%@'!", filename);
+ [self throwExceptionWithName:kTKSystemError basedOnError:error];
}
}

0 comments on commit fe4e023

Please sign in to comment.