refactor: consolidate [x]TooLongErrors into StringTooLongError
This commit is contained in:
		@@ -194,7 +194,7 @@ namespace PluralKit.Bot
 | 
			
		||||
            {
 | 
			
		||||
                var description = ctx.RemainderOrNull().NormalizeLineEndSpacing();
 | 
			
		||||
                if (description.IsLongerThan(Limits.MaxDescriptionLength))
 | 
			
		||||
                    throw Errors.DescriptionTooLongError(description.Length);
 | 
			
		||||
                    throw Errors.StringTooLongError("Description", description.Length, Limits.MaxDescriptionLength);
 | 
			
		||||
 | 
			
		||||
                var patch = new GroupPatch { Description = Partial<string>.Present(description) };
 | 
			
		||||
                await _db.Execute(conn => _repo.UpdateGroup(conn, target.Id, patch));
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,8 @@ namespace PluralKit.Bot
 | 
			
		||||
            var memberName = ctx.RemainderOrNull() ?? throw new PKSyntaxError("You must pass a member name.");
 | 
			
		||||
 | 
			
		||||
            // Hard name length cap
 | 
			
		||||
            if (memberName.Length > Limits.MaxMemberNameLength) throw Errors.MemberNameTooLongError(memberName.Length);
 | 
			
		||||
            if (memberName.Length > Limits.MaxMemberNameLength)
 | 
			
		||||
                throw Errors.StringTooLongError("Member name", memberName.Length, Limits.MaxMemberNameLength);
 | 
			
		||||
 | 
			
		||||
            // Warn if there's already a member by this name
 | 
			
		||||
            var existingMember = await _db.Execute(c => _repo.GetMemberByName(c, ctx.System.Id, memberName));
 | 
			
		||||
 
 | 
			
		||||
@@ -31,7 +31,8 @@ namespace PluralKit.Bot
 | 
			
		||||
            var newName = ctx.RemainderOrNull() ?? throw new PKSyntaxError("You must pass a new name for the member.");
 | 
			
		||||
 | 
			
		||||
            // Hard name length cap
 | 
			
		||||
            if (newName.Length > Limits.MaxMemberNameLength) throw Errors.MemberNameTooLongError(newName.Length);
 | 
			
		||||
            if (newName.Length > Limits.MaxMemberNameLength)
 | 
			
		||||
                throw Errors.StringTooLongError("Member name", newName.Length, Limits.MaxMemberNameLength);
 | 
			
		||||
 | 
			
		||||
            // Warn if there's already a member by this name
 | 
			
		||||
            var existingMember = await _db.Execute(conn => _repo.GetMemberByName(conn, ctx.System.Id, newName));
 | 
			
		||||
@@ -100,7 +101,7 @@ namespace PluralKit.Bot
 | 
			
		||||
            {
 | 
			
		||||
                var description = ctx.RemainderOrNull().NormalizeLineEndSpacing();
 | 
			
		||||
                if (description.IsLongerThan(Limits.MaxDescriptionLength))
 | 
			
		||||
                    throw Errors.DescriptionTooLongError(description.Length);
 | 
			
		||||
                    throw Errors.StringTooLongError("Description", description.Length, Limits.MaxDescriptionLength);
 | 
			
		||||
 | 
			
		||||
                var patch = new MemberPatch { Description = Partial<string>.Present(description) };
 | 
			
		||||
                await _db.Execute(conn => _repo.UpdateMember(conn, target.Id, patch));
 | 
			
		||||
@@ -148,7 +149,7 @@ namespace PluralKit.Bot
 | 
			
		||||
            {
 | 
			
		||||
                var pronouns = ctx.RemainderOrNull().NormalizeLineEndSpacing();
 | 
			
		||||
                if (pronouns.IsLongerThan(Limits.MaxPronounsLength))
 | 
			
		||||
                    throw Errors.MemberPronounsTooLongError(pronouns.Length);
 | 
			
		||||
                    throw Errors.StringTooLongError("Pronouns", pronouns.Length, Limits.MaxPronounsLength);
 | 
			
		||||
 | 
			
		||||
                var patch = new MemberPatch { Pronouns = Partial<string>.Present(pronouns) };
 | 
			
		||||
                await _db.Execute(conn => _repo.UpdateMember(conn, target.Id, patch));
 | 
			
		||||
 
 | 
			
		||||
@@ -30,7 +30,7 @@ namespace PluralKit.Bot
 | 
			
		||||
 | 
			
		||||
            var systemName = ctx.RemainderOrNull();
 | 
			
		||||
            if (systemName != null && systemName.Length > Limits.MaxSystemNameLength)
 | 
			
		||||
                throw Errors.SystemNameTooLongError(systemName.Length);
 | 
			
		||||
                throw Errors.StringTooLongError("System name", systemName.Length, Limits.MaxSystemNameLength);
 | 
			
		||||
 | 
			
		||||
            var system = _db.Execute(async c =>
 | 
			
		||||
            {
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,7 @@ namespace PluralKit.Bot
 | 
			
		||||
                var newSystemName = ctx.RemainderOrNull();
 | 
			
		||||
 | 
			
		||||
                if (newSystemName.Length > Limits.MaxSystemNameLength)
 | 
			
		||||
                    throw Errors.SystemNameTooLongError(newSystemName.Length);
 | 
			
		||||
                    throw Errors.StringTooLongError("System name", newSystemName.Length, Limits.MaxSystemNameLength);
 | 
			
		||||
 | 
			
		||||
                var patch = new SystemPatch { Name = newSystemName };
 | 
			
		||||
                await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, patch));
 | 
			
		||||
@@ -109,7 +109,8 @@ namespace PluralKit.Bot
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                var newDescription = ctx.RemainderOrNull()?.NormalizeLineEndSpacing();
 | 
			
		||||
                if (newDescription.Length > Limits.MaxDescriptionLength) throw Errors.DescriptionTooLongError(newDescription.Length);
 | 
			
		||||
                if (newDescription.Length > Limits.MaxDescriptionLength)
 | 
			
		||||
                    throw Errors.StringTooLongError("Description", newDescription.Length, Limits.MaxDescriptionLength);
 | 
			
		||||
 | 
			
		||||
                var patch = new SystemPatch { Description = newDescription };
 | 
			
		||||
                await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, patch));
 | 
			
		||||
@@ -195,7 +196,7 @@ namespace PluralKit.Bot
 | 
			
		||||
                var newTag = ctx.RemainderOrNull(skipFlags: false);
 | 
			
		||||
                if (newTag != null)
 | 
			
		||||
                    if (newTag.Length > Limits.MaxSystemTagLength)
 | 
			
		||||
                        throw Errors.SystemTagTooLongError(newTag.Length);
 | 
			
		||||
                        throw Errors.StringTooLongError("System tag", newTag.Length, Limits.MaxSystemTagLength);
 | 
			
		||||
 | 
			
		||||
                var patch = new SystemPatch { Tag = newTag };
 | 
			
		||||
                await _db.Execute(conn => _repo.UpdateSystem(conn, ctx.System.Id, patch));
 | 
			
		||||
@@ -234,7 +235,7 @@ namespace PluralKit.Bot
 | 
			
		||||
            {
 | 
			
		||||
                var newTag = ctx.RemainderOrNull(skipFlags: false);
 | 
			
		||||
                if (newTag != null && newTag.Length > Limits.MaxSystemTagLength)
 | 
			
		||||
                    throw Errors.SystemTagTooLongError(newTag.Length);
 | 
			
		||||
                    throw Errors.StringTooLongError("System server tag", newTag.Length, Limits.MaxSystemTagLength);
 | 
			
		||||
 | 
			
		||||
                var patch = new SystemGuildPatch { Tag = newTag };
 | 
			
		||||
                await _db.Execute(conn => _repo.UpsertSystemGuild(conn, ctx.System.Id, ctx.Guild.Id, patch));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user