From b0bd4be59a926898c1ee1e4377e7e4625c53d844 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sat, 28 Aug 2021 10:10:41 -0400 Subject: [PATCH] Config CLI: Handle missing config values correctly If the domain/group/key doesn't exist in the config, exit with non-zero status and don't print out anything. Previously the CLI would print a single empty line if the config value was not found with LibConfig. Now, we use the proper `Config::Client::the().read_string()` API which can return an `Optional` type indicating failure.` --- Userland/Utilities/config.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Userland/Utilities/config.cpp b/Userland/Utilities/config.cpp index 14e31a559f..880a06b46d 100644 --- a/Userland/Utilities/config.cpp +++ b/Userland/Utilities/config.cpp @@ -29,8 +29,9 @@ int main(int argc, char** argv) return 0; } - auto value = Config::read_string(domain, group, key); - outln("{}", value); - + auto value_or_error = Config::Client::the().read_string_value(domain, group, key); + if (!value_or_error.has_value()) + return 1; + outln("{}", value_or_error.value()); return 0; }