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

refinery_cli: Escaped statements are printed #245

Open
no-miso opened this issue Sep 9, 2022 · 10 comments
Open

refinery_cli: Escaped statements are printed #245

no-miso opened this issue Sep 9, 2022 · 10 comments

Comments

@no-miso
Copy link

no-miso commented Sep 9, 2022

my development environment
・windows10
・vscode(powershell)

This is the contents of refinery.toml created by setup.

[main]
db_type = "Postgres"
db_host = "localhost\r"
db_port = "5432\r"
db_user = "root\r"
db_pass = "root\r"
db_name = "postgres\r"
trust_cert = false

The value is escaped for some reason, and migration fails as it is.
If I remove the escaping it works fine.

@jxs
Copy link
Member

jxs commented Sep 9, 2022

Hi, can you provide the output of the error?
Thanks

@no-miso
Copy link
Author

no-miso commented Sep 10, 2022

refinery_cli = "0.8.6"
rustc 1.62.0

Error: `could not connect to database`, `invalid connection string: invalid value for option `port``

Caused by:
    0: invalid connection string: invalid value for option `port`
    1: invalid value for option `port`

port number is correct.
I am using cargo install.

@jxs
Copy link
Member

jxs commented Sep 15, 2022

sorry, I don't have a windows machine near. Would you be able to debug what value is then being parsed as the port?

@jxs jxs added the bug Something isn't working label Sep 15, 2022
@no-miso
Copy link
Author

no-miso commented Sep 19, 2022

sorry i don't know how. Please let me know if you know.
I think that the escape character of db_host is in the way and I can not read after the port number.

@jxs
Copy link
Member

jxs commented Sep 21, 2022

no worries, are you running refinery via refinery_cli? If not Config impls Debug so you can dbg!() before passing it to Runner::run.

@no-miso
Copy link
Author

no-miso commented Sep 23, 2022

Could you please elaborate on the steps to do this?
I tried but I don't know how to debug the cli tool.

@jxs
Copy link
Member

jxs commented Nov 26, 2022

I meant in the code and before compiling refinery cli. You need to download rust clone the repo and cargo build -p refinery_cli

@jxs jxs removed the bug Something isn't working label Nov 26, 2022
@no-miso
Copy link
Author

no-miso commented Dec 27, 2022

I'm sorry to have kept you waiting.
Maybe solved.
The problem is that the input values passed to the config are trimmed in sqlite but not in the other database.

[refinery_cli\src\setup.rs:99] &config = Config {
    main: Main {
        db_type: Postgres,
        db_path: None,
        db_host: Some(
            "p\r",
        ),
        db_port: Some(
            "p\r",
        ),
        db_user: Some(
            "p\r",
        ),
        db_pass: Some(
            "p\r",
        ),
        db_name: Some(
            "p\r",
        ),
        trust_cert: false,
    },
}

Trim each input value before passing it to the config.

   refinery_cli\src\setup.rs

   // other...

    print!("Enter database host: ");
    io::stdout().flush()?;
    let mut db_host = String::new();
    io::stdin().read_line(&mut db_host)?;
    db_host.pop();
    // config = config.set_db_host(&db_host); 
    config = config.set_db_host(db_host.trim());

    // other...

print

[refinery_cli\src\setup.rs:99] &config = Config {
    main: Main {
        db_type: Postgres,
        db_path: None,
        db_host: Some(
            "p",
        ),
        db_port: Some(
            "p",
        ),
        db_user: Some(
            "p",
        ),
        db_pass: Some(
            "p",
        ),
        db_name: Some(
            "p",
        ),
        trust_cert: false,
    },
}

@jxs
Copy link
Member

jxs commented Dec 31, 2022

no worries :) But why are you passing carriage returns \r on the config file?

@no-miso
Copy link
Author

no-miso commented Jan 1, 2023

The previous post is the output when building the code changed as below and entering the prescribed information from the terminal with the setup command.

refinery_cli\src\setup.rs

fn get_config_from_input() -> Result<Config> {

    // ...other

    print!("Enter database name: ");
    io::stdout().flush()?;
    let mut db_name = String::new();
    io::stdin().read_line(&mut db_name)?;
    db_name.pop();
    config = config.set_db_name(&db_name);

    dbg!(&config);    //add
    Ok(config)
}

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

No branches or pull requests

2 participants