mirror of
https://github.com/ModernRelay/omnigraph.git
synced 2026-06-09 01:35:18 +02:00
fix(config): error when OMNIGRAPH_CONFIG names a missing file
An explicitly-set OMNIGRAPH_CONFIG pointing at a missing path was silently dropped (no global layer, confusing downstream 'graph not found'). Bail naming the file, so an explicitly-named global config is required like --config; the default ~/.omnigraph path stays optional.
This commit is contained in:
parent
d0a44cba23
commit
c7c82beafb
2 changed files with 33 additions and 0 deletions
|
|
@ -417,6 +417,26 @@ fn use_sets_active_graph_targeted_by_bare_commands() {
|
|||
assert!(parse_stdout_json(&output).is_object());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn explicit_omnigraph_config_pointing_at_missing_file_errors() {
|
||||
// A typo'd OMNIGRAPH_CONFIG must fail loudly naming the file, not silently
|
||||
// load no global layer.
|
||||
let empty_cwd = tempdir().unwrap();
|
||||
let missing = empty_cwd.path().join("does-not-exist.yaml");
|
||||
let output = output_failure(
|
||||
cli()
|
||||
.current_dir(empty_cwd.path())
|
||||
.env("OMNIGRAPH_CONFIG", &missing)
|
||||
.arg("config")
|
||||
.arg("view"),
|
||||
);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(
|
||||
stderr.contains("OMNIGRAPH_CONFIG") && stderr.contains("does-not-exist.yaml"),
|
||||
"missing OMNIGRAPH_CONFIG must error naming the file: {stderr}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schema_plan_json_reports_supported_additive_change() {
|
||||
let temp = tempdir().unwrap();
|
||||
|
|
|
|||
|
|
@ -1158,6 +1158,19 @@ pub struct LayeredConfig {
|
|||
pub fn load_layered_config(project_config_path: Option<&PathBuf>) -> Result<LayeredConfig> {
|
||||
let cwd = env::current_dir()?;
|
||||
let global = global_config_file();
|
||||
// An explicitly-named global file (via `OMNIGRAPH_CONFIG`) is *required*: a
|
||||
// typo must error loudly, not silently load no global layer. A missing
|
||||
// default-location file (`~/.omnigraph/config.yaml`) stays optional.
|
||||
if env::var_os("OMNIGRAPH_CONFIG").is_some() {
|
||||
if let Some(path) = &global {
|
||||
if !path.exists() {
|
||||
bail!(
|
||||
"OMNIGRAPH_CONFIG points at a missing file: {}",
|
||||
path.display()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
let active = active_context_file();
|
||||
load_layered_config_in(
|
||||
&cwd,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue