From 6804dc6ff62c477399183dc85d2ad387298aa49d Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 27 Apr 2026 15:05:16 +0200 Subject: GetEnvVariable: return std::optional (#1017) - `GetEnvVariable` now returns `std::optional` so callers can distinguish an unset variable from one set to an empty value. - Windows path uses `SetLastError(ERROR_SUCCESS)` + `ERROR_ENVVAR_NOT_FOUND` to detect "not found"; POSIX path returns `nullopt` when `getenv` returns `nullptr`. - All call sites migrated. Most use `.value_or("")` to preserve current empty-or-unset behavior. The diagnostic helpers in `zen-test/artifactprovider-tests.cpp` now report `` vs `` distinctly. - Added a check in the `ExpandEnvironmentVariables` test confirming `nullopt` for an unset variable; PATH/HOME lookups in that test use `REQUIRE(has_value())` so a missing var fails cleanly instead of throwing `bad_optional_access`. --- src/zen/authutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/zen/authutils.cpp') diff --git a/src/zen/authutils.cpp b/src/zen/authutils.cpp index a2af2b63e..f186a2b0b 100644 --- a/src/zen/authutils.cpp +++ b/src/zen/authutils.cpp @@ -338,7 +338,7 @@ AuthCommandLineOptions::ParseOptions(cxxopts::Options& Ops, auto GetEnvAccessToken = [](const std::string& AccessTokenEnv) -> std::string { if (!AccessTokenEnv.empty()) { - return GetEnvVariable(AccessTokenEnv); + return GetEnvVariable(AccessTokenEnv).value_or(""); } return {}; }; -- cgit v1.2.3