Skip to content

Commit a545f8d

Browse files
happyCoder92copybara-github
authored andcommitted
PolicyBuilder: Do not CHECK fail on conflicting namespace setup
PiperOrigin-RevId: 707058554 Change-Id: I8b5240e4abeca8e9d0003fc3a6e9264b40b17f30
1 parent fe32ef4 commit a545f8d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

sandboxed_api/sandbox2/policybuilder.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,11 @@ class PolicyBuilder final {
717717
// This is a no-op.
718718
ABSL_DEPRECATED("Namespaces are enabled by default; no need to call this")
719719
PolicyBuilder& EnableNamespaces() {
720-
CHECK(use_namespaces_) << "Namespaces cannot be both disabled and enabled";
720+
if (!use_namespaces_) {
721+
SetError(absl::FailedPreconditionError(
722+
"Namespaces cannot be both disabled and enabled"));
723+
return *this;
724+
}
721725
requires_namespaces_ = true;
722726
return *this;
723727
}
@@ -727,11 +731,14 @@ class PolicyBuilder final {
727731
// Call in order to use Sandbox2 without namespaces.
728732
// This is not recommended.
729733
PolicyBuilder& DisableNamespaces() {
730-
CHECK(!requires_namespaces_)
731-
<< "Namespaces cannot be both disabled and enabled. You're probably "
732-
"using features that implicitly enable namespaces (SetHostname, "
733-
"AddFile, AddDirectory, AddDataDependency, AddLibrariesForBinary "
734-
"or similar)";
734+
if (requires_namespaces_) {
735+
SetError(absl::FailedPreconditionError(
736+
"Namespaces cannot be both disabled and enabled. You're probably "
737+
"using features that implicitly enable namespaces (SetHostname, "
738+
"AddFile, AddDirectory, AddDataDependency, AddLibrariesForBinary "
739+
"or similar)"));
740+
return *this;
741+
}
735742
use_namespaces_ = false;
736743
return *this;
737744
}

0 commit comments

Comments
 (0)