-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error handling for database path retrieval across Tauri compo…
…nents - Refactored `get_database_path` function to return a `Result<String, io::Error>` for better error management. - Updated calls to `get_database_path` in `get_chat_history`, `get_chat_history_by_session`, `get_chatgpt_response`, `get_session_id_list`, and `lib.rs` to handle potential errors gracefully. - Removed direct panics from database path retrieval and directory creation by incorporating proper error handling. - Ensured that the application can gracefully handle scenarios when the database path cannot be determined, improving overall robustness. This update enhances the reliability of database-related operations within the application.
- Loading branch information
1 parent
4461b17
commit 41e7e21
Showing
6 changed files
with
16 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
use dirs; | ||
use std::fs; | ||
use std::io; | ||
|
||
pub fn get_database_path() -> String { | ||
let mut db_path = dirs::home_dir().expect("Failed to get home directory"); | ||
pub fn get_database_path() -> Result<String, io::Error> { | ||
// ホームディレクトリの取得 | ||
let mut db_path = dirs::home_dir() | ||
.ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "Failed to get home directory"))?; | ||
db_path.push(".cuuri/chat.db"); | ||
|
||
// 親ディレクトリの作成 | ||
if let Some(parent) = db_path.parent() { | ||
fs::create_dir_all(parent).expect("Failed to create directories for database file"); | ||
fs::create_dir_all(parent)?; | ||
} | ||
|
||
// データベースURLの生成 | ||
let database_url = format!("sqlite://{}", db_path.to_string_lossy()); | ||
|
||
return database_url; | ||
Ok(database_url) // 成功時はOkを返す | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters