Skip to content

Commit

Permalink
PolicyBuilder: Do not CHECK fail on conflicting namespace setup
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 707058554
Change-Id: I8b5240e4abeca8e9d0003fc3a6e9264b40b17f30
  • Loading branch information
happyCoder92 authored and copybara-github committed Dec 17, 2024
1 parent fe32ef4 commit a545f8d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions sandboxed_api/sandbox2/policybuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit a545f8d

Please sign in to comment.