tursodatabase / tursodatabase/libsql
`libsql::Builder` panics if given invalid remote db url
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 17.2k
- Forks
- 531
- Avg merge
- 1h 12m
- Merged PRs (30d)
- 1
Description
Builder::new_remote_replica build panics if supplied with an invalid url.
When trying to build an embedded replica of a db with a malformed db url, the build() method just panics and crashes the thread. In my case, I was taking an un-sanitized db name from user as input (stupid of me, I know); create a new namespace in sqld and initialize the user db with that name and then create an embedded synced replica for that db. Surprisingly, sqld successfully creates a namespace even if the name would result in an invalid db_url (maybe I should create another issue for that) and when I try to create the embedded replica with that invalid url it just panics. For example, if the user input is db-name I create a sqld namespace for the same and the sqld instance is available at something like db-name.local which is then synced locally. This works fine as it should. But if the user input is something like db-name:3000, sqld creates a namespace for it even though the url to access this db would be db-name:3000.local which is invalid and embedded replica creation crashes.
The offending line seems to be this:
Not sure why there is a greedy unwrap here.
Expected: Gracefully error out with an appropriate error.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in libsql/src/local/database.rs around line 94 and trace Builder::new_remote_replica through build() for malformed remote database URLs. Confirm how the invalid URL reaches the panic, then make completion return an appropriate error instead; verify that the malformed-url case no longer crashes the thread.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100