Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
cli: more explicit error message when rad node logs fail
Merged arnaud.mbp opened 1 year ago

If the rad node is spawned by systemd there won’t be any logs file to read and rad node logs command will fail with the standard error message from fs.

1 file changed +7 -3 3ad84420 0ecdc764
modified radicle-cli/src/commands/node/control.rs
@@ -3,7 +3,7 @@ use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader, Read, Seek, SeekFrom};
use std::{fs, io, path::Path, process, thread, time};

-
use anyhow::anyhow;
+
use anyhow::{anyhow, Context};
use localtime::LocalTime;

use radicle::node;
@@ -128,9 +128,13 @@ pub fn debug(node: &mut Node) -> anyhow::Result<()> {
}

pub fn logs(lines: usize, follow: Option<time::Duration>, profile: &Profile) -> anyhow::Result<()> {
-
    let logs = profile.home.node().join("node.log");
+
    let logs_path = profile.home.node().join("node.log");
+
    let mut file = File::open(logs_path.clone())
+
        .map(BufReader::new)
+
        .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()))?;

-
    let mut file = BufReader::new(File::open(logs)?);
    file.seek(SeekFrom::End(0))?;

    let mut tail = Vec::new();