Closed freezy7 closed 2 years ago
希望对这个方法中的string 取 range 做下防护
- (NSString *)getBucket:(NSDictionary *)info { NSString *scope = [info objectForKey:@"scope"]; if (!scope || [scope isKindOfClass:[NSNull class]]) { return @""; } // 判断scope是否是 NSString NSRange range = [scope rangeOfString:@":"]; if (range.location == NSNotFound) { return scope; } return [scope substringToIndex:range.location]; }
Fatal Exception: NSInvalidArgumentException 0 CoreFoundation 0x11898c __exceptionPreprocess 1 libobjc.A.dylib 0x59f8 objc_exception_throw 2 CoreFoundation 0x351c8 -[NSOrderedSet initWithSet:copyItems:] 3 CoreFoundation 0x11e1d4 ___forwarding___ 4 CoreFoundation 0x11fe6c _CF_forwarding_prep_0 5 xxx 0xcbbd2c -[QNUpToken getBucket:] + 44 (QNUpToken.m:44) 6 xxx 0xcbbbf0 -[QNUpToken init:token:] + 24 (QNUpToken.m:24) 7 xxx 0xcbbf50 +[QNUpToken parse:] + 66 (QNUpToken.m:66) 8 xxx 0xcba034 -[QNUploadManager putData:fileName:key:token:complete:option:] + 135 (QNUploadManager.m:135) 9 xxx 0xf13fc __49-[xxx uploadToQiniuWithResponse:]_block_invoke_2 + 105 (xxxxUploadImagePicker.m:105) 10 xxx 0xa3de70 __72+[xxx requestResultWithPath:httpMethod:parameters:completion:]_block_invoke + 214 (xxxDataService.m:214) 11 xxx 0xa40930 __94-[xxx dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:]_block_invoke + 285 (xxxHTTPSessionManager.m:285) 12 xxx 0x7f39b0 __72-[AFURLSessionManagerTaskDelegate URLSession:task:didCompleteWithError:]_block_invoke_2.102 + 248 (AFURLSessionManager.m:248) 13 libdispatch.dylib 0x5fa38 _dispatch_call_block_and_release 14 libdispatch.dylib 0x607d4 _dispatch_client_callout 15 libdispatch.dylib 0xde50 _dispatch_main_queue_callback_4CF$VARIANT$mp 16 CoreFoundation 0xaa32c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ 17 CoreFoundation 0xa5264 __CFRunLoopRun 18 CoreFoundation 0xa47c0 CFRunLoopRunSpecific 19 GraphicsServices 0xa79c GSEventRunModal 20 UIKitCore 0x8bcc38 UIApplicationMain 21 xxx 0x2efb48 main + 14 (main.m:14) 22 libdyld.dylib 0x18e0 start
@freezy7 这种错误产生的原因是 scope 配置错误,这样的错误对在开发阶段发现配置问题是有积极作用的。
那也应该咋debug时才出问题的啊,虽然是我们服务器对scope配置有误,但是这种问题在线上的确影响了我们,造成了大量的crash,希望对release环境还是要进行防护的
希望对这个方法中的string 取 range 做下防护