schollz / find3-android-scanner

An android app that scans Bluetooth and WiFi for FIND3
https://www.internalpositioning.com/doc/tracking_your_phone.md
MIT License
124 stars 56 forks source link

Catch-all exceptions make for bad UX (need to ensure http:// on server) #3

Closed nh2 closed 6 years ago

nh2 commented 6 years ago

I followed the server-via-docker setup and entered as URL 192.168.1.1000:8005.

If I go to localhost:8005 on the server, and enter the family that I put into the phone, it says that family doesn't exist.

If I go manually to /view/dashboard/myfamily, it loads the page but says at the top. You need to add learning data first: group 'mygroup' does not exist, despite me having learned 5 locations already.

If in the app I press the link shown at the top, I get to FIND dashboard, it shows myfamily / mydevice, but the Location guesses just shows the logo with the orange square circling around.

In the adb logcat I see:

03-26 14:15:19.572 10394 10507 E Volley  : [524] NetworkDispatcher.processRequest: Unhandled exception java.lang.RuntimeException: Bad URL 192.168.1.100:8005/data
03-26 14:15:19.572 10394 10507 E Volley  : java.lang.RuntimeException: Bad URL 192.168.1.100:8005/data
03-26 14:15:19.572 10394 10507 E Volley  :  at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:171)
03-26 14:15:19.572 10394 10507 E Volley  :  at com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
03-26 14:15:19.572 10394 10507 E Volley  :  at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
03-26 14:15:19.572 10394 10507 E Volley  : Caused by: java.net.MalformedURLException: Protocol not found: 192.168.1.100:8005/data
03-26 14:15:19.572 10394 10507 E Volley  :  at java.net.URL.<init>(URL.java:176)
03-26 14:15:19.572 10394 10507 E Volley  :  at java.net.URL.<init>(URL.java:125)
03-26 14:15:19.572 10394 10507 E Volley  :  at com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:92)
03-26 14:15:19.572 10394 10507 E Volley  :  at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)
03-26 14:15:19.572 10394 10507 E Volley  :  ... 2 more
03-26 14:15:19.592 10394 10394 E ScanService: com.android.volley.VolleyError: java.lang.RuntimeException: Bad URL 192.168.1.100:8005/data
03-26 14:15:19.644 10394 10521 D ScanService: started wifi scan
03-26 14:15:19.644 10394 10521 D ScanService: started discovery
03-26 14:15:20.703 10394 10394 D ScanService: timer off, trying to send data

So there are 3 problems here:

They these locations use code like

                } catch (Exception e) {
                    Log.e(TAG, e.toString());
                }

Catching all exceptions is a well-known antipattern in Java; turning all exceptions into mere warnings and then continuing makes for bad UX because the program cannot work that way.

I suspect that this error is triggering the code path where the exception is thrown here and this catch-all` catches it and the app continues despite error.

schollz commented 6 years ago

Leaving off the http is a common error sorry! It should be specified better.

The other try-catch statements are because I just wanted it to work and I've only been programming in Android for a month :)

nh2 commented 6 years ago

The other try-catch statements are because I just wanted it to work and I've only been programming in Android for a month :)

Fair enough :) but ignoring the exceptions won't make things work more, only less (the app will continue in an incorrect state, and users won't know something is wrong).

I recommend you dont catch the exceptions. Then things will work equally much, the app will force-close properly, and users may even get a Report button where they can send you the stack trace.

schollz commented 6 years ago

That's a good point, I will go through those when I update it.