Skip to content

Conversation

@THardy98
Copy link
Contributor

Previously, when override_env_vars was not provided, the code passed an empty hash (override_env_vars || {}) to the Rust bridge. This caused the core library to use that empty hash as the env var source instead of reading from the actual system environment.

The fix conditionally omits the argument when nil, allowing the Rust bridge to treat it as optional and fall back to std::env::var() for system environment variable lookups.

Why?

Bug fix

  1. How was this tested:
    Added test

Previously, when `override_env_vars` was not provided, the code passed
an empty hash (`override_env_vars || {}`) to the Rust bridge. This
caused the core library to use that empty hash as the env var source
instead of reading from the actual system environment.

The fix conditionally omits the argument when nil, allowing the Rust
bridge to treat it as optional and fall back to `std::env::var()`
for system environment variable lookups.
@THardy98 THardy98 requested a review from a team as a code owner December 29, 2025 14:40
)
path, data = EnvConfig._source_to_path_and_data(config_source)

raw_profile = Internal::Bridge::EnvConfig.load_client_connect_config(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you just leave the existing code and just remove || {}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially did this, I thought Rust's Option<HashMap> would allow for nil values from Ruby, but scan_args tries to convert nil to HashMap.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could just spread the optional arg: *([override_env_vars] unless override_env_vars.nil?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh nice - done

Copy link
Member

@cretz cretz Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not splat at this point. I think you should make every argument required from the Rust side. It's internal code, we should not add optional fields on ourselves. Can move to structs if needed since param list is growing large.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed from splatting to explicit conditional. Making the change Rust side is prudent but I'd prefer not to delay the fix.

end
end

def with_system_env_vars(env_vars)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add a decl to the .rbs:

  def with_system_env_vars: [T] (Hash[String, String] env_vars) { () -> T } -> T

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants