Skip to content

Commit 5535e7e

Browse files
committed
don't panic if no asset is found
1 parent 64b7d16 commit 5535e7e

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

src/update.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,13 @@ pub fn check_update() -> Option<Release> {
6767
/// custom update function for use with bundles
6868
pub fn update(release: Release) -> Result<(), Box<dyn std::error::Error>> {
6969
let target_asset = if cfg!(target_os = "windows") {
70-
release
71-
.asset_for(self_update::get_target(), Some("exe"))
72-
.unwrap()
70+
release.asset_for(self_update::get_target(), Some("exe"))
7371
} else if cfg!(target_os = "linux") {
74-
release
75-
.asset_for(self_update::get_target(), Some("bin"))
76-
.unwrap()
72+
release.asset_for(self_update::get_target(), Some("bin"))
7773
} else {
78-
release.asset_for(self_update::get_target(), None).unwrap()
79-
};
74+
release.asset_for(self_update::get_target(), None)
75+
}
76+
.ok_or("No asset found")?;
8077
let tmp_archive_dir = tempfile::TempDir::new()?;
8178
let tmp_archive_path = tmp_archive_dir.path().join(&target_asset.name);
8279
let tmp_archive = fs::File::create(&tmp_archive_path)?;
@@ -87,24 +84,21 @@ pub fn update(release: Release) -> Result<(), Box<dyn std::error::Error>> {
8784

8885
self_update::Extract::from_source(&tmp_archive_path).extract_into(tmp_archive_dir.path())?;
8986
let new_exe = if cfg!(target_os = "windows") {
90-
let binary = env::current_exe()
91-
.unwrap()
87+
let binary = env::current_exe()?
9288
.file_name()
9389
.unwrap()
9490
.to_str()
9591
.unwrap()
9692
.to_string();
9793
tmp_archive_dir.path().join(binary)
9894
} else if cfg!(target_os = "macos") {
99-
let binary = env::current_exe()
100-
.unwrap()
95+
let binary = env::current_exe()?
10196
.file_name()
10297
.unwrap()
10398
.to_str()
10499
.unwrap()
105100
.to_string();
106-
let app_dir = env::current_exe()
107-
.unwrap()
101+
let app_dir = env::current_exe()?
108102
.parent()
109103
.unwrap()
110104
.parent()
@@ -131,8 +125,7 @@ pub fn update(release: Release) -> Result<(), Box<dyn std::error::Error>> {
131125
.path()
132126
.join(format!("{}/Contents/MacOS/{}", MACOS_APP_NAME, binary))
133127
} else if cfg!(target_os = "linux") {
134-
let binary = env::current_exe()
135-
.unwrap()
128+
let binary = env::current_exe()?
136129
.file_name()
137130
.unwrap()
138131
.to_str()

0 commit comments

Comments
 (0)