{"record":{"id":"a6b28a9ef0c92c08","repo":"paperclipai/paperclip","slug":"principal-is-not-a-member-of-this-company","errorCode":null,"errorMessage":"Principal is not a member of this company","messagePattern":"Principal is not a member of this company","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-host-services.ts","lineNumber":3055,"sourceCode":"        ].filter((condition): condition is NonNullable<typeof condition> => Boolean(condition));\n        const rows = await db\n          .select()\n          .from(principalPermissionGrants)\n          .where(and(...conditions))\n          .orderBy(principalPermissionGrants.principalType, principalPermissionGrants.principalId, principalPermissionGrants.permissionKey);\n        return rows.map(redactGrant);\n      },\n      async setGrants(params) {\n        const companyId = ensureCompanyId(params.companyId);\n        await ensurePluginAvailableForCompany(companyId);\n        if (params.principalType !== \"agent\" && params.principalType !== \"user\") {\n          throw new Error(\"principalType must be 'agent' or 'user'\");\n        }\n        if (params.principalType === \"agent\") {\n          requireInCompany(\"Agent\", await agents.getById(params.principalId), companyId);\n        } else {\n          const membership = await access.getMembership(companyId, params.principalType as PrincipalType, params.principalId);\n          if (!membership) throw new Error(\"Principal is not a member of this company\");\n        }\n        await access.setPrincipalGrants(\n          companyId,\n          params.principalType as PrincipalType,\n          params.principalId,\n          params.grants.map((grant) => ({\n            permissionKey: grant.permissionKey as PermissionKey,\n            scope: grant.scope ? sanitizeRecord(grant.scope) : null,\n          })),\n          params.grantedByUserId ?? null,\n        );\n        await logPluginActivity({\n          companyId,\n          action: \"authorization.grants_updated_by_plugin\",\n          entityType: \"principal_permission_grants\",\n          entityId: `${params.principalType}:${params.principalId}`,\n          details: { grantCount: params.grants.length },\n        });","sourceCodeStart":3037,"sourceCodeEnd":3073,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/server/src/services/plugin-host-services.ts#L3037-L3073","documentation":"The principal targeted by a permission grant operation has no active membership in the company. Grants can only be managed for principals that belong to the company being modified.","triggerScenarios":"Thrown at server/src/services/plugin-host-services.ts:3046 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add the principal (agent or user) as a member of the company first, or use a principal that is already a member."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a7e689b3c35347b529cb9f54c9b9a8575a3dcab6","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}