2
0

Show internal reason for why import fails.

This commit is contained in:
Maarten Billemont 2020-04-20 17:09:38 -04:00
parent 694b5ea227
commit d4de3afb72

View File

@ -563,21 +563,20 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted );
// Read metadata for the import file. // Read metadata for the import file.
MPMarshalledFile *file = mpw_marshal_read( NULL, importData.UTF8String ); MPMarshalledFile *file = mpw_marshal_read( NULL, importData.UTF8String );
MPMarshalledUser *importUser = nil;
@try {
if (!file) if (!file)
return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{ return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{
@"type" : @(MPMarshalErrorInternal), @"type" : @(MPMarshalErrorInternal),
NSLocalizedDescriptionKey: @"Could not process Master Password import data.", NSLocalizedDescriptionKey: @"Could not process Master Password import data.",
}]), @"While importing sites." ); }]), @"While importing sites." );
if (file->error.type != MPMarshalSuccess) { if (file->error.type != MPMarshalSuccess) {
MPMarshalErrorType type = file->error.type;
mpw_marshal_file_free( &file );
return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{ return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{
@"type" : @(type), @"type" : @(file->error.type),
NSLocalizedDescriptionKey: @"Could not parse Master Password import data.", NSLocalizedDescriptionKey: strf( @"Could not parse Master Password import data:\n%@", @(file->error.message) ),
}]), @"While importing sites." ); }]), @"While importing sites." );
} }
if (file->info->format == MPMarshalFormatNone) { if (file->info->format == MPMarshalFormatNone) {
mpw_marshal_file_free( &file );
return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{ return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{
@"type" : @(MPMarshalErrorFormat), @"type" : @(MPMarshalErrorFormat),
NSLocalizedDescriptionKey: @"This is not a Master Password import file.", NSLocalizedDescriptionKey: @"This is not a Master Password import file.",
@ -591,7 +590,6 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted );
importMasterPassword = askImportPassword( @(file->info->fullName) ); importMasterPassword = askImportPassword( @(file->info->fullName) );
if (!importMasterPassword) { if (!importMasterPassword) {
inf( @"Import cancelled." ); inf( @"Import cancelled." );
mpw_marshal_file_free( &file );
return MPError( ([NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil]), @"" ); return MPError( ([NSError errorWithDomain:NSCocoaErrorDomain code:NSUserCancelledError userInfo:nil]), @"" );
} }
@ -600,13 +598,11 @@ PearlAssociatedObjectProperty( NSNumber*, StoreCorrupted, storeCorrupted );
caseInsensitiveCompare:@(file->info->keyID)] != NSOrderedSame); caseInsensitiveCompare:@(file->info->keyID)] != NSOrderedSame);
// Parse import data. // Parse import data.
MPMarshalledUser *importUser = mpw_marshal_auth( file, mpw_masterKeyProvider_str( importMasterPassword.UTF8String ) ); importUser = mpw_marshal_auth( file, mpw_masterKeyProvider_str( importMasterPassword.UTF8String ) );
@try {
if (!importUser || file->error.type != MPMarshalSuccess) if (!importUser || file->error.type != MPMarshalSuccess)
return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{ return MPError( ([NSError errorWithDomain:MPErrorDomain code:MPErrorMarshalCode userInfo:@{
@"type" : @(file->error.type), @"type" : @(file->error.type),
NSLocalizedDescriptionKey: @(file->error.message), NSLocalizedDescriptionKey: strf( @"Could not authenticate Master Password import:\n%@", @(file->error.message) ),
}]), @"While importing sites." ); }]), @"While importing sites." );
// Find an existing user to update. // Find an existing user to update.