Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert failing for NSParameterAssert([modelClass isSubclassOfClass:AWSMTLModel.class]); #3537

Closed
jfranckretrieve opened this issue Apr 19, 2021 · 2 comments
Labels
bug Something isn't working s3 Issues related to S3

Comments

@jfranckretrieve
Copy link

jfranckretrieve commented Apr 19, 2021

Describe the bug
I am seeing an assert fail in + (NSValueTransformer *)awsmtl_JSONDictionaryTransformerWithModelClass:(Class)modelClass

The assert is on NSParameterAssert([modelClass isSubclassOfClass:AWSMTLModel.class]); and the class being passed in AWSS3CompletedMultipartUpload which does appear to inherit from AWSMTLModel.

To Reproduce
Upload a large video file that will result in an AWSS3CompletedMultipartUpload being used.

Stack Trace

* thread #40, queue = 'com.apple.NSURLSession-delegate', stop reason = hit Objective-C exception
    frame #0: 0x00000001b0076c14 libobjc.A.dylib`objc_exception_throw
    frame #1: 0x000000019af63000 CoreFoundation`+[NSException raise:format:arguments:] + 100
    frame #2: 0x000000019c2f791c Foundation`-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 132
  * frame #3: 0x0000000100da4268 SiteSelectedLibraryApp`+[NSValueTransformer(self=NSValueTransformer, _cmd="awsmtl_JSONDictionaryTransformerWithModelClass:", modelClass=AWSS3CompletedMultipartUpload) awsmtl_JSONDictionaryTransformerWithModelClass:] at NSValueTransformer+AWSMTLPredefinedTransformerAdditions.m:51:2
    frame #4: 0x00000001024e26dc RTIBookKit`+[AWSS3CompleteMultipartUploadRequest multipartUploadJSONTransformer](self=AWSS3CompleteMultipartUploadRequest, _cmd="multipartUploadJSONTransformer") at AWSS3Model.m:560:12
    frame #5: 0x000000019b0628f4 CoreFoundation`__invoking___ + 148
    frame #6: 0x000000019af39df8 CoreFoundation`-[NSInvocation invoke] + 448
    frame #7: 0x000000010247385c RTIBookKit`-[AWSMTLJSONAdapter JSONTransformerForKey:](self=0x0000000282cc5e20, _cmd="JSONTransformerForKey:", key=@"multipartUpload") at AWSMTLJSONAdapter.m:281:3
    frame #8: 0x0000000102473260 RTIBookKit`__35-[AWSMTLJSONAdapter JSONDictionary]_block_invoke(.block_descriptor=0x000000016f7a4580, propertyKey=@"multipartUpload", value=0x0000000282e1c460, stop=NO) at AWSMTLJSONAdapter.m:245:37
    frame #9: 0x000000019afc3adc CoreFoundation`__NSDICTIONARY_IS_CALLING_OUT_TO_A_BLOCK__ + 24
    frame #10: 0x000000019af3a280 CoreFoundation`-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 208
    frame #11: 0x0000000102473148 RTIBookKit`-[AWSMTLJSONAdapter JSONDictionary](self=0x0000000282cc5e20, _cmd="JSONDictionary") at AWSMTLJSONAdapter.m:241:2
    frame #12: 0x00000001024713ec RTIBookKit`+[AWSMTLJSONAdapter JSONDictionaryFromModel:](self=AWSMTLJSONAdapter, _cmd="JSONDictionaryFromModel:", model=0x00000002808a8300) at AWSMTLJSONAdapter.m:77:17
    frame #13: 0x00000001025272d0 RTIBookKit`-[AWSS3 invokeRequest:HTTPMethod:URLString:targetPrefix:operationName:outputClass:](self=0x0000000282ccd5a0, _cmd="invokeRequest:HTTPMethod:URLString:targetPrefix:operationName:outputClass:", request=0x00000002808a8300, HTTPMethod=AWSHTTPMethodPOST, URLString=@"/{Bucket}/{Key+}", targetPrefix=@"", operationName=@"CompleteMultipartUpload", outputClass=AWSS3CompleteMultipartUploadOutput) at AWSS3Service.m:188:45
    frame #14: 0x00000001025279c0 RTIBookKit`-[AWSS3 completeMultipartUpload:](self=0x0000000282ccd5a0, _cmd="completeMultipartUpload:", request=0x00000002808a8300) at AWSS3Service.m:232:12
    frame #15: 0x0000000102539a74 RTIBookKit`__58-[AWSS3TransferManager multipartUpload:fileSize:cacheKey:]_block_invoke.299(.block_descriptor=0x000000028366aa40, task=0x0000000283668d00) at AWSS3TransferManager.m:445:16
    frame #16: 0x00000001024a8a60 RTIBookKit`__63-[AWSTask continueWithExecutor:successBlock:cancellationToken:]_block_invoke(.block_descriptor=0x0000000282351770, task=0x0000000283668d00) at AWSTask.m:398:20
    frame #17: 0x00000001024a8270 RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke(.block_descriptor=0x000000028366abc0) at AWSTask.m:331:21
    frame #18: 0x000000010245a7dc RTIBookKit`__30+[AWSExecutor defaultExecutor]_block_invoke_2(.block_descriptor=0x00000001028b4e50, block=0x00000001024a8204) at AWSExecutor.m:65:21
    frame #19: 0x000000010245b068 RTIBookKit`-[AWSExecutor execute:](self=0x0000000282e15ca0, _cmd="execute:", block=0x00000001024a8204) at AWSExecutor.m:131:5
    frame #20: 0x00000001024a85bc RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke.103(.block_descriptor=0x00000002823517a0) at AWSTask.m:363:17
    frame #21: 0x00000001024a7ca4 RTIBookKit`-[AWSTask runContinuations](self=0x0000000283668d00, _cmd="runContinuations") at AWSTask.m:307:13
    frame #22: 0x00000001024a75d0 RTIBookKit`-[AWSTask trySetResult:](self=0x0000000283668d00, _cmd="trySetResult:", result=0x0000000000000000) at AWSTask.m:247:9
    frame #23: 0x00000001024a94c8 RTIBookKit`-[AWSTaskCompletionSource setResult:](self=0x0000000282e161c0, _cmd="setResult:", result=0x0000000000000000) at AWSTaskCompletionSource.m:45:10
    frame #24: 0x00000001024a8560 RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke_2(.block_descriptor=0x0000000282291830, task=0x0000000283664d40) at AWSTask.m:340:25
    frame #25: 0x00000001024a8270 RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke(.block_descriptor=0x0000000283664cc0) at AWSTask.m:331:21
    frame #26: 0x000000010245a7dc RTIBookKit`__30+[AWSExecutor defaultExecutor]_block_invoke_2(.block_descriptor=0x00000001028b4e50, block=0x00000001024a8204) at AWSExecutor.m:65:21
    frame #27: 0x000000010245b068 RTIBookKit`-[AWSExecutor execute:](self=0x0000000282e15ca0, _cmd="execute:", block=0x00000001024a8204) at AWSExecutor.m:131:5
    frame #28: 0x00000001024a85bc RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke.103(.block_descriptor=0x00000002822affc0) at AWSTask.m:363:17
    frame #29: 0x00000001024a7ca4 RTIBookKit`-[AWSTask runContinuations](self=0x0000000283664d40, _cmd="runContinuations") at AWSTask.m:307:13
    frame #30: 0x00000001024a75d0 RTIBookKit`-[AWSTask trySetResult:](self=0x0000000283664d40, _cmd="trySetResult:", result=0x0000000000000000) at AWSTask.m:247:9
    frame #31: 0x00000001024a94c8 RTIBookKit`-[AWSTaskCompletionSource setResult:](self=0x0000000282e262d0, _cmd="setResult:", result=0x0000000000000000) at AWSTaskCompletionSource.m:45:10
    frame #32: 0x00000001024a8560 RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke_2(.block_descriptor=0x000000028235c330, task=0x0000000283987900) at AWSTask.m:340:25
    frame #33: 0x00000001024a8270 RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke(.block_descriptor=0x0000000283987a00) at AWSTask.m:331:21
    frame #34: 0x000000010245a7dc RTIBookKit`__30+[AWSExecutor defaultExecutor]_block_invoke_2(.block_descriptor=0x00000001028b4e50, block=0x00000001024a8204) at AWSExecutor.m:65:21
    frame #35: 0x000000010245b068 RTIBookKit`-[AWSExecutor execute:](self=0x0000000282e15ca0, _cmd="execute:", block=0x00000001024a8204) at AWSExecutor.m:131:5
    frame #36: 0x00000001024a85bc RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke.103(.block_descriptor=0x000000028235cb40) at AWSTask.m:363:17
    frame #37: 0x00000001024a7ca4 RTIBookKit`-[AWSTask runContinuations](self=0x0000000283987900, _cmd="runContinuations") at AWSTask.m:307:13
    frame #38: 0x00000001024a75d0 RTIBookKit`-[AWSTask trySetResult:](self=0x0000000283987900, _cmd="trySetResult:", result=0x0000000000000000) at AWSTask.m:247:9
    frame #39: 0x00000001024a94c8 RTIBookKit`-[AWSTaskCompletionSource setResult:](self=0x0000000282e31d20, _cmd="setResult:", result=0x0000000000000000) at AWSTaskCompletionSource.m:45:10
    frame #40: 0x00000001024a840c RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke(.block_descriptor=0x0000000283985580) at AWSTask.m:354:17
    frame #41: 0x000000010245a7dc RTIBookKit`__30+[AWSExecutor defaultExecutor]_block_invoke_2(.block_descriptor=0x00000001028b4e50, block=0x00000001024a8204) at AWSExecutor.m:65:21
    frame #42: 0x000000010245b068 RTIBookKit`-[AWSExecutor execute:](self=0x0000000282e15ca0, _cmd="execute:", block=0x00000001024a8204) at AWSExecutor.m:131:5
    frame #43: 0x00000001024a85bc RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke.103(.block_descriptor=0x000000028235c600) at AWSTask.m:363:17
    frame #44: 0x00000001024a7ca4 RTIBookKit`-[AWSTask runContinuations](self=0x0000000283987dc0, _cmd="runContinuations") at AWSTask.m:307:13
    frame #45: 0x00000001024a75d0 RTIBookKit`-[AWSTask trySetResult:](self=0x0000000283987dc0, _cmd="trySetResult:", result=0x0000000000000000) at AWSTask.m:247:9
    frame #46: 0x00000001024a94c8 RTIBookKit`-[AWSTaskCompletionSource setResult:](self=0x0000000282e31630, _cmd="setResult:", result=0x0000000000000000) at AWSTaskCompletionSource.m:45:10
    frame #47: 0x00000001024a840c RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke(.block_descriptor=0x0000000283987480) at AWSTask.m:354:17
    frame #48: 0x000000010245a7dc RTIBookKit`__30+[AWSExecutor defaultExecutor]_block_invoke_2(.block_descriptor=0x00000001028b4e50, block=0x00000001024a8204) at AWSExecutor.m:65:21
    frame #49: 0x000000010245b068 RTIBookKit`-[AWSExecutor execute:](self=0x0000000282e15ca0, _cmd="execute:", block=0x00000001024a8204) at AWSExecutor.m:131:5
    frame #50: 0x00000001024a85bc RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke.103(.block_descriptor=0x000000028235c300) at AWSTask.m:363:17
    frame #51: 0x00000001024a7ca4 RTIBookKit`-[AWSTask runContinuations](self=0x00000002839851c0, _cmd="runContinuations") at AWSTask.m:307:13
    frame #52: 0x00000001024a75d0 RTIBookKit`-[AWSTask trySetResult:](self=0x00000002839851c0, _cmd="trySetResult:", result=0x000000028367c480) at AWSTask.m:247:9
    frame #53: 0x00000001024a94c8 RTIBookKit`-[AWSTaskCompletionSource setResult:](self=0x0000000282e32620, _cmd="setResult:", result=0x000000028367c480) at AWSTaskCompletionSource.m:45:10
    frame #54: 0x00000001024d0cf0 RTIBookKit`__61-[AWSURLSessionManager URLSession:task:didCompleteWithError:]_block_invoke(.block_descriptor=0x000000028367e7c0, task=0x000000028367ea80) at AWSURLSessionManager.m:373:47
    frame #55: 0x00000001024a8a60 RTIBookKit`__63-[AWSTask continueWithExecutor:successBlock:cancellationToken:]_block_invoke(.block_descriptor=0x0000000282361680, task=0x000000028367ea80) at AWSTask.m:398:20
    frame #56: 0x00000001024a8270 RTIBookKit`__56-[AWSTask continueWithExecutor:block:cancellationToken:]_block_invoke(.block_descriptor=0x000000028367c6c0) at AWSTask.m:331:21
    frame #57: 0x000000010245a7dc RTIBookKit`__30+[AWSExecutor defaultExecutor]_block_invoke_2(.block_descriptor=0x00000001028b4e50, block=0x00000001024a8204) at AWSExecutor.m:65:21
    frame #58: 0x000000010245b068 RTIBookKit`-[AWSExecutor execute:](self=0x0000000282e15ca0, _cmd="execute:", block=0x00000001024a8204) at AWSExecutor.m:131:5
    frame #59: 0x00000001024a8144 RTIBookKit`-[AWSTask continueWithExecutor:block:cancellationToken:](self=0x000000028367ea80, _cmd="continueWithExecutor:block:cancellationToken:", executor=0x0000000282e15ca0, block=0x00000001024a89cc, cancellationToken=0x0000000000000000) at AWSTask.m:368:9
    frame #60: 0x00000001024a896c RTIBookKit`-[AWSTask continueWithExecutor:successBlock:cancellationToken:](self=0x000000028367ea80, _cmd="continueWithExecutor:successBlock:cancellationToken:", executor=0x0000000282e15ca0, block=0x00000001024cf080, cancellationToken=0x0000000000000000) at AWSTask.m:394:12
    frame #61: 0x00000001024a8b24 RTIBookKit`-[AWSTask continueWithSuccessBlock:](self=0x000000028367ea80, _cmd="continueWithSuccessBlock:", block=0x00000001024cf080) at AWSTask.m:404:12
    frame #62: 0x00000001024cef7c RTIBookKit`-[AWSURLSessionManager URLSession:task:didCompleteWithError:](self=0x0000000282cce300, _cmd="URLSession:task:didCompleteWithError:", session=0x0000000140e55470, sessionTask=0x000000013cf07ce0, error=0x0000000000000000) at AWSURLSessionManager.m:216:6
    frame #63: 0x000000019b8367cc CFNetwork`___lldb_unnamed_symbol8794$$CFNetwork + 676
    frame #64: 0x00000001017abbcc libdispatch.dylib`_dispatch_call_block_and_release + 32
    frame #65: 0x00000001017ad6c0 libdispatch.dylib`_dispatch_client_callout + 20
    frame #66: 0x00000001017b5354 libdispatch.dylib`_dispatch_lane_serial_drain + 736
    frame #67: 0x00000001017b60f4 libdispatch.dylib`_dispatch_lane_invoke + 500
    frame #68: 0x00000001017c2644 libdispatch.dylib`_dispatch_workloop_worker_thread + 1520
    frame #69: 0x00000001e6b09814 libsystem_pthread.dylib`_pthread_wqthread + 276

