Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$env.config now always holds a record with only valid values #7309

Merged
merged 8 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
into_config() muts a copy of the previous config
  • Loading branch information
webbedspace committed Dec 8, 2022
commit a2d7893e3cdd3859dc5e21c38c7ae73d4759cac5
8 changes: 5 additions & 3 deletions crates/nu-protocol/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ pub struct ExploreConfig {
}

impl Value {
pub fn into_config(self) -> Result<Config, ShellError> {
pub fn into_config(self, config: &Config) -> Result<Config, ShellError> {
let v = self.as_record();

let mut config = Config::default();

// Use the passed-in config as a basis for the changes.
// This means, among other things, that putting in various invalid values won't
// blow away existing changes for those config keys.
let mut config = config.clone();
let mut legacy_options_used = false;

if let Ok(v) = v {
Expand Down
2 changes: 1 addition & 1 deletion crates/nu-protocol/src/engine/engine_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl EngineState {
// NOTE: currently (Dec 2022) the subrecords of config.menus, config.keybindings and config.hooks
// are NOT reconstructed by config_to_nu_record(), but restored from self.config as-is.
// As such, invalid values may persist on them (as into_config() doesn't remove them.
if let Ok(config) = v.clone().into_config() {
if let Ok(config) = v.clone().into_config(&self.config) {
// Don't replace self.config unless into_config() succeeds.
// Note that into_config() produces Err in only very dire circumstances.
self.config = config;
Expand Down