Giter Site home page Giter Site logo

Comments (32)

yaronlevi avatar yaronlevi commented on May 10, 2024 6

Managed to make it work (-:
I deleted main.m and appdelegate.{h,m} (not just commenting their content, although I think it didn't have any effect )

and did:
react-native unlink bugsnag-react-native
react-native link bugsnag-react-native

Thank you for your help, much appreciated!

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024 1

I pushed a sample project to the swift-sample-project branch of the repository. Can you try checking it out and seeing if it runs for you? If so, maybe we can determine what setting is different from your project and causing the build error.

Steps to generate:

  1. react-native init SturdyPants
  2. cd SturdyPants
  3. npm install bugsnag-react-native --save
  4. react-native link
  5. Open Xcode, replace main.m, AppDelegate.{h,m} with AppDelegate.swift and Bridging-Header.h
  6. Add Bugsnag to bridging header, use from AppDelegate

from bugsnag-react-native.

foxyblocks avatar foxyblocks commented on May 10, 2024

Hello @yaronlevi, the bugsnag-react-native library already includes the bugsnag cocoa library as a dependency. You should not be using cocoapods to add it separately for react native projects. If you follow the react native setup instructions and configure the library from javascript, it will automatically catch exceptions from both javascript and swift environments.

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

I tried this, but errors from native code would not seem to be channeled to Bugsnag. For example, I tried this lines in my AppDelegate.swift, in the end of didFinishLaunchingWithOptions:

let arr = [2];
let n = arr[3];
return true

And the error would not apperar in my Bugsnag console

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

@yaronlevi Once the react native bugsnag library is installed, you can continue to use Bugsnag.start() in your AppDelegate by importing "Bugsnag.h" in your bridging header. There is also a podspec you can add to your Podfile using something like:

pod 'Bugsnag', :path => '../node_modules/bugsnag-react-native'

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

The only xcode project I have in my workspace is BugsnagReactNative.xcodeproj,
so I tried to import #import <BugsnagReactNative/BugsnagReactNative.h> but it won't let me use BugsnagReactNative.start()

But it let me call:
BugsnagReactNative.init()
Is it a viable option?

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

The only xcode project I have in my workspace is BugsnagReactNative.xcodeproj,
so I tried to import #import <BugsnagReactNative/BugsnagReactNative.h> but it won't let me use BugsnagReactNative.start()

If you expand the BugsnagReactNative project in the Project pane of the sidebar, you’ll see that it contains a Libraries folder. Within libraries are its two dependencies, bugsnag-cocoa and KSCrash. These files reside in the bugsnag-react-native directory in vendor/cocoa. Its how it handles native exceptions under the hood. Instead of importing BugsnagReactNative.h, use Bugsnag.h, which is in the base library, and Bugsnag.start().

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

Ok, I am trying:
#import <BugsnagReactNative/Bugsnag.h>
#import <BugsnagReactNative/Bugsnag/Bugsnag.h>
#import <BugsnagReactNative/Libraries/Bugsnag/Bugsnag.h>

but for all of them I get file not found

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

Where did #import <BugsnagReactNative/Bugsnag.h> come from? Try:

#import "Bugsnag.h"

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

They all sit inside myapp-Briding-Header.h . (attached an image)

screen shot 2017-03-07 at 2 00 50

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

and also this is the project structure:
screen shot 2017-03-07 at 2 03 33

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

Alright. Let's take a step back to figure out what's going on here. If I understand correctly, you have:

  • successfully configured bugsnag-react-native using npm
  • are seeing JavaScript errors reported
  • are not seeing some native errors being reported

Is that much correct?

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

correct.
I have bugsnag-react-native 2.0.2 installed.
Bugs from the js land are reported ok.
But now I want to import Bugsnag to my swift's appDelegate.
(and make it so that all unhandled expcetions in native code get reported as well)

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

Did you see a crash, but no report was generated on your project dashboard on bugsnag.com?

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

yes....I tried putting:

let arr = [2];
let n = arr[3];

inside appDelegate's didFinishLaunchingWithOptions.
no error was reported.

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

Got it. I've tested that importing "Bugsnag.h" is working as expected from Objective-C, but there seems to be an issue with the umbrella header/module map when importing it from a bridging header for Swift. Investigating.

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

OK (and yes, I have changed my default react native project structure, so that instead of the regular generated AppDelegate.h and AppDelegate.m (which I've commented their entire content) I now have a AppDelegate.swift

(As you can see in the pictures I've uploaded)

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

What does the error message say when using #import "Bugsnag.h"? I initially got a message indicating that the umbrella header could not be found, but after cleaning the project a few times, it works as expected and reported errors successfully after initializing with Bugsnag.start(). Note that native crashes are not reported when a debugger is attached.

Test project

package.json

{
  "name": "MyProject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "bugsnag-react-native": "^2.1.0",
    "react": "15.4.2",
    "react-native": "0.42.0"
  },
  "devDependencies": {
    "babel-jest": "19.0.0",
    "babel-preset-react-native": "1.9.1",
    "jest": "19.0.2",
    "react-test-renderer": "15.4.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

MyProject-Bridging-Header.h

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "Bugsnag.h"

AppDelegate.swift

Uncomment the call to crashApp to cause a crash, re-comment to stop crashing on launch and send reports.

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?

  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Bugsnag.start(withApiKey: "YOUR-API-KEY-HERE")
    
    let jsCodeLocation = RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index.ios", fallbackResource: nil)
    let rootView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "FancyPants", initialProperties: nil, launchOptions: launchOptions)
    rootView?.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1)

    window = UIWindow(frame: UIScreen.main.bounds)
    let rootViewController = UIViewController()
    rootViewController.view = rootView
    window?.rootViewController = rootViewController
    window?.makeKeyAndVisible()

    // crashApp()

    return true
  }

  func crashApp() {
    let items = [2]
    let item = items[34]
    print("\(item) will never be printed")
  }
}

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

Ok, will check this and report you in couple of hours.

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

Ok I tried clean and build several times but I still get the same result
screen shot 2017-03-07 at 15 43 35

Any other things I should check regarding xcode project references etc?

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

What does the error message say exactly when using #import "Bugsnag.h"?

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

screen shot 2017-03-08 at 0 12 33

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

Great.. I am checking.
Nice. I've reproduced a working project as you described. Now comparing both projects to trace the differences.

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

Awesome!! 🎉

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

Sorry for opening the issue again. When I call:

Bugsnag.notifyError(NSError(domain:"com.example", code:408, userInfo:nil))

The error is being sent correctly to Bugsnag and I can see it in the dashboard. But when doing:

let arr = [2];
let n = arr[3];

I see not error being reported. I've tried it multiple times. (and also in the SturdyPants sample project).
Any clue to why this is happening?

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

Sure, if you look in the console, the error is being captured, but if you crash the app in the first moments it's open, there's not enough time to send the error report, as that happens in the background.

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

Actually it happens after the app is loaded, when I click a button:
screen shot 2017-03-08 at 19 03 22

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

I can see in the xcode console the error:
fatal error: Index out of range

But after that nothing about "crash reported" or KSCrashReports

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

Ok, everything is cool. The error is reported. But only after I restart the app.

from bugsnag-react-native.

kattrali avatar kattrali commented on May 10, 2024

Ah cool, makes sense. iOS is in an unstable state after an unhandled exception happens, so exceptions are only written to disk and sent on the next launch.

from bugsnag-react-native.

pvinis avatar pvinis commented on May 10, 2024

when you get the report, have you managed to get them symbolicated too? because i cant.

from bugsnag-react-native.

yaronlevi avatar yaronlevi commented on May 10, 2024

Actually I am dealing with this problem right now. Can't seem to get line numbers showing on errors in the dashboard.

from bugsnag-react-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.