diff --git a/ChangeLog b/ChangeLog index 1c9689741..ef14d901e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-01-19 Fred Kiefer + + * Source/NSDocument.m: Add some NSError return values. + 2014-01-12 Fred Kiefer * Source/NSTextAttachment.m: Add keyed coding. diff --git a/Source/NSDocument.m b/Source/NSDocument.m index c27adf41a..2f46ac46f 100644 --- a/Source/NSDocument.m +++ b/Source/NSDocument.m @@ -29,6 +29,7 @@ */ #import +#import #import #import #import @@ -48,6 +49,16 @@ #import "GSGuiPrivate.h" +static inline NSError* +create_error(int code, NSString* desc) +{ + return [NSError errorWithDomain: @"NSDocument" + code: code + userInfo: [NSDictionary + dictionaryWithObjectsAndKeys: desc, + NSLocalizedDescriptionKey, nil]]; +} + @implementation NSDocument + (NSArray *) readableTypes @@ -629,8 +640,11 @@ withContentsOfURL: (NSURL *)url data = [self dataOfType: type error: error]; if (data == nil) - return nil; - + { + *error = create_error(0, NSLocalizedString(@"Could not create data for type.", + @"Error description")); + return nil; + } return AUTORELEASE([[NSFileWrapper alloc] initRegularFileWithContents: data]); } @@ -730,9 +744,11 @@ withContentsOfURL: (NSURL *)url error: error]; } - // FIXME: Set error if (error) - *error = nil; + { + *error = create_error(0, NSLocalizedString(@"File wrapper is no file.", + @"Error description")); + } return NO; } @@ -894,6 +910,11 @@ withContentsOfURL: (NSURL *)url ofType: type saveOperation: op]) { + if (error) + { + *error = create_error(0, NSLocalizedString(@"Could not write backup file.", + @"Error description")); + } return NO; } @@ -907,9 +928,11 @@ withContentsOfURL: (NSURL *)url if (!isNativeType || (url == nil)) { - // FIXME: Set error if (error) - *error = nil; + { + *error = create_error(0, NSLocalizedString(@"Not a writable type or no URL given.", + @"Error description")); + } return NO; } @@ -927,9 +950,11 @@ withContentsOfURL: (NSURL *)url if (![self _writeBackupForFile: fileName toFile: backupFilename]) { - // FIXME: Set error. if (error) - *error = nil; + { + *error = create_error(0, NSLocalizedString(@"Could not write backup file.", + @"Error description")); + } return NO; } } @@ -997,9 +1022,11 @@ withContentsOfURL: (NSURL *)url error: error]; if (wrapper == nil) { - // FIXME: Set error if (error) - *error = nil; + { + *error = create_error(0, NSLocalizedString(@"Could not write file wrapper.", + @"Error description")); + } return NO; }