From a545f8db057d77c84c1bf47c78e91d018ba0b6ac Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Tue, 17 Dec 2024 05:38:28 -0800 Subject: [PATCH] PolicyBuilder: Do not CHECK fail on conflicting namespace setup PiperOrigin-RevId: 707058554 Change-Id: I8b5240e4abeca8e9d0003fc3a6e9264b40b17f30 --- sandboxed_api/sandbox2/policybuilder.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/sandboxed_api/sandbox2/policybuilder.h b/sandboxed_api/sandbox2/policybuilder.h index 0ac6a768..4950105d 100644 --- a/sandboxed_api/sandbox2/policybuilder.h +++ b/sandboxed_api/sandbox2/policybuilder.h @@ -717,7 +717,11 @@ class PolicyBuilder final { // This is a no-op. ABSL_DEPRECATED("Namespaces are enabled by default; no need to call this") PolicyBuilder& EnableNamespaces() { - CHECK(use_namespaces_) << "Namespaces cannot be both disabled and enabled"; + if (!use_namespaces_) { + SetError(absl::FailedPreconditionError( + "Namespaces cannot be both disabled and enabled")); + return *this; + } requires_namespaces_ = true; return *this; } @@ -727,11 +731,14 @@ class PolicyBuilder final { // Call in order to use Sandbox2 without namespaces. // This is not recommended. PolicyBuilder& DisableNamespaces() { - CHECK(!requires_namespaces_) - << "Namespaces cannot be both disabled and enabled. You're probably " - "using features that implicitly enable namespaces (SetHostname, " - "AddFile, AddDirectory, AddDataDependency, AddLibrariesForBinary " - "or similar)"; + if (requires_namespaces_) { + SetError(absl::FailedPreconditionError( + "Namespaces cannot be both disabled and enabled. You're probably " + "using features that implicitly enable namespaces (SetHostname, " + "AddFile, AddDirectory, AddDataDependency, AddLibrariesForBinary " + "or similar)")); + return *this; + } use_namespaces_ = false; return *this; }