fix: improve error handling in get_languages()

This commit is contained in:
Ariq Pradipa Santoso
2023-04-04 01:09:54 +07:00
parent 45ee8fbb23
commit b6a2e4dbc0

View File

@@ -27,7 +27,12 @@ pub async fn get_languages() -> std::collections::HashMap<String, String> {
for entry in lang_files {
let entry = entry.unwrap();
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) {
Ok(x) => x,