toeverything/AFFiNE · error · NotFoundException

not_found

not_found

Error message

Resource not found.

What it means

AdminWorkspaceResolver.assertCloudOnly throws Nest's NotFoundException whenever env.selfhosted is truthy. Admin GraphQL fields (adminWorkspaces and siblings) deliberately return generic 404 not-found on self-hosted builds so the admin surface is neither usable nor discoverable there.

Source

Thrown at packages/backend/server/src/core/workspaces/resolvers/admin.ts:445

  ] as const),
  InputType
) {
  @Field()
  id!: string;
}

@Injectable()
@Admin()
@Resolver(() => AdminWorkspace)
export class AdminWorkspaceResolver {
  constructor(
    private readonly models: Models,
    private readonly url: URLHelper
  ) {}

  private assertCloudOnly() {
    if (env.selfhosted) {
      throw new NotFoundException();
    }
  }

  @Query(() => [AdminWorkspace], {
    description: 'List workspaces for admin',
  })
  async adminWorkspaces(
    @Args('filter', { type: () => ListWorkspaceInput })
    filter: ListWorkspaceInput
  ) {
    this.assertCloudOnly();
    const { rows } = await this.models.workspace.adminListWorkspaces({
      first: filter.first,
      skip: filter.skip,
      keyword: filter.keyword,
      order: this.mapSort(filter.orderBy),
      flags: {
        public: filter.public ?? undefined,

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Do not call admin* resolvers on self-hosted — they are intentionally absent there
  2. If this deployment should be cloud, set the selfhosted env flag to false
  3. Target admin APIs only at the cloud deployment with an admin-authenticated account
  4. In clients, detect this 404 on admin fields and show 'not available on self-hosted' instead of retrying
Defensive patterns

Strategy: validation

Validate before calling

// know your deployment before wiring admin tooling
const isSelfHosted = await detectSelfHosted(); // e.g. from server capabilities/config endpoint
if (isSelfHosted) {
  disableAdminFeatures(); // admin resolvers intentionally 404 there
} else {
  mountAdminConsole();
}

Try / catch

try {
  return await adminClient.request(ADMIN_WORKSPACES_QUERY);
} catch (e) {
  if (e?.code === 'not_found' && targetIsSelfHosted) {
    return showAdminUnavailable(); // by design — do not retry
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking any admin* query/mutation guarded by assertCloudOnly on a deployment built or configured with selfhosted=true; also schema-introspecting clients that assume listed admin fields are callable everywhere.

Common situations: Self-hosted installs pointed at admin tooling or scripts written for the cloud; a cloud-like deployment where the selfhosted env flag was left/mis-set to true; operators wondering why admin queries 404 despite an admin user account.

Understand the failure class

Background: NOT_FOUND error code: why tRPC, Harbor, Nacos and other libraries return 404 "not found" errors for resources that may still exist — this error's family across 11 libraries.

Related errors


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/9c047e7a2e39418c. Report an issue: GitHub.