{"record":{"id":"f51cb8ea580adc0b","repo":"paperclipai/paperclip","slug":"principaltype-must-be-agent-or-user","errorCode":null,"errorMessage":"principalType must be 'agent' or 'user'","messagePattern":"principalType must be 'agent' or 'user'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-host-services.ts","lineNumber":3049,"sourceCode":"        const companyId = ensureCompanyId(params.companyId);\n        await ensurePluginAvailableForCompany(companyId);\n        const conditions = [\n          eq(principalPermissionGrants.companyId, companyId),\n          params.principalType ? eq(principalPermissionGrants.principalType, params.principalType) : undefined,\n          params.principalId ? eq(principalPermissionGrants.principalId, params.principalId) : undefined,\n        ].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({","sourceCodeStart":3031,"sourceCodeEnd":3067,"githubUrl":"https://github.com/paperclipai/paperclip/blob/a7e689b3c35347b529cb9f54c9b9a8575a3dcab6/server/src/services/plugin-host-services.ts#L3031-L3067","documentation":"setGrants received a principalType outside the allowed set. Permission grants apply only to 'agent' or 'user' principals; the plugin passed some other value.","triggerScenarios":"Thrown at server/src/services/plugin-host-services.ts:3040 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set principalType to exactly 'agent' or 'user' in the request; any other value is rejected."],"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"}