Skip to content

Commit fa4a3b1

Browse files
committed
notifications: log directly about non-fatal errors
1 parent ee51ed5 commit fa4a3b1

File tree

6 files changed

+10
-36
lines changed

6 files changed

+10
-36
lines changed

src/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use anyhow::{Context, Result, anyhow, bail};
88
use serde::Deserialize;
99
use thiserror::Error as ThisError;
1010
use tokio_stream::StreamExt;
11-
use tracing::trace;
11+
use tracing::{error, trace};
1212

1313
use crate::dist::AutoInstallMode;
1414
use crate::{
@@ -939,7 +939,7 @@ impl<'a> Cfg<'a> {
939939
.update_extra(&[], &[], profile, force_update, false)
940940
.await;
941941
if let Err(e) = &st {
942-
(self.notify_handler)(Notification::NonFatalError(e));
942+
error!("{e}");
943943
}
944944
(desc, st)
945945
});

src/dist/component/transaction.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ use std::fs::File;
1313
use std::path::{Path, PathBuf};
1414

1515
use anyhow::{Context, Result, anyhow};
16-
use tracing::info;
16+
use tracing::{error, info};
1717

1818
use crate::dist::prefix::InstallPrefix;
1919
use crate::dist::temp;
2020
use crate::errors::*;
21-
use crate::notifications::Notification;
2221
use crate::process::Process;
2322
use crate::utils;
2423

@@ -39,23 +38,16 @@ pub struct Transaction<'a> {
3938
prefix: InstallPrefix,
4039
changes: Vec<ChangedItem<'a>>,
4140
tmp_cx: &'a temp::Context,
42-
notify_handler: &'a dyn Fn(Notification<'_>),
4341
committed: bool,
4442
process: &'a Process,
4543
}
4644

4745
impl<'a> Transaction<'a> {
48-
pub fn new(
49-
prefix: InstallPrefix,
50-
tmp_cx: &'a temp::Context,
51-
notify_handler: &'a dyn Fn(Notification<'_>),
52-
process: &'a Process,
53-
) -> Self {
46+
pub fn new(prefix: InstallPrefix, tmp_cx: &'a temp::Context, process: &'a Process) -> Self {
5447
Transaction {
5548
prefix,
5649
changes: Vec::new(),
5750
tmp_cx,
58-
notify_handler,
5951
committed: false,
6052
process,
6153
}
@@ -179,9 +171,7 @@ impl Drop for Transaction<'_> {
179171
// Notification::NonFatalError,
180172
match item.roll_back(&self.prefix, self.process) {
181173
Ok(()) => {}
182-
Err(e) => {
183-
(self.notify_handler)(Notification::NonFatalError(&e));
184-
}
174+
Err(e) => error!("{e}"),
185175
}
186176
}
187177
}

src/dist/manifestation.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,7 @@ impl Manifestation {
216216
}
217217

218218
// Begin transaction
219-
let mut tx = Transaction::new(
220-
prefix.clone(),
221-
tmp_cx,
222-
download_cfg.notify_handler,
223-
download_cfg.process,
224-
);
219+
let mut tx = Transaction::new(prefix.clone(), tmp_cx, download_cfg.process);
225220

226221
// If the previous installation was from a v1 manifest we need
227222
// to uninstall it first.
@@ -329,7 +324,7 @@ impl Manifestation {
329324
) -> Result<()> {
330325
let prefix = self.installation.prefix();
331326

332-
let mut tx = Transaction::new(prefix.clone(), tmp_cx, notify_handler, process);
327+
let mut tx = Transaction::new(prefix.clone(), tmp_cx, process);
333328

334329
// Read configuration and delete it
335330
let rel_config_path = prefix.rel_manifest_file(CONFIG_FILE);
@@ -476,7 +471,7 @@ impl Manifestation {
476471
));
477472

478473
// Begin transaction
479-
let mut tx = Transaction::new(prefix, tmp_cx, notify_handler, process);
474+
let mut tx = Transaction::new(prefix, tmp_cx, process);
480475

481476
// Uninstall components
482477
let components = self.installation.list()?;

src/notifications.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub enum Notification<'a> {
2020
FileAlreadyDownloaded,
2121
CachedFileChecksumFailed,
2222
ExtensionNotInstalled(&'a str),
23-
NonFatalError(&'a anyhow::Error),
2423
MissingInstalledComponent(&'a str),
2524
/// The URL of the download is passed as the last argument, to allow us to track concurrent downloads.
2625
DownloadingComponent(&'a str, &'a TargetTriple, Option<&'a TargetTriple>, &'a str),
@@ -108,7 +107,6 @@ impl Notification<'_> {
108107
| ComponentUnavailable(_, _)
109108
| ForcingUnavailableComponent(_)
110109
| StrayHash(_) => NotificationLevel::Warn,
111-
NonFatalError(_) => NotificationLevel::Error,
112110
SignatureInvalid(_) => NotificationLevel::Warn,
113111
SetDefaultBufferSize(_) => NotificationLevel::Trace,
114112
DownloadingFile(_, _)
@@ -163,7 +161,6 @@ impl Display for Notification<'_> {
163161
FileAlreadyDownloaded => write!(f, "reusing previously downloaded file"),
164162
CachedFileChecksumFailed => write!(f, "bad checksum for cached download"),
165163
ExtensionNotInstalled(c) => write!(f, "extension '{c}' was not installed"),
166-
NonFatalError(e) => write!(f, "{e}"),
167164
MissingInstalledComponent(c) => {
168165
write!(f, "during uninstall component {c} was not found")
169166
}

src/test/dist.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::dist::{
2222
prefix::InstallPrefix,
2323
temp,
2424
};
25-
use crate::notifications::Notification;
2625
use crate::process::TestProcess;
2726

2827
pub struct DistContext {
@@ -67,12 +66,7 @@ impl DistContext {
6766
}
6867

6968
pub fn transaction(&self) -> Transaction<'_> {
70-
Transaction::new(
71-
self.prefix.clone(),
72-
&self.cx,
73-
&|_: Notification<'_>| (),
74-
&self.tp.process,
75-
)
69+
Transaction::new(self.prefix.clone(), &self.cx, &self.tp.process)
7670
}
7771
}
7872

tests/suite/dist_install.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustup::dist::component::Components;
55
use rustup::dist::component::Transaction;
66
use rustup::dist::component::{DirectoryPackage, Package};
77
use rustup::dist::prefix::InstallPrefix;
8-
use rustup::notifications::Notification;
98
use rustup::test::{DistContext, MockComponentBuilder, MockFile, MockInstallerBuilder};
109
use rustup::utils;
1110

@@ -170,8 +169,7 @@ fn uninstall() {
170169
tx.commit();
171170

172171
// Now uninstall
173-
let notify = |_: Notification<'_>| ();
174-
let mut tx = Transaction::new(cx.prefix.clone(), &cx.cx, &notify, &cx.tp.process);
172+
let mut tx = Transaction::new(cx.prefix.clone(), &cx.cx, &cx.tp.process);
175173
for component in components.list().unwrap() {
176174
tx = component.uninstall(tx, &cx.tp.process).unwrap();
177175
}

0 commit comments

Comments
 (0)