From 00c7d885cd21c317702af6749244f613f1cb039d Mon Sep 17 00:00:00 2001 From: tisfeng Date: Sat, 23 Dec 2023 09:41:26 +0800 Subject: [PATCH] fix: openai delta[@"content"] may be NSNull, cause crash --- Easydict/Feature/Service/OpenAI/EZOpenAIService.m | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Easydict/Feature/Service/OpenAI/EZOpenAIService.m b/Easydict/Feature/Service/OpenAI/EZOpenAIService.m index 511739a8c..01dfca1f2 100644 --- a/Easydict/Feature/Service/OpenAI/EZOpenAIService.m +++ b/Easydict/Feature/Service/OpenAI/EZOpenAIService.m @@ -553,12 +553,23 @@ - (NSString *)parseContentFromStreamData:(NSData *)data if (delta) { if (delta[@"content"]) { NSString *content = delta[@"content"]; -// NSLog(@"delta content: %@", content); - [mutableString appendString:content]; + // NSLog(@"delta content: %@", content); + + /** + SIGABRT: -[NSNull length]: unrecognized selector sent to instance 0x1dff03ce0 + + -[__NSCFString appendString:] + -[EZOpenAIService parseContentFromStreamData:lastData:error:isFinished:] EZOpenAIService.m:536 + */ + if ([content isKindOfClass:NSString.class]) { + [mutableString appendString:content]; + } } // finish_reason is string or null NSString *finishReason = choice[@"finish_reason"]; + + // Fix: SIGABRT: -[NSNull length]: unrecognized selector sent to instance 0x1dff03ce0 if ([finishReason isKindOfClass:NSString.class] && finishReason.length) { NSLog(@"finish reason: %@", finishReason);