question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When remote debugging is turned on, underlying error in promise rejection causes: NSError RCTJSONStringify: Invalid type in JSON write (NSError)

See original GitHub issue

Issue 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?): macOS

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
fungilationcommented, Feb 18, 2017

I’m still hitting a similar error:

RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL)

With NSURL in brackets instead.

I haven’t been hitting this error until I upgraded RN from 0.37 to 0.41.

1reaction
miklschmidtcommented, Mar 1, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found