Skip to content

Commit

Permalink
Improve errors in FCEU.
Browse files Browse the repository at this point in the history
  • Loading branch information
clobber committed Sep 15, 2013
1 parent 0366158 commit 8100a2d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions FCEUGameCore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,15 @@ - (void)saveStateToFileAtPath:(NSString *)fileName completionHandler:(void (^)(B
int serial_size = snes_serialize_size();
NSMutableData *stateData = [NSMutableData dataWithLength:serial_size];

snes_serialize((uint8_t *)[stateData mutableBytes], serial_size);
if(!snes_serialize((uint8_t *)[stateData mutableBytes], serial_size))
{
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotSaveStateError userInfo:@{
NSLocalizedDescriptionKey : @"Save state data could not be written",
NSLocalizedRecoverySuggestionErrorKey : @"The emulator could not write the state data."
}];
block(NO, error);
return;
}

__autoreleasing NSError *error = nil;
BOOL success = [stateData writeToFile:fileName options:NSDataWritingAtomic error:&error];
Expand All @@ -378,17 +386,20 @@ - (void)loadStateFromFileAtPath:(NSString *)fileName completionHandler:(void (^)
int serial_size = snes_serialize_size();
if(serial_size != [data length])
{
// FIXME: Provide constants for error handling in OpenEmu SDK.
NSError *error = [NSError errorWithDomain:@"org.openemu.GameCore.Load" code:-10 userInfo:
@{ NSLocalizedDescriptionKey : [NSString stringWithFormat:@"The size of the file %@ does not have the right size, %d expected, got: %ld.", fileName, serial_size, [data length]] }];
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreStateHasWrongSizeError userInfo:@{
NSLocalizedDescriptionKey : @"Save state has wrong file size.",
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat:@"The size of the file %@ does not have the right size, %d expected, got: %ld.", fileName, serial_size, [data length]],
}];
block(NO, error);
return;
}

if(!snes_unserialize((uint8_t *)[data bytes], serial_size))
{
NSError *error = [NSError errorWithDomain:@"org.openemu.GameCore.Load" code:-10 userInfo:
@{ NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Could not read the file state in %@.", fileName] }];
NSError *error = [NSError errorWithDomain:OEGameCoreErrorDomain code:OEGameCoreCouldNotLoadStateError userInfo:@{
NSLocalizedDescriptionKey : @"The save state data could not be read",
NSLocalizedRecoverySuggestionErrorKey : [NSString stringWithFormat:@"Could not read the file state in %@.", fileName]
}];
block(NO, error);
return;
}
Expand Down

0 comments on commit 8100a2d

Please sign in to comment.