Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Open SQLite File On Windows #66

Closed
KMastroluca opened this issue Oct 22, 2023 · 11 comments · Fixed by #67
Closed

Can't Open SQLite File On Windows #66

KMastroluca opened this issue Oct 22, 2023 · 11 comments · Fixed by #67

Comments

@KMastroluca
Copy link
Contributor

KMastroluca commented Oct 22, 2023

Whatever the same issue that was being caused by App tests on our build before, is now happening locally on my machine after I pulled your latest code.

Im getting an error related to the inability to open the SQLite3 file. When I check the directory that its in on Windows C:\Users\username\AppData\Local\CuTE\CuTE.db CuTE.db is showing up as a directory not a SQLite database file.


thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SqliteFailure(Error { code: CannotOpen, extended_code: 14 }, Some("unable to open database file: C:\\Users\\k.mastroluca-clark\\AppData\\Local\\CuTE\\CuTE.db"))', src\app.rs:72:36

This is happening on startup before anything happens, its blocking my ability to open the app at all.

@PThorpe92
Copy link
Owner

Ok I think I know the issue.. I had to do some hacky stuff to be able to pass the --db-path flag (which honestly, you should be able to create a file CuTE.db in your CWD and pass the flag to ./target/debug/CutTE_tui --db-path .

@KMastroluca
Copy link
Contributor Author

You have

    pub fn get_default_path() -> PathBuf {
        let dir = data_local_dir().expect("Failed to get data local directory,\nPlease specify a path at $CONFIG/CuTE/config.toml\nOr with the --db_path={path/to/CuTE.db}");
        let dir = dir.join("CuTE");
        dir.join("CuTE.db")
    }

then over here you do this

            // If it doesn't exist, create it
            if let Err(err) = std::fs::create_dir_all(&path) {
                std::fs::File::create(&path).expect("failed to create database");
                eprintln!("Failed to create CuTE directory: {}", err);
            } else {
                println!("CuTE directory created at {:?}", path);
            }

Create Dir All is creating CuTE.db as a folder and then you pass that exact same path to create a file with the same name at the same place for the SOLite3 db. I dont know for sure, but that seems like a windows nightmare.

@KMastroluca
Copy link
Contributor Author

If i delete the folder structure there I get this on cargo run

CuTE directory created at "C:\\Users\\k.mastroluca-clark\\AppData\\Local\\CuTE\\CuTE.db"
CuTE Database Error: SqliteFailure(Error { code: CannotOpen, extended_code: 14 }, Some("unable to open database file: C:\\Users\\k.mastroluca-clark\\AppData\\Local\\CuTE\\CuTE.db")) thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SqliteFailure(Error { code: CannotOpen, extended_code: 14 }, Some("unable to open database file: C:\\Users\\k.mastroluca-clark\\AppData\\Local\\CuTE\\CuTE.db"))', src\app.rs:72:36

@KMastroluca
Copy link
Contributor Author

KMastroluca commented Oct 22, 2023

Okay i was able to fix this by doing this

    pub fn get_default_path() -> PathBuf {
        let dir = data_local_dir().expect("Failed to get data local directory,\nPlease specify a path at $CONFIG/CuTE/config.toml\nOr with the --db_path={path/to/CuTE.db}");
        let dir = dir.join("CuTE");
        //dir.join("CuTE.db")
        dir
    }

and then

        let conn_result = Connection::open_with_flags(
            path.join("CuTE.db"),
            OpenFlags::SQLITE_OPEN_READ_WRITE
                | OpenFlags::SQLITE_OPEN_CREATE
                | OpenFlags::SQLITE_OPEN_URI
                | OpenFlags::SQLITE_OPEN_NO_MUTEX,
        );

        let conn;

        // We Need To Handle Some Errors Here Related To Opening SQLite3 Database Files
        match conn_result {
            Ok(connection) => {
                conn = connection;
            }
            Err(e) => {
                println!("CuTE Database Error: {:?}", e);
                return Err(e);
            }
        }

this correctly creates the db file like we want in the place you want it on windows.

However, this revealed another error related to trying to read a config file that doesnt exist. How are we doing that?

thread 'main' panicked at 'Failed to write config file: Os { code: 3, kind: NotFound, message: "The system cannot find the path specified." }', src\main.rs:81:45

@KMastroluca
Copy link
Contributor Author

Ideally we should have a default config file that gets created, probably in the same AppData / .config directory with default settings that make sense on all platforms.

@PThorpe92
Copy link
Owner

Well what is supposed to happen, is that it just has a default config struct.. and if it can't find a file in the dir, it should just create the default struct. unless someone runs cute --dump-config /path/to/config

@KMastroluca
Copy link
Contributor Author

Okay.

@PThorpe92
Copy link
Owner

that way it's not required and someone can just use the default config, but if they choose to --dump-config /path and then they can edit that as they choose. I guess in that case it might need a flag for --config-path, or maybe we check the CWD as well as the ~/.config/CuTE and ~/.local/share/CuTE dirs

I got the request body working
image

@KMastroluca
Copy link
Contributor Author

KMastroluca commented Oct 22, 2023

Okay well, for some reason im panicking here
specifically the last line writing the config file.

    if args.contains_id("dump-config") {
        let mut config_path: String = args
            .get_one::<String>("dump-config")
            .expect("Missing dump-config argument")
            .to_string();
        if !config_path.contains("config.toml") {
            config_path.push_str("/config.toml");
        }
        let config = CuTE_tui::Config::default();
        let config = toml::to_string_pretty(&config).expect("Failed to serialize config");
        std::fs::write(config_path, config).expect("Failed to write config file");
    }

just by executing cargo run with no arguments? Wtf.

Love clap tho.

@PThorpe92
Copy link
Owner

hmm that is weird af.. hold on i am fixing this request body then i'll fix that

@KMastroluca
Copy link
Contributor Author

K, then ill pr this smaller fix i made

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants