Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
Rename reader -> file and improve error message
✗ CI failure Arnaud Bailly committed 1 year ago
commit f9512443edd8714398b9a25eb68dd9ab339745b9
parent 703d3c40241cc136cd90e4f67c016e1e5bf4ec0e
1 passed 1 failed (2 total) View logs
1 file changed +10 -8
modified radicle-cli/src/commands/node/control.rs
@@ -129,19 +129,21 @@ pub fn debug(node: &mut Node) -> anyhow::Result<()> {

pub fn logs(lines: usize, follow: Option<time::Duration>, profile: &Profile) -> anyhow::Result<()> {
    let logs_path = profile.home.node().join("node.log");
-
    let mut reader = File::open(logs_path.clone())
+
    let mut file = File::open(logs_path.clone())
        .map(BufReader::new)
-
        .with_context(|| format!("Failed to open logs from {}. If radicle node is run with systemd, check systemd logs.", logs_path.display()))?;
+
        .with_context(|| format!("Failed to read logs from file {}. Did you start
+
the node with 'rad node start'? If radicle node is run through a process manager,
+
check out logs using the manager's tool.", logs_path.display()))?;

-
    reader.seek(SeekFrom::End(0))?;
+
    file.seek(SeekFrom::End(0))?;

    let mut tail = Vec::new();
    let mut nlines = 0;

-
    for i in (1..=reader.stream_position()?).rev() {
+
    for i in (1..=file.stream_position()?).rev() {
        let mut buf = [0; 1];
-
        reader.seek(SeekFrom::Start(i - 1))?;
-
        reader.read_exact(&mut buf)?;
+
        file.seek(SeekFrom::Start(i - 1))?;
+
        file.read_exact(&mut buf)?;

        if buf[0] == b'\n' {
            nlines += 1;
@@ -156,13 +158,13 @@ pub fn logs(lines: usize, follow: Option<time::Duration>, profile: &Profile) ->
    print!("{}", term::format::dim(String::from_utf8_lossy(&tail)));

    if let Some(timeout) = follow {
-
        reader.seek(SeekFrom::End(0))?;
+
        file.seek(SeekFrom::End(0))?;

        let start = time::Instant::now();

        while start.elapsed() < timeout {
            let mut line = String::new();
-
            let len = reader.read_line(&mut line)?;
+
            let len = file.read_line(&mut line)?;

            if len == 0 {
                thread::sleep(time::Duration::from_millis(250));