Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Refactor initial database creation to avoid SQLITE_CANTOPEN exception #10796

Closed

Description

@friedbunny

We currently use the SQLITE_CANTOPEN exception as the cue to create our database:

} catch (mapbox::sqlite::Exception& ex) {
if (ex.code != mapbox::sqlite::Exception::Code::CANTOPEN && ex.code != mapbox::sqlite::Exception::Code::NOTADB) {
Log::Error(Event::Database, "Unexpected error connecting to database: %s", ex.what());
throw;
}
try {
if (ex.code == mapbox::sqlite::Exception::Code::NOTADB) {
removeExisting();
}
connect(mapbox::sqlite::ReadWrite | mapbox::sqlite::Create);
} catch (...) {
Log::Error(Event::Database, "Unexpected error creating database: %s", util::toString(std::current_exception()).c_str());
throw;
}

But iOS developers that have exception breakpoints enabled frequently interpret this as a crash, not realizing it’s recoverable. See #9761, #10264, #10789, #11479, #11863, etc.

Using exceptions for flow control is unusual in iOS development and seeing an apparent crash the first time a developer tries to integrate our SDK is a bad/discouraging experience that we should endeavour to prevent.

Refs #10031

/cc @kkaefer @jfirebaugh

Activity

  1. added
    Core
    on Dec 22, 2017
  2. friedbunny commented on Mar 19, 2018

    @friedbunny
    ContributorAuthor

    For searchability, here’s what an iOS developer will see in the console on the first run of an app:

    2018-03-19 13:23:08.879582-0400 Mapbox GL[936:453383] [INFO] {com.mapbox.mbgl.DefaultFileSour}[Database]: cannot open file at line 40840 of [2b0954060f] (Code 14)

    2018-03-19 13:23:08.879688-0400 Mapbox GL[936:453383] [INFO] {com.mapbox.mbgl.DefaultFileSour}[Database]: [2b0954060f]:40840: (0) open(/var/mobile/Containers/Data/Application/FABF6BB2-CC02-4F6D-BB7F-5468529C7713/Library/Application Support/com.mapbox.MapboxGL/.mapbox/cache.db) - Undefined error: 0 (Code 14)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Corerefactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions