Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@


class FeatureRequiresUpgradeError(Exception):
"""Raised when a feature requires enterprise upgrade."""
"""Raised when a feature requires the MemoryLayer Enterprise extensions."""

def __init__(self, feature: str):
self.feature = feature
super().__init__(f"Feature '{feature}' requires MemoryLayer Enterprise. Visit https://memorylayer.ai/enterprise to upgrade.")
super().__init__(f"Feature '{feature}' requires MemoryLayer Enterprise (open source, AGPL-3.0): https://github.com/scitrera/memorylayer-enterprise")


# Unified ontology. The compact knowledge-work application profile below is
Expand Down
2 changes: 1 addition & 1 deletion memorylayer-sdk-go/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func mapError(resp *Response, enterpriseFeature string) error {
return &PreconditionRequiredError{newError(detail(resp.Body, "Precondition required"), sc)}
case http.StatusNotImplemented: // 501
if enterpriseFeature != "" {
msg := enterpriseFeature + " requires MemoryLayer Enterprise. See https://memorylayer.ai for upgrade options."
msg := enterpriseFeature + " requires MemoryLayer Enterprise (open source, AGPL-3.0): https://github.com/scitrera/memorylayer-enterprise"
return &EnterpriseRequiredError{APIError: newError(msg, sc), Feature: enterpriseFeature}
}
return &NotFoundError{newError(detail(resp.Body, "Not implemented"), sc)}
Expand Down
14 changes: 14 additions & 0 deletions memorylayer-sdk-go/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ func TestTypedErrorsUnwrapToAPIError(t *testing.T) {
}
}

func TestEnterpriseRequiredErrorMessage(t *testing.T) {
err := mapError(&Response{StatusCode: http.StatusNotImplemented, Body: []byte(`{"detail":"nope"}`)}, "Dataset management")
var e *EnterpriseRequiredError
if !errors.As(err, &e) {
t.Fatalf("expected EnterpriseRequiredError, got %v", err)
}
if e.StatusCode != http.StatusNotImplemented || e.Feature != "Dataset management" {
t.Errorf("status=%d feature=%q", e.StatusCode, e.Feature)
}
if !strings.Contains(e.Message, "github.com/scitrera/memorylayer-enterprise") || strings.Contains(e.Message, "upgrade") {
t.Errorf("unexpected message %q", e.Message)
}
}

func TestForgetSendsHardParam(t *testing.T) {
var hard string
var method string
Expand Down
2 changes: 1 addition & 1 deletion memorylayer-sdk-python/src/memorylayer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ async def _request(

Raises:
AuthenticationError: Authentication failed (401)
EnterpriseRequiredError: Enterprise-only endpoint (404 + enterprise_feature)
EnterpriseRequiredError: Enterprise-only endpoint (501 + enterprise_feature)
NotFoundError: Resource not found (404)
ValidationError: Validation failed (422)
RateLimitError: Rate limit exceeded (429)
Expand Down
11 changes: 6 additions & 5 deletions memorylayer-sdk-python/src/memorylayer/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ def __init__(self, message: str = "Resource not found") -> None:


class EnterpriseRequiredError(MemoryLayerError):
"""Raised when an enterprise-only endpoint returns 404.
"""Raised when an Enterprise-only endpoint returns 501 (Not Implemented).

This indicates the server is running MemoryLayer OSS which does not
include the requested feature (e.g. document ingestion, page search).
This indicates the server does not provide the requested feature (for
example dataset management), typically because the MemoryLayer Enterprise
extensions are not installed.
"""

def __init__(
self,
feature: str = "This feature",
message: str | None = None,
) -> None:
msg = message or (f"{feature} requires MemoryLayer Enterprise. See https://memorylayer.ai for upgrade options.")
super().__init__(msg, status_code=404)
msg = message or (f"{feature} requires MemoryLayer Enterprise (open source, AGPL-3.0): https://github.com/scitrera/memorylayer-enterprise")
super().__init__(msg, status_code=501)
self.feature = feature


Expand Down
4 changes: 2 additions & 2 deletions memorylayer-sdk-python/src/memorylayer/sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ def _request(
path: API path
json: JSON body
params: Query parameters
enterprise_feature: If set, a 404 raises EnterpriseRequiredError
enterprise_feature: If set, a 501 raises EnterpriseRequiredError
instead of NotFoundError.

Returns:
Response JSON

Raises:
AuthenticationError: Authentication failed (401)
EnterpriseRequiredError: Enterprise-only endpoint (404 + enterprise_feature)
EnterpriseRequiredError: Enterprise-only endpoint (501 + enterprise_feature)
NotFoundError: Resource not found (404)
ValidationError: Validation failed (422)
RateLimitError: Rate limit exceeded (429)
Expand Down
5 changes: 4 additions & 1 deletion memorylayer-sdk-python/tests/test_phase2_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ async def test_entities_gated_501_raises_enterprise(client: MemoryLayerClient, b
return_value=Response(501, json={"detail": "Entity registry is not enabled"})
)
async with client:
with pytest.raises(EnterpriseRequiredError):
with pytest.raises(EnterpriseRequiredError) as excinfo:
await client.list_entities()
assert excinfo.value.status_code == 501
assert "github.com/scitrera/memorylayer-enterprise" in excinfo.value.message
assert "upgrade" not in excinfo.value.message


@pytest.mark.asyncio
Expand Down
11 changes: 6 additions & 5 deletions memorylayer-sdk-typescript/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ export class RateLimitError extends MemoryLayerError {
}

/**
* Raised when an enterprise-only endpoint returns 404.
* Indicates the server is running MemoryLayer OSS which does not
* include the requested feature (e.g. document ingestion, page search).
* Raised when an Enterprise-only endpoint returns 501 (Not Implemented).
* Indicates the server does not provide the requested feature (for example
* dataset management), typically because the MemoryLayer Enterprise
* extensions are not installed.
*/
export class EnterpriseRequiredError extends MemoryLayerError {
constructor(
Expand All @@ -52,8 +53,8 @@ export class EnterpriseRequiredError extends MemoryLayerError {
) {
super(
message ??
`${feature} requires MemoryLayer Enterprise. See https://memorylayer.ai for upgrade options.`,
404
`${feature} requires MemoryLayer Enterprise (open source, AGPL-3.0): https://github.com/scitrera/memorylayer-enterprise`,
501
);
this.name = "EnterpriseRequiredError";
}
Expand Down
6 changes: 5 additions & 1 deletion memorylayer-sdk-typescript/tests/coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ describe("Entity registry ops", () => {

it("maps 501 to EnterpriseRequiredError when registry disabled", async () => {
(global.fetch as ReturnType<typeof vi.fn>).mockResolvedValueOnce(mockErr(501, { detail: "registry off" }));
await expect(client.listEntities()).rejects.toBeInstanceOf(EnterpriseRequiredError);
const err = await client.listEntities().catch((e: unknown) => e);
expect(err).toBeInstanceOf(EnterpriseRequiredError);
expect((err as EnterpriseRequiredError).statusCode).toBe(501);
expect((err as EnterpriseRequiredError).message).toContain("github.com/scitrera/memorylayer-enterprise");
expect((err as EnterpriseRequiredError).message).not.toContain("upgrade");
});
});

Expand Down
Loading