Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

[Error] Uh-oh. Database failed to load, we're in big trouble #188

Closed eliaslaouiti closed 5 years ago

eliaslaouiti commented 5 years ago

Hi Guys,

I've got an error on react-native : console.error: "[DB] Uh-oh. Database failed to load, we're in big trouble", {"line":154357,"column":32,"sourceURL":"http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false"}. (Complete stack trace : https://pastebin.com/mx4zwBjA)

I don't use expo, I do the react-native link (+ test to link manually) but nothing works 😢

Plateform : iOS 12.1, Iphone X on simulator, Node : 11.4.0 NPM: 6.5.0 react-native-cli: 2.0.1 react-native: 0.57.7 WatermelonDB : 0.9.0

Do you have any idea of how can I debug that ?

Thanks Elias

radex commented 5 years ago

@eliaslaouiti check Xcode console logs… you might have forgotten to recompile your app maybe?

eliaslaouiti commented 5 years ago

@radex I try to compile directly on XCode, and i've got this fatal error during the runtime :


2018-12-17 17:43:36.174360+0100 App[17234:550951] [] nw_connection_get_connected_socket [C4] Client called nw_connection_get_connected_socket on unconnected nw_connection
2018-12-17 17:43:36.747241+0100 App[17234:550951] [] nw_socket_handle_socket_event [C5.1:1] Socket SO_ERROR [61: Connection refused]
2018-12-17 17:43:36.748104+0100 App[17234:550958] [] nw_connection_get_connected_socket [C5] Client called nw_connection_get_connected_socket on unconnected nw_connection
2018-12-17 17:43:36.760 [info][tid:com.facebook.react.JavaScript] Running application "App" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2018-12-17 17:43:36.760183+0100 App[17234:550985] Running application "App" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF
2018-12-17 17:43:36.856 [info][tid:com.facebook.react.JavaScript] [DB] Setting up database with schema version 1
2018-12-17 17:43:36.856281+0100 App[17234:550985] [DB] Setting up database with schema version 1
2018-12-17 17:43:36.859735+0100 App[17234:550999] [logging] unrecognized token: ":"
2018-12-17 17:43:36.859862+0100 App[17234:550999] Error inserting batch: unrecognized token: ":"
Error Domain=FMDatabase Code=1 "unrecognized token: ":"" UserInfo={NSLocalizedDescription=unrecognized token: ":"}```
radex commented 5 years ago
2018-12-17 17:43:36.856281+0100 App[17234:550985] [DB] Setting up database with schema version 1
2018-12-17 17:43:36.859735+0100 App[17234:550999] [logging] unrecognized token: ":"
2018-12-17 17:43:36.859862+0100 App[17234:550999] Error inserting batch: unrecognized token: ":"
Error Domain=FMDatabase Code=1 "unrecognized token: ":"" UserInfo={NSLocalizedDescription=unrecognized token: ":"}```

Seems like there's a SQL error during setUp, which is weird. You can fiddle with adapters/sqlite/index → _init — follow the code paths and console.log the SQL that's sent to native code. Or you can set a breakpoint in Xcode on Database.swift → executeStatements and view SQL from debugger (po queries).

eliaslaouiti commented 5 years ago

Ok, i found the problem.

Maybe it will be good to display the sql query on error.

Thanks @radex :)

radex commented 5 years ago

@eliaslaouiti what was the problem? Is there a way Watermelon could catch the problem easier?

eliaslaouiti commented 5 years ago

On tableSchema, a put a ":" in the name value :
{ name: 'name:', type: 'string', isIndexed: true }, I had to display the sql query to show my error. Maybe, you can display the sql query in development mode if there is an error.

radex commented 5 years ago

@eliaslaouiti — right. That should be sanitized. Or at least, as you say, show a better error. I could point you to where to make the improvements if you want to contribute

vinaynarayankutty commented 5 years ago

I got the same problem. This is my schema, models, index and other files

indexjs model1 model2 navigationjs rootjs schema