fix: validate CSV before logger startup
Rust CI tiny-wb passed CI.
Gitea/tiny-wb/pipeline/head This commit looks good
Details
Rust CI tiny-wb passed CI.
Gitea/tiny-wb/pipeline/head This commit looks good
Details
This commit is contained in:
parent
96b4bfb13a
commit
8a0e7bd9b1
|
|
@ -84,7 +84,8 @@ boundary can grow into a tabbed collection without coupling CSV parsing or
|
|||
acquisition to Ratatui.
|
||||
|
||||
The terminal guard restores terminal modes on ordinary returns and unwinding.
|
||||
Configuration, logging and enumeration errors occur before terminal takeover.
|
||||
Configuration and direct-view CSV errors occur before logger initialization;
|
||||
logging and enumeration errors occur before terminal takeover.
|
||||
Process termination or release-mode panic abort cannot be recovered by a guard.
|
||||
|
||||
## Acquisition and protocol boundary
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ frequency-label convention explicitly after reviewing the
|
|||
[frequency assignment notes](usb-protocol.md#frequency-assignment).
|
||||
The direct renderer accepts this header or headerless files, ignores blank
|
||||
lines, and reports malformed, non-finite, empty, or decreasing-frequency data
|
||||
with its CSV line number before taking over the terminal.
|
||||
with its CSV line number before initializing logging or taking over the terminal.
|
||||
|
||||
### Logs
|
||||
|
||||
|
|
|
|||
44
src/main.rs
44
src/main.rs
|
|
@ -59,6 +59,25 @@ fn main() -> Result<(), AppError> {
|
|||
eprintln!("Cannot load {}: {error}", config_path.display());
|
||||
error
|
||||
})?;
|
||||
let loaded_plot = if let StartMode::View(path) = &mode {
|
||||
let file = File::open(path).map_err(|source| AppError::Csv {
|
||||
path: path.clone(),
|
||||
source,
|
||||
})?;
|
||||
let samples =
|
||||
tiny_wb::export::read_csv(BufReader::new(file)).map_err(|source| AppError::Csv {
|
||||
path: path.clone(),
|
||||
source,
|
||||
})?;
|
||||
Some(
|
||||
samples
|
||||
.into_iter()
|
||||
.map(|sample| (sample.frequency_mhz, sample.level_dbm))
|
||||
.collect(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let _logger = Logger::try_with_str(&config.logging.filter)?
|
||||
.log_to_file(FileSpec::default().directory(&config.logging.directory))
|
||||
.write_mode(WriteMode::BufferAndFlush)
|
||||
|
|
@ -74,26 +93,11 @@ fn main() -> Result<(), AppError> {
|
|||
};
|
||||
ui::App::new(ports, config, config_path)
|
||||
}
|
||||
StartMode::View(path) => {
|
||||
let file = File::open(&path).map_err(|source| AppError::Csv {
|
||||
path: path.clone(),
|
||||
source,
|
||||
})?;
|
||||
let samples = tiny_wb::export::read_csv(BufReader::new(file)).map_err(|source| {
|
||||
AppError::Csv {
|
||||
path: path.clone(),
|
||||
source,
|
||||
}
|
||||
})?;
|
||||
ui::App::viewer(
|
||||
config,
|
||||
path,
|
||||
samples
|
||||
.into_iter()
|
||||
.map(|sample| (sample.frequency_mhz, sample.level_dbm))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
StartMode::View(path) => ui::App::viewer(
|
||||
config,
|
||||
path,
|
||||
loaded_plot.expect("viewer data was loaded for view mode"),
|
||||
),
|
||||
StartMode::Help => unreachable!("help returned before configuration loading"),
|
||||
};
|
||||
let _session = TerminalSession;
|
||||
|
|
|
|||
|
|
@ -29,16 +29,20 @@ fn malformed_csv_exits_without_entering_the_terminal_or_enumerating_ports() {
|
|||
fs::create_dir_all(&directory).unwrap();
|
||||
let path = directory.join("broken.csv");
|
||||
fs::write(&path, "frequency_MHz,level_dBm\n240,not-a-level\n").unwrap();
|
||||
let config_path = directory.join("viewer.toml");
|
||||
fs::write(&config_path, "[logging]\ndirectory = 'not-a-directory'\n").unwrap();
|
||||
fs::write(directory.join("not-a-directory"), "ordinary file").unwrap();
|
||||
let result = Command::new(env!("CARGO_BIN_EXE_tiny-wb"))
|
||||
.current_dir(&directory)
|
||||
.env("TINY_WB_CONFIG", config_path)
|
||||
.arg("--view")
|
||||
.arg(&path)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(!result.status.success());
|
||||
let error = String::from_utf8_lossy(&result.stderr);
|
||||
assert!(error.contains("broken.csv"));
|
||||
assert!(error.contains("line 2"));
|
||||
assert!(error.contains("broken.csv"), "unexpected stderr: {error}");
|
||||
assert!(error.contains("line 2"), "unexpected stderr: {error}");
|
||||
assert!(!result.stdout.windows(2).any(|bytes| bytes == b"\x1b["));
|
||||
fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue