joshdholtz / Sentry-Android

[Deprecated] Use official "raven-java" library
https://github.com/getsentry/sentry-java
MIT License
180 stars 48 forks source link

Exception init Sentry #22

Closed felipeska closed 7 years ago

felipeska commented 9 years ago

init my sentry client:

 public void onCreate() {
     super.onCreate();
     Sentry.init(this, SentryLogger.BASE_URL,
     SentryLogger.DSN);
  }
Debugged  D  current handler class=com.android.internal.os.RuntimeInit$UncaughtHandler
                Sentry  D  Send all Cached Capture events!
            System.err  W  java.io.FileNotFoundException: /data/data/co.com.aranda.afls.onsite/files/unsent_requests: open failed: ENOENT (No such fil
                           e or directory)
                        W      at libcore.io.IoBridge.open(IoBridge.java:456)
                        W      at java.io.FileInputStream.<init>(FileInputStream.java:76)
                        W      at android.app.ContextImpl.openFileInput(ContextImpl.java:955)
                        W      at android.content.ContextWrapper.openFileInput(ContextWrapper.java:175)
                        W      at com.joshdholtz.sentry.Sentry$InternalStorage.readObject(Sentry.java:438)
                        W      at com.joshdholtz.sentry.Sentry$InternalStorage.<init>(Sentry.java:394)
                        W      at com.joshdholtz.sentry.Sentry$InternalStorage.<init>(Sentry.java:380)
                        W      at com.joshdholtz.sentry.Sentry$InternalStorage$LazyHolder.<clinit>(Sentry.java:390)
                        W      at com.joshdholtz.sentry.Sentry$InternalStorage.getInstance(Sentry.java:386)
                        W      at com.joshdholtz.sentry.Sentry$InternalStorage.access$200(Sentry.java:380)
                        W      at com.joshdholtz.sentry.Sentry.sendAllCachedCapturedEvents(Sentry.java:141)
                        W      at com.joshdholtz.sentry.Sentry.setupUncaughtExceptionHandler(Sentry.java:109)
                        W      at com.joshdholtz.sentry.Sentry.init(Sentry.java:92)
                        W      at co.com.aranda.afls.onsite.common.context.FieldServiceApp.onCreate(FieldServiceApp.java:95)
                        W      at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
                        W      at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518)
                        W      at android.app.ActivityThread.access$1500(ActivityThread.java:144)
                        W      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
                        W      at android.os.Handler.dispatchMessage(Handler.java:102)
                        W      at android.os.Looper.loop(Looper.java:135)
                        W      at android.app.ActivityThread.main(ActivityThread.java:5221)
                        W      at java.lang.reflect.Method.invoke(Native Method)
                        W      at java.lang.reflect.Method.invoke(Method.java:372)
                        W      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
                        W      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
                        W  Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                        W      at libcore.io.Posix.open(Native Method)
                        W      at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
                        W      at libcore.io.IoBridge.open(IoBridge.java:442)
                        W      ... 24 more
                Sentry  D  Sending up 0 cached response(s)

anyone has a similar problem?

joshdholtz commented 9 years ago

@felipeska Are you trying to use the hosted Sentry at getsentry.com? Or your own instance?

felipeska commented 9 years ago

@joshdholtz own instance :sunny:

joshdholtz commented 9 years ago

@felipeska I have not personally tried that myself yet :grin: That is an odd stacktrace though. I can try and spin one up myself though next week. I sadly don't have time this week.

joshdholtz commented 9 years ago

@felipeska Can you paste an example of what you are setting for your BASE_URL and DSN? Doesn't need to be your actually one but just so I can see the pattern.

felipeska commented 9 years ago

yes:


  public static final String BASE_URL = "http://sentryafls.noip.me:9000";
  public static final String DSN = "http://314f0a13ad8d4d43b4e6a6feea7d5f3f:5a4fa23776b24a8f8d58b1459b8f9a59@sentryafls.noip.me:9000/2";
joshdholtz commented 9 years ago

Awesome, thanks! I try to squeeze in some time tonight to see what's up

felipeska commented 9 years ago

@joshdholtz Thanks!!! :metal:

joshdholtz commented 9 years ago

@felipeska Hey, just wanted to let you know that I am taking a look at this now! I had to make the move from Eclipse to Android Studio so took a bit to get everything going again :grimacing:

felipeska commented 9 years ago

@joshdholtz Thanks. Add: the onCreate belongs to a class that inherits from Application

joshdholtz commented 9 years ago

