From 0ecdc764221fddf442c3e019098dc6f09697ef6c Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Tue, 5 Nov 2024 10:00:58 +0100 Subject: [PATCH] cli: Improve `rad node logs` error message 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. --- radicle-cli/src/commands/node/control.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/radicle-cli/src/commands/node/control.rs b/radicle-cli/src/commands/node/control.rs index 5e86a957..7a198ea8 100644 --- a/radicle-cli/src/commands/node/control.rs +++ b/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,17 @@ pub fn debug(node: &mut Node) -> anyhow::Result<()> { } pub fn logs(lines: usize, follow: Option, 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 log file at '{}'. Did you start the node with `rad node start`? \ + If the node was started through a process manager, check its logs instead.", + logs_path.display() + ) + })?; - let mut file = BufReader::new(File::open(logs)?); file.seek(SeekFrom::End(0))?; let mut tail = Vec::new();