dbcli / litecli

CLI for SQLite Databases with auto-completion and syntax highlighting
https://litecli.com
BSD 3-Clause "New" or "Revised" License
2.12k stars 68 forks source link

Inconsistent behavior when path does not exist #44

Closed j-bennet closed 5 years ago

j-bennet commented 5 years ago

If I open litecli providing a non-existent file name, but the directory exists, litecli will create a new database:

--- ~ » litecli ~/nonexistent-file.sqlite                                                                                                                                                                                                                1 ↵
Version: 1.0.0
Mail: https://groups.google.com/forum/#!forum/litecli-users
Github: https://github.com/dbcli/litecli
/Users/irina/nonexistent-file.sqlite>

However, if the path does not exists, litecli will throw an error:

--- ~ » litecli ~/nonexistent/path.sqlite                                                                                                                                                                                                                1 ↵
unable to open database file

The error also does not say that "path does not exist". This is a bit misleading, because it makes one think the database is there, but it's corrupt.

I think litecli should try creating directories in path if they don't exist, and then create a new database. Then the behavior will be consistent between case 1 and case 2.

delgermurun commented 5 years ago

@j-bennet Good catch! I like the idea to make things consistent. Let's try to create directories if they don't exist.

Happy to receive a PR for it.

zmwangx commented 5 years ago

Just want to chime in: most *nix command line tools are happy to create nonexistent files (or new direct subdirectories, if creating a directory structure is the tool's goal), but balk at the idea of creating intermediate subdirectories, unless explicitly told to do so. litecli is designed to deal with a single file at a time, so I don't think it's in the business of creating directories.

As a reference point, when you give sqlite3 a non-existent path, it happily starts the shell; when you actually start making queries, it either creates the database file, or aborts with "unable to open database file" if the directory doesn't exist.

IMO it's okay for litecli to create the file immediately, but in the nonexistent directory case, a better error message saying so should be enough.

j-bennet commented 5 years ago

Good point. Perhaps this is too much responsibility for litecli to create directories.

This PR adds a more clear error message for this case:

https://github.com/dbcli/litecli/pull/46

delgermurun commented 5 years ago

Fixed with #46