DJBen / Graviton

Real-time night sky rendering and planetarium in Swift 4 with native SceneKit and Metal.
GNU General Public License v3.0
60 stars 13 forks source link

App is crashing on Launch #163

Closed Danny-SS closed 1 year ago

Danny-SS commented 6 years ago

I downloaded, configured Carthage and built the app on an iOS 12 device.

The app launches both in Simulator and physical phone. I am the crash is happening when getting the initial data from Horizons.

Relavant Code

in Horizons.swift

func fetchOnlineRawDataExponentialBackoff(queries: [HorizonsQuery], complete: @escaping ([Int: String], [Error]?) -> Void) 

.
.
.
let nsError = error as NSError?
            if let e = nsError {
                if !retry(url: e.userInfo[NSURLErrorFailingURLErrorKey] as! URL) {
                    errors.append(e)
                }
            } else if let d = data {
                let httpResponse = response as! HTTPURLResponse
                let url = httpResponse.url!
                let utf8String = String(data: d, encoding: .utf8)!
                switch ResponseValidator.default.parse(content: utf8String) {
                case .busy:
                    logger.verbose("busy: \(url), retrying")
                    let retried = retry(url: url)
                    if retried == false {
                        // retries run out
                        logger.verbose("stop retrying: \(url)")
                    }
                default:
                    rawData[url.naifId!] = utf8String
                    logger.verbose("complete: \(url) - \(d)")
                }
            } else {
                logger.verbose("reponse has no data: \(String(describing: response))")
            }

.
.
.

The error is in the default part of the switch statement.

rawData[url.naifId!] = utf8String

The url does not have naifId (thread 7: Fatal error: Unexpectedly found nil while unwrapping an Optional value).

Debugging, the ur in the response is : _url NSURL "https://ssd.jpl.nasa.gov/?horizons" 0x000060000184e980

Checking I did step through the code and see the URLRequest, well, dataTask and can see the full URL with parameters being sent for each planet.

e.g. the first dataTask URL is:

http://ssd.jpl.nasa.gov/horizons_batch.cgi?CENTER='10'&COMMAND='199'&CSV_FORMAT='YES'&MAKE_EPHEM='YES'&START_TIME='2018-Jan-01%2000:00'&STEP_SIZE='1'&STOP_TIME='2018-Jan-01%2000:30'&TABLE_TYPE='Elements'&batch='1'

That URL gives me the query results we are expecting when I paste it into Safari

I am not sure if this is something with iOS 12.

I'll continue to explore.

DJBen commented 6 years ago

Hi Danny,

Thank you for digging so deep! The NASA horizon data format changed without warning and I made hard assumptions on the data format, causing the crash. I am pretty sure it’s irrelevant with iOS versions.

I will fix it at my best convenience.

Thank you again!

On Oct 3, 2018, at 9:40 AM, Danny-SS notifications@github.com wrote:

I downloaded, configured Carthage and built the app on an iOS 12 device.

The app launches both in Simulator and physical phone. I am the crash is happening when getting the initial data from Horizons.

Relavant Code

in Horizons.swift

func fetchOnlineRawDataExponentialBackoff(queries: [HorizonsQuery], complete: @escaping ([Int: String], [Error]?) -> Void)

.. . .. let nsError = error as NSError? if let e = nsError { if !retry(url: e.userInfo[NSURLErrorFailingURLErrorKey] as! URL) { errors.append(e) } } else if let d = data { let httpResponse = response as! HTTPURLResponse let url = httpResponse.url! let utf8String = String(data: d, encoding: .utf8)! switch ResponseValidator.default.parse(content: utf8String) { case .busy: logger.verbose("busy: (url), retrying") let retried = retry(url: url) if retried == false { // retries run out logger.verbose("stop retrying: (url)") } default: rawData[url.naifId!] = utf8String logger.verbose("complete: (url) - (d)") } } else { logger.verbose("reponse has no data: (String(describing: response))") }

.. . .. The error is in the default part of the switch statement.

rawData[url.naifId!] = utf8String

The url does not have naifId (thread 7: Fatal error: Unexpectedly found nil while unwrapping an Optional value).

Debugging, the ur in the response is : _url NSURL "https://ssd.jpl.nasa.gov/?horizons" 0x000060000184e980

Checking I did step through the code and see the URLRequest, well, dataTask and can see the full URL with parameters being sent for each planet.

e.g. the first dataTask URL is:

http://ssd.jpl.nasa.gov/horizons_batch.cgi?CENTER='10'&COMMAND='199'&CSV_FORMAT='YES'&MAKE_EPHEM='YES'&START_TIME='2018-Jan-01%2000:00'&STEP_SIZE='1'&STOP_TIME='2018-Jan-01%2000:30'&TABLE_TYPE='Elements'&batch='1'

That URL gives me the query results we are expecting when I paste it into Safari

I am not sure if this is something with iOS 12.

I'll continue to explore.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/DJBen/Graviton/issues/163, or mute the thread https://github.com/notifications/unsubscribe-auth/AB-3vato-nmVYjyt8novR3z7_4ZxEP0cks5uhOiDgaJpZM4XGbGS.

Danny-SS commented 6 years ago

Yeah. It seems that way. I did a reduction and think is, like you noted, a change in the NASA Horizon web interface. I confirmed this using the Rested App and sending my queries. If I send with a GET, I receive the correct response body.

DJBen commented 6 years ago

Hey it looks like my HTTP request gets redirected to the NASA Horizon's homepage... I fixed the crash at least.