pscand-cli: error when there are no scanners configured

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Id4e5a2ffc70efb10ba37c0b203a0ac166a6a6964
This commit is contained in:
raf 2026-02-19 01:03:28 +03:00
commit 5850f342a1
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
2 changed files with 39 additions and 12 deletions

View file

@ -42,12 +42,8 @@ interval_secs = 30 # Battery status changes slowly
enabled = true
interval_secs = 5
# Example: Disable a scanner
[scanners.system]
enabled = false
# Example: Custom scanner with extra parameters
[scanners.custom]
enabled = true
interval_secs = 60
extra = { custom_param = "value", threshold = 100 }
# [scanners.custom]
# enabled = true
# interval_secs = 60
# extra = { custom_param = "value", threshold = 100 }

View file

@ -27,7 +27,7 @@ enum Args {
#[derive(Parser, Debug)]
struct RunArgs {
#[arg(short, long, default_value = "/etc/pscand/pscand.toml")]
#[arg(short, long, default_value = "~/.config/pscand/pscand.toml")]
config: PathBuf,
#[arg(short, long)]
@ -179,7 +179,16 @@ async fn run_daemon(args: RunArgs) -> Result<(), Box<dyn std::error::Error>> {
let config = if args.config.exists() {
CoreConfig::load(&args.config)?
} else {
log::warn!("Config file not found, using defaults");
log::warn!("Config file not found at {:?}", args.config);
log::info!("Creating default config. Run with --config to specify a different path.");
// Create default config directory if it doesn't exist
if let Some(parent) = args.config.parent() {
if let Err(e) = std::fs::create_dir_all(parent) {
log::warn!("Failed to create config directory: {}", e);
}
}
CoreConfig::default()
};
@ -256,8 +265,18 @@ async fn run_daemon(args: RunArgs) -> Result<(), Box<dyn std::error::Error>> {
let scanners = load_scanners(&config, &logger).await?;
if scanners.is_empty() {
log::warn!("No scanners loaded!");
logger.log(LogLevel::Warn, "daemon", "no_scanners", "{}".to_string());
log::error!("No scanners loaded!");
log::error!("Please ensure:");
log::error!(" 1. Scanner plugins are installed in one of the configured directories");
log::error!(" 2. Scanner directories are correctly set in config file or PSCAND_SCANNER_DIRS env var");
log::error!(" 3. Scanners are not disabled in the configuration");
logger.log(
LogLevel::Error,
"daemon",
"no_scanners",
"No scanner plugins loaded".to_string(),
);
return Err("No scanners loaded. See error messages above.".into());
} else {
log::info!("Loaded {} scanners", scanners.len());
logger.log(
@ -423,8 +442,12 @@ async fn load_scanners(
) -> Result<Vec<LoadedScanner>, Box<dyn std::error::Error>> {
let mut loaded = Vec::new();
let mut missing_dirs = Vec::new();
for dir in &config.scanner_dirs {
if !dir.exists() {
missing_dirs.push(dir.clone());
log::warn!("Scanner directory does not exist: {:?}", dir);
continue;
}
@ -521,6 +544,14 @@ async fn load_scanners(
}
}
if !missing_dirs.is_empty() {
log::warn!("The following scanner directories do not exist:");
for dir in &missing_dirs {
log::warn!(" - {:?}", dir);
}
log::info!("Create these directories or update scanner_dirs in config");
}
Ok(loaded)
}