#Tauri shutdown right away

92 messages · Page 1 of 1 (latest)

hard copper
#

Running tauri.exe has a phenomenon that turns off right away. However, if press enter and run it multiple times, it only runs. Does anyone know anything about this?

copper flicker
hard copper
hard copper
#

This has occurred since you added the settings.

#

pub fn create_db_pool() -> DbPool {
    let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
    let manager = ConnectionManager::<PgConnection>::new(&database_url);
    Pool::builder()
        .build(manager)
        .expect("Failed to create pool.")
} ```
#
    dotenv::dotenv().ok();
    
    // simple_logger를 초기화합니다. (오류 로그를 더 잘 볼 수 있게 합니다)
    simple_logger::init().unwrap();

    tauri::Builder::default()
        .manage(create_db_pool()) // DB 풀을 애플리케이션 상태로 관리합니다.
        .invoke_handler(tauri::generate_handler![
            load_json_data,
            update_image_data,
            get_real_image, // 필요한 모든 핸들러를 등록합니다.
        ])
        .setup(|app| {
            #[cfg(debug_assertions)] // 개발 중일 때만 개발자 도구를 엽니다.
            {
                if let Some(window) = app.get_window("main") {
                    window.open_devtools();
                }
            }
            Ok(())
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
} ```
copper flicker
copper flicker
hard copper
#

I don't understand this ridiculous phenomenon

copper flicker
hard copper
#

There's nothing special about the composition of the code..

copper flicker
# hard copper same issue..

I'm not sure but it might be a panic or an expectation that's crashing it then it's caches so it works after

#

Do you use the FS API in rust or the front-end side by any random chance?

hard copper
#

yes

#

i use fs

#

use std::fs::{self, File};

copper flicker
#

can you show me all of the code of that file

hard copper
#

so thank you resu..

copper flicker
#

np but can you take a screenshot cuz I'm on my phone

hard copper
#

screenshot all the code?

#

ok

copper flicker
#

ye please

hard copper
#

The whole thing is too much, so I only attach commands.rs and main.rs . Is there a problem here?

#

I'll sort it

#

commands.rs

#

field and dependencies, and dbPool

#

fn load_json_data

#

fn update_image_data

#

fn get_real_img

#

fn decode_base64_image_data

#

fn get_home_directory

#

The last corrections are fn 'get_real_img' and dbPool

#

main.rs

mental monolith
# hard copper

On Windows, running with start will create a new terminal. You want to bind your app to the current terminal so you see the output. To do that, you run the app directly without start like so: tauri.exe.

mental monolith
#

It's strange that you're not getting output. What command did you use to compile your app?

#

Can you also share your tauri.conf.json file? Mainly interested in anything inside the windows array.

hard copper
#

I tried 'npm run tauri build' and 'tauri build'

#

To be precise, this has happened since we added dataPool.

#

use diesel::r2d2::{self, ConnectionManager, Pool};

mental monolith
#

npm run tauri dev will give you output on Windows. npm run tauri build will suppress the output to prevent a terminal showing with the app.

#

It's probably a panic somewhere from unwrap() but it doesn't hurt to be sure where it's happening by getting output.

hard copper
#

npm run tauri dev is the same phenomenon

#

It's shut down right away, and it only takes a few times to execute

mental monolith
#

There should be an error shown in the console if it's closing because of a panic.

#

Can you add some println! in various places to see where it gets up to?

#

Do you have your code available online somewhere?

hard copper
#

It doesn't run at all, so even println!, which should be run first, doesn't run.

hard copper
#

No error logs appear at all.

mental monolith
hard copper
#

//#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] << now my setting

#

There is no error log when it is not running..

hard copper
#

just this log

tribal token
# hard copper

dumb idea: try moving it to a dir with no special charactors

mental monolith
#

If moving directories doesn't work, can you try println! between each part of the main()? The goal is to find out where the code stops, even if it's not producing an error.

hard copper
#
    // .env 파일에서 환경 변수들을 불러옵니다.
    dotenv::dotenv().ok();
    
    // DATABASE_URL 환경 변수에서 데이터베이스 연결 정보를 불러옵니다.
    let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");

    let manager = ConnectionManager::<PgConnection>::new(database_url);
    let pool = r2d2::Pool::builder()
        .build(manager)
        .expect("Failed to create pool.");
    
    // 연결을 시도하고, 실패할 경우 재시도합니다.
    loop {
        match pool.get() {
            Ok(_) => {
                println!("Successfully connected to the database.");
                break; // 연결 성공 시 루프를 빠져나온 후, 풀을 반환
            },
            Err(e) => {
                println!("Failed to connect to database: {}, will retry in 5 seconds", e);
                thread::sleep(Duration::from_secs(5)); // 5초 후에 다시 시도
            }
        }
    }
    
    pool
} ```
#

This code is a code that was modified to reconnect because it was suspected that the execution was shut down due to a db connection.

#

When running normally, it runs up to println! ("Successfully connected to the database") of the db connection, but if not, it runs up to println! ("Starting application...") on main.rs and shuts down.

mental monolith
#

That sounds like it would be failing on the .expect from Pool::builder(). I don't see any other code that would cause a complete exit of the program.

mental monolith
#

If you run it from the terminal with tauri.exe, you should get that last line of output. It's probably closing before it can print.

hard copper
#

oh right

#

Is there any element here that might cause tauri.exe to shut down?

#

There seems to be an error in this part

mental monolith
#

There are 2 .expect() inside the create_db_pool function which might cause it. Beyond that, this would be an exercise in debugging the r2d2 library.

hard copper
#

I changed it from expect to Err, but it's the same phenomenon.

hard copper
#

Problem identified.