mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-16 17:14:36 +01:00
fix: improve error handling in get_languages()
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use crate::system_helpers::*;
|
use crate::system_helpers::*;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{ Path, PathBuf };
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_lang(window: tauri::Window, lang: String) -> String {
|
pub async fn get_lang(window: tauri::Window, lang: String) -> String {
|
||||||
@@ -27,7 +27,12 @@ pub async fn get_languages() -> std::collections::HashMap<String, String> {
|
|||||||
for entry in lang_files {
|
for entry in lang_files {
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
let filename = path.file_name().unwrap().to_str().unwrap();
|
let filename = path
|
||||||
|
.file_name()
|
||||||
|
.unwrap_or_else(|| panic!("Failed to get filename from path: {:?}", path))
|
||||||
|
.to_str()
|
||||||
|
.unwrap_or_else(|| panic!("Failed to convert filename to string: {:?}", path))
|
||||||
|
.to_string();
|
||||||
|
|
||||||
let content = match std::fs::read_to_string(&path) {
|
let content = match std::fs::read_to_string(&path) {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
|
|||||||
Reference in New Issue
Block a user