When remote debugging is turned on, underlying error in promise rejection causes: NSError RCTJSONStringify: Invalid type in JSON write (NSError)
See original GitHub issueIssue Description
Some native modules such as NSFileManager
return an NSError
that has an underlying NSError
in the userInfo
dictionary. React native handles this fine out of the box, but when the remote debugger is turned on, the websocket message sender chokes on attempting to stringify the second NSError
into json.
I’m happy to help fix this, first time contributing so any pointers are welcome.
Steps to Reproduce / Code Snippets
I’ve posted a repository with the minimal reproduction case here https://github.com/superseriouscompany/react-native-error-repro
The steps are: first, turn on remote debugging. Then implement the following code:
// objc
RCT_EXPORT_METHOD(triggerError:(NSString *)foo
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
NSError *underlyingError = [NSError errorWithDomain:@"underlyingDomain" code:419 userInfo:nil];
NSError *err = [NSError errorWithDomain:@"domain" code:68 userInfo:@{@"NSUnderlyingError": underlyingError}];
reject(@"foo", @"bar", err);
}
// js
triggerError('anything').catch(err => { console.log(err)})
Expected Results
error is logged to console, execution continues.
Actual Results
### Additional Information - React Native version: 0.35.0 - Platform(s) (iOS, Android, or both?): iOS - Operating System (macOS, Linux, or Windows?): macOSIssue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:9 (3 by maintainers)
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m still hitting a similar error:
With
NSURL
in brackets instead.I haven’t been hitting this error until I upgraded RN from 0.37 to 0.41.
Okay, in my case it seems to be the AppTransportSecurityPolicy (or whatever it’s called) that wasn’t set to allow insecure connections. I had to hack RTCUtils.m:82 to print the JSON blob instead of the error. It seems like the userInfo object is the cause of the issue.