@felipeska I think I just sent a successful request to your Sentry instance :grin: Can you let me know when you get a chance? I think it said "Hey yo"

QuadFlask commented 9 years ago

+1 I got same Exception when init sentry.

joshdholtz commented 9 years ago

@QuadFlask I am not able to reproduce @felipeska's issue or the issue you are seeing :confused: Can you give send me example code that you are trying to use?

QuadFlask commented 9 years ago

@joshdholtz I just code like @felipeska did. In Application which I extends Application class, and init at the onCraete() method. Could you add code that check file is exist at Sentry class line 586?

spidfire commented 9 years ago

Same error here I only use `Sentry.init(this.getApplicationContext(), "https://xxxxxxxxx"); from getsentry

W/System.err(17327): java.io.FileNotFoundException: /data/data/com.example/files/unsent_requests: open failed: ENOENT (No such file or directory)
W/System.err(17327):    at libcore.io.IoBridge.open(IoBridge.java:456)
W/System.err(17327):    at java.io.FileInputStream.<init>(FileInputStream.java:76)
W/System.err(17327):    at android.app.ContextImpl.openFileInput(ContextImpl.java:961)
W/System.err(17327):    at android.content.ContextWrapper.openFileInput(ContextWrapper.java:176)
W/System.err(17327):    at com.example.Sentry$InternalStorage.readObject(Sentry.java:584)
W/System.err(17327):    at com.example.Sentry$InternalStorage.<init>(Sentry.java:540)
W/System.err(17327):    at com.example.Sentry$InternalStorage.<init>(Sentry.java:526)
W/System.err(17327):    at com.example.Sentry$InternalStorage$LazyHolder.<clinit>(Sentry.java:536)
W/System.err(17327):    at com.example.Sentry$InternalStorage.getInstance(Sentry.java:532)
W/System.err(17327):    at com.example.Sentry$InternalStorage.access$200(Sentry.java:526)
W/System.err(17327):    at com.example.Sentry.sendAllCachedCapturedEvents(Sentry.java:188)
W/System.err(17327):    at com.example.Sentry.setupUncaughtExceptionHandler(Sentry.java:156)
W/System.err(17327):    at com.example.Sentry.init(Sentry.java:119)
W/System.err(17327):    at com.example.Sentry.init(Sentry.java:107)
W/System.err(17327):    at com.example.ScalaTestActivity.onCreate(ScalaTestActivity.scala:154)
W/System.err(17327):    at android.app.Activity.performCreate(Activity.java:5990)
W/System.err(17327):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
W/System.err(17327):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
W/System.err(17327):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
W/System.err(17327):    at android.app.ActivityThread.access$800(ActivityThread.java:151)
W/System.err(17327):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
W/System.err(17327):    at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err(17327):    at android.os.Looper.loop(Looper.java:135)
W/System.err(17327):    at android.app.ActivityThread.main(ActivityThread.java:5254)
W/System.err(17327):    at java.lang.reflect.Method.invoke(Native Method)

I did include the lib into my own classes though

spidfire commented 9 years ago

I think it's debug output.

Maybe someone can encapsulate it with a check if the file exists?

maxim-yudin commented 9 years ago

Yeah, you're right. It occurs only first time after installing application at

private ArrayList readObject(Context context) { try { FileInputStream fis = context.openFileInput(FILE_NAME); ... } catch (FileNotFoundException e) { e.printStackTrace(); } return new ArrayList(); }

akramShokri commented 8 years ago

@joshdholtz
I am experiencing the exact same problem in my application (using sentry-android-1.2.2): 03-08 09:41:55.996 2394-2394/*** W/System.err: java.io.FileNotFoundException: /data/data/***/files/unsent_requests: open failed: ENOENT (No such file or directory) 03-08 09:41:55.998 2394-2394/*** W/System.err: at libcore.io.IoBridge.open(IoBridge.java:456) 03-08 09:41:55.998 2394-2394/*** W/System.err: at java.io.FileInputStream.<init>(FileInputStream.java:76) 03-08 09:41:55.999 2394-2394/*** W/System.err: at android.app.ContextImpl.openFileInput(ContextImpl.java:961) 03-08 09:41:55.999 2394-2394/*** W/System.err: at android.content.ContextWrapper.openFileInput(ContextWrapper.java:176) 03-08 09:41:55.999 2394-2394/*** W/System.err: at com.joshdholtz.sentry.Sentry$InternalStorage.readObject(Sentry.java:586) 03-08 09:41:55.999 2394-2394/*** W/System.err: at com.joshdholtz.sentry.Sentry$InternalStorage.<init>(Sentry.java:542) 03-08 09:41:55.999 2394-2394/*** W/System.err: at com.joshdholtz.sentry.Sentry$InternalStorage.<init>(Sentry.java:528) 03-08 09:41:55.999 2394-2394/*** W/System.err: at com.joshdholtz.sentry.Sentry$InternalStorage$LazyHolder.<clinit>(Sentry.java:538) 03-08 09:41:55.999 2394-2394/*** W/System.err: at com.joshdholtz.sentry.Sentry$InternalStorage.getInstance(Sentry.java:534) 03-08 09:41:55.999 2394-2394/*** W/System.err: at com.joshdholtz.sentry.Sentry$InternalStorage.access$200(Sentry.java:528) 03-08 09:41:55.999 2394-2394/*** W/System.err: at com.joshdholtz.sentry.Sentry.sendAllCachedCapturedEvents(Sentry.java:190) 03-08 09:41:55.999 2394-2394/*** W/System.err: at com.joshdholtz.sentry.Sentry.setupUncaughtExceptionHandler(Sentry.java:158) 03-08 09:41:55.999 2394-2394/*** W/System.err: at com.joshdholtz.sentry.Sentry.init(Sentry.java:121)

So far, in a few cases it prevents my application from working properly, but most of the time it works. Can you please explain what impact this error can have on functionality of your library (Like what portion of your lib may not work in case of this error)? Any chance that this issue being resolved soon?

saeedsq commented 8 years ago

+1 I faced the same exception with my own sentry instance.

amiraliakbari commented 8 years ago

+1 Same problem with local Sentry, and not just on the first run.

joshdholtz commented 8 years ago

I do have a local Sentry that I can spin up now so I will take a look this as soon as I can for you guys

amiraliakbari commented 8 years ago

@joshdholtz Thanks a lot.

I can't see how this issue is related to using local sentry instances (and may be unrelated), but the problem seems to be related to calling Sentry::InternalStorage::readObject before any call to Sentry::InternalStorage::writeObject. I think either this file is not created at all, or is not created in certain conditions.

Currently I am using this code before calling Sentry.init to mitigate the problem:

try {
    File unsetRequestsFile = new File(getFilesDir(), "unsent_requests");
    if (!unsetRequestsFile.exists()) {
        FileOutputStream fos = openFileOutput("unsent_requests", Context.MODE_PRIVATE);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(new ArrayList<Sentry.SentryEventRequest>());
        oos.close();
        fos.close();
    }
} catch (IOException e) {
    e.printStackTrace();
}

And would recommend this patch to the InternalStorage constructor:

private InternalStorage() {
    Context context = Sentry.getInstance().context;
    try {
        File unsetRequestsFile = new File(getFilesDir(), FILE_NAME);
        if (!unsetRequestsFile.exists()) {
            writeObject(context, new ArrayList<Sentry.SentryEventRequest>());
       }
    } catch (IOException e) {
        e.printStackTrace();
    }
    this.unsentRequests = this.readObject(context);
}
joshdholtz commented 8 years ago

@amiraliakbari Thanks for the recommend patch! I haven't gotten a chance yet to test it with a local installation of Sentry but I don't see how this is related to a local installation of Sentry either.

What kind of device / OS are you running this on where you are seeing this? Or does it just not matter the device?

amiraliakbari commented 8 years ago

I have seen it on multiple devices/Android versions. Also it seems to be independent of using local Sentry instance. I think resource management in InternalStorage class should be improved to solve this issue and possibly other related special cases.

Another recommended patch:

private ArrayList<SentryEventRequest> readObject(Context context) {
    try {
        FileInputStream fis = context.openFileInput(FILE_NAME);
        ObjectInputStream ois = new ObjectInputStream(fis);
        ArrayList<SentryEventRequest> requests = (ArrayList<SentryEventRequest>) ois.readObject();
        + ois,close(); 
        + fis,close();
        return requests;

To remove this warning:

E/StrictMode: A resource was acquired at attached stack trace but never released. 
              See java.io.Closeable for information on avoiding resource leaks.
joshdholtz commented 8 years ago

@amiraliakbari Good call on those closes :wink: I have no idea how those got missed :broken_heart:

joshdholtz commented 8 years ago

Alright everyone (who is having this issue), if you could try this release to see if its fixes it, that would be great :blush:

compile 'com.joshdholtz.sentry:sentry-android:1.3.0'

I still can't reproduce so I hope this works :heart:

joshdholtz commented 7 years ago

Closing this due to inactivity