Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions thrown in the native code #1117

Closed
compojoom opened this issue Jul 4, 2017 · 15 comments
Closed

Exceptions thrown in the native code #1117

compojoom opened this issue Jul 4, 2017 · 15 comments

Comments

@compojoom
Copy link

Hey guys,
Realm is throwing exceptions in the native ios code. As such my app execution halts and I can see the error in xCode. It's ok, since I can see the error and decide how to continue, but the problem is that whenever I hit "continue program execution" I end up at the same error.
I was clicking here like a monkey for at least 100 times and I always end up in the same exception. I have to stop the app and start it.

In this particular case I'm doing this:
database.write(() => {
database.create('Company', value);
})
I tried to save value twice both with the same id key and I run into else if (!try_update) {
throw std::logic_error(util::format("Attempting to create an object of type '%1' with an existing primary key value '%2'.",
object_schema.name, ctx.print(*primary_value)));
}

I saw that I need to pass a third argument true if I want realm to magically update my object instead of creating it again. But now I have to stop the app to retry. How are we supposed to deal with those exceptions?

@bmunkholm
Copy link
Contributor

As the exception explains, you can't create two objects with the same primary key but have to update it once it's been created the first time. Changing your code is the only way to handle that exception. Now sure what else you expect to be able to do?

@compojoom
Copy link
Author

Yea, that is clear. The Problem is that the only way to work again with the app is stoping it and re-launching it through xCode. Is there a way to continue with the execution? Can I catch those exceptions in the js code?

@fealebenpae
Copy link
Member

fealebenpae commented Jul 4, 2017

The native exceptions should be translated to JavaScript exceptions. This might be a bug or a regression. I'll add it to the backlog for further investigation.

@compojoom
Copy link
Author

@fealebenpae - on the subject of exceptions not being translated to Javascript exceptions: #1095 - it happens here as well.

@fealebenpae
Copy link
Member

Well, that’s not in Realm code, or called by Realm code.

@fealebenpae
Copy link
Member

The bug is likely that this particular exception in the create path is not rethrown in JS. There are lots of other C++ exceptions that do get rethrown in JS.

@compojoom
Copy link
Author

compojoom commented Jul 5, 2017 via email

@fealebenpae
Copy link
Member

Huh. You wouldn’t happen to have an exception breakpoint activated in the Xcode Debug Navigator?

@compojoom
Copy link
Author

compojoom commented Jul 5, 2017 via email

@fealebenpae
Copy link
Member

Do you get the same problem if you create a new project?

@compojoom
Copy link
Author

This: #1095 is definitely happening on a new project( RN 0.45 and realm only)

But I couldn't recreate the exception throwing with create on a new project. The exceptions are properly shown in the simulator.
And on this project I also have this: #1049 in production mode. Despite the fact that I'm using 1.8.3.

Now go figure why this shit happens on one project, but not in the other... :(

@fealebenpae
Copy link
Member

if you can please send your projects to [email protected].

@fealebenpae
Copy link
Member

My hunch is that your Xcode project decided to break on every exception thrown, even if it is later caught and rethrown in JavaScript.

@fealebenpae
Copy link
Member

I hope #1122 solved #1049 for you, and I've added #1095 to our backlog. Please feel free to close the current issue if you can't reproduce the exception throwing problem.

@compojoom
Copy link
Author

@fealebenpae - it doesn't brake on RN exceptions? Just on RealmJS exceptions.
I double checked the exceptions screen - I have no breakpoints whatsoever.
this thing is driving me crazy as for each error I make in a query I have to build the project again... But I can't figure out why the ... it does what it does...

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants