{"record":{"id":"e8de1c37675847a1","repo":"Tencent/WeKnora","slug":"user-is-not-a-system-administrator","errorCode":null,"errorMessage":"user is not a system administrator","messagePattern":"user is not a system administrator","errorType":"error_code","errorClass":null,"httpStatus":400,"severity":"error","filePath":"internal/application/repository/user.go","lineNumber":19,"sourceCode":"package repository\n\nimport (\n\t\"context\"\n\t\"errors\"\n\n\t\"github.com/Tencent/WeKnora/internal/types\"\n\t\"github.com/Tencent/WeKnora/internal/types/interfaces\"\n\t\"gorm.io/gorm\"\n\t\"gorm.io/gorm/clause\"\n)\n\nvar (\n\tErrUserNotFound       = errors.New(\"user not found\")\n\tErrUserAlreadyExists  = errors.New(\"user already exists\")\n\tErrTokenNotFound      = errors.New(\"token not found\")\n\tErrCannotRevokeSelf   = errors.New(\"cannot revoke your own system admin privileges\")\n\tErrLastSystemAdmin    = errors.New(\"cannot revoke the last remaining system administrator\")\n\tErrUserNotSystemAdmin = errors.New(\"user is not a system administrator\")\n)\n\n// userRepository implements user repository interface\ntype userRepository struct {\n\tdb *gorm.DB\n}\n\n// NewUserRepository creates a new user repository\nfunc NewUserRepository(db *gorm.DB) interfaces.UserRepository {\n\treturn &userRepository{db: db}\n}\n\n// CreateUser creates a user\nfunc (r *userRepository) CreateUser(ctx context.Context, user *types.User) error {\n\t// users.tenant_id is nullable in both PostgreSQL and SQLite. GORM would\n\t// otherwise serialise the uint64 zero value as 0, which violates the\n\t// PostgreSQL FK and loses the distinction between \"not provisioned yet\"\n\t// and a real tenant. Omitting the column stores SQL NULL; reads hydrate it","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/repository/user.go#L1-L37","documentation":"Sentinel ErrUserNotSystemAdmin returned when revoking system-admin from a user whose IsSystemAdmin flag is false — the target simply lacks the privilege. The repo still returns the user plus this error so an audit row with changed=false is recorded for probing attempts.","triggerScenarios":"Thrown at internal/application/repository/user.go:19 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the target is actually a system admin before revoking","Treat as a no-op success in the UI, since nothing changed; check for probing patterns in audit logs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}