Code Snippet

- (void)uploadContentsOfURL:(RTIAttachmentPickerSelection * __nullable)attachment bookId:(NSInteger)bookId scope:(RTIMediaScopeType)scope progress:(RTI_API_UPLOAD_PROGRESS_CB)progress withSuccess:(RTI_API_MEDIA_ATTACHMENT_CB)successBlock withError:(AWSContinuationErrorBlock)errorBlock {
    NSString *fileUploadBucket = APP_DEFAULTS.fileUploadBucket;
    
    if (!fileUploadBucket) {
        if (errorBlock) {
            errorBlock([NSError errorWithDomain:@"Error"
                                           code:500
                                       userInfo:@{@"userMessage": @"Could not upload contents. Please log out and log in again."}]);
        }
                       
        return;
    }
    
    if (attachment == nil) {
        if (successBlock) {
            successBlock(nil, 0);
        }
        return;
    }
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cacheDirectory = [paths objectAtIndex:0];
    NSData *data = [[NSData alloc] initWithContentsOfURL:attachment.attachment.downloadUrl];

    // heic conversion
    UIImage *convertedImage = [[UIImage alloc] initWithData:data];

    if (convertedImage) {
        data = UIImageJPEGRepresentation(convertedImage, 1.0);
    }

    NSString *randomFilename = [NSString stringWithFormat:@"%lu-%f", (long)arc4random(), [[NSDate date] timeIntervalSince1970]];
    NSString *tempPath = [cacheDirectory stringByAppendingPathComponent:randomFilename];

    [[NSFileManager defaultManager] createFileAtPath:tempPath contents:data attributes:nil];

    AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
    AWSS3TransferManagerUploadRequest *uploadRequest = [[AWSS3TransferManagerUploadRequest alloc] init];

    uploadRequest.bucket = APP_DEFAULTS.fileUploadBucket;
    uploadRequest.key = [self s3FilenameForAttachment:attachment];
    uploadRequest.body = [NSURL fileURLWithPath:tempPath];
    uploadRequest.uploadProgress = ^(int64_t bytesSent, int64_t totalBytesSent, int64_t totalBytesExpectedToSend) {

        if (progress) {
            NSProgress *p = [NSProgress new];
            p.totalUnitCount = totalBytesExpectedToSend;
            p.completedUnitCount = totalBytesSent;

            progress(p);
        }
    };

    
    [[transferManager upload:uploadRequest] continueWithExecutor:[AWSExecutor defaultExecutor] withBlock:^id _Nullable(AWSTask * _Nonnull t) {
        [[NSFileManager defaultManager] removeItemAtPath:tempPath error:nil];

        if (t.error) {
            if (errorBlock) {
                if (t.error.code == AWSNetworkingErrorCancelled) {
                    NSDictionary *data = [[NSDictionary alloc] initWithObjectsAndKeys:@YES, @"didCancel", t.error, @"AWSError", nil];
                    
                    if (successBlock) {
                        successBlock([RTIApiResponse responseWithData:data], 0);
                    }
                    else  {
                        errorBlock(t.error);
                    }
                }
                else {
                    errorBlock(t.error);
                }
            }

            return nil;
        }
        
        BOOL audioOnly = attachment.attachment.type == RTIMediaTypeAudio;

        [self addMediaS3Tag:uploadRequest.key inBook:bookId scope:scope audioOnly:audioOnly cb:^(RTIApiResponse * _Nonnull response, NSError *error) {
            if (response.error) {
                if (errorBlock) {
                    errorBlock(response.error);
                }

                return;
            }

            NSDictionary *json = response.data;
            NSInteger attachmentId = [json[@"id"] intValue];

            if (successBlock) {
                successBlock(response, attachmentId);
            }
        }];

        return nil;
    }];
}

Environment(please complete the following information):

  • SDK Version: 2.7.4
  • Dependency Manager: Cocoapods
  • Xcode Version: 12.4

Device Information (please complete the following information):

  • Device: iphone 12 Pro
  • iOS Version: 14.4
@lawmicha lawmicha added bug Something isn't working pending-triage Issue is pending triage s3 Issues related to S3 labels Apr 22, 2021
@lawmicha lawmicha self-assigned this Aug 13, 2021
@lawmicha
Copy link
Member

Hi @jfranckretrieve we have since deprecated TransferManager. Our recommendation for S3 is through Amplify.Storage. we recommend migrating over to this as we're constantly making improvements to it

@lawmicha lawmicha removed the pending-triage Issue is pending triage label Aug 13, 2021
@lawmicha lawmicha removed their assignment Aug 13, 2021
@ukhan-amazon
Copy link

Closing due to recommendation to use Amplify.Storage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working s3 Issues related to S3
Projects
None yet
Development

No branches or pull requests

3 participants