I came across this issue when trying to add a role to my own user, in order to have the account serve as a community account for community user provisioning. I also tried creating another admin with the role set from the get-go but same issue. Anybody else seen this?
This is a pretty common issue with scratch orgs, particularly if your org is generated with
hasSampleData: false. It comes up any time you assign one of the built-in Roles to any User and it's always a gack.
I typically begin scratch org builds that use
hasSampleData: false with a little Anonymous Apex:
delete [SELECT Id FROM UserRole]; UserRole ur = new UserRole(Name = 'CEO'); insert ur; update new User(Id = UserInfo.getUserId(), UserRoleId = ur.Id);