question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IllegalArgumentException: File contains a path separator - Cannot create sqldelight file on ios application group directory

See original GitHub issue

I’m trying to create the sqlite file on iOS in the application group directory so it can be shared between the main app and the today notification center widget. I’ve created sqlite files and shared it successfully this way in the past, just not using sqldelight.

let url = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.identifier")!
let file = url.path + "/" + Schema.FILE_NAME

val dbConfig = DatabaseConfiguration(
                name = file,
                version = Schema.version,
                foreignKeyConstraints = true,
                create = { connection ->
                    wrapConnection(connection) { Schema.create(it) }
                },
                upgrade = { connection, oldVersion, newVersion ->
                    wrapConnection(connection) { Schema.migrate(it, oldVersion, newVersion) }
                }
        )

        return NativeSqliteDriver(
                dbConfig)

Runtime Environment SQLDelight version: 1.3.0 Application OS: iOS

Describe the bug

Exception:

Uncaught Kotlin exception: kotlin.IllegalArgumentException: File
/Users/username/Library/Developer/CoreSimulator/Devices/63D82DB4-4A53-4931-906C-BB63480D651C/data/Containers/Shared/AppGroup/23F1DE03-88A2-4840-BB83-037915A442B9/db contains a path separator

It seems in DatabaseConfiguration there is a hard requirement that the sqlite file doesn’t contain path separators:

if (name.contains("/")) {
        throw IllegalArgumentException(
            "File $name contains a path separator"
        )
    }

Putting the sqlite file in the application group directory is a pretty common scenario to share data with extensions - is there any way to do this? Can this path check be removed? Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
mikezliucommented, Feb 16, 2022

Path should be

let path = PKPersistentContainer.defaultDirectoryURL()
1reaction
mikezliucommented, Feb 16, 2022
val dbConfig = DatabaseConfiguration(
                name = Schema.FILE_NAME,
                version = Schema.version,
                extendedConfig = DatabaseConfiguration.Extended(
                        foreignKeyConstraints = true,
                        basePath = path
                ),
Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.IllegalArgumentException: contains a path separator
The solution is: FileInputStream fis = new FileInputStream (new File(NAME_OF_FILE)); // 2nd line. The openFileInput method doesn't accept path separators.
Read more >
Android : java.lang.IllegalArgumentException File contains a ...
How to resolve java.lang.IllegalArgumentException: File /Dir/data.txt contains a path separator error.
Read more >
Home | KMPizza - Lena Stepanova - Android Developer
Step 27: Add a local database to KMM Android and iOS app with SQLDelight ... Android and iOS apps. Go to the shared...
Read more >
GraphQL and Android FINAL Version - CommonsWare
clients: Web apps, Android apps, iOS apps, other servers, etc. ... If you have your GraphQL in a dedicated document file, you might...
Read more >
Kotlin Language Documentation 1.7.21
iOS app. Create a multiplatform app using Ktor and SQLDelight – tutorial ... Converting an existing Java file to Kotlin with J2K.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found