From fdc268c39a0b7586551fd77d0f9c1b22769d3182 Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Fri, 8 Feb 2019 13:05:18 -0800 Subject: [PATCH] specify reason why exception is thrown despite regex match --- src/Discord.Net.Webhook/DiscordWebhookClient.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Webhook/DiscordWebhookClient.cs b/src/Discord.Net.Webhook/DiscordWebhookClient.cs index 71f4793be..143f4f687 100644 --- a/src/Discord.Net.Webhook/DiscordWebhookClient.cs +++ b/src/Discord.Net.Webhook/DiscordWebhookClient.cs @@ -64,18 +64,19 @@ namespace Discord.Webhook "The given webhook Url cannot be null or whitespace."); // thrown when groups are not populated/valid, or when there is no match - ArgumentException ex() - => new ArgumentException(paramName: nameof(webhookUrl), message: "The given webhook Url was not in a valid format."); + ArgumentException ex(string reason = null) + => new ArgumentException(paramName: nameof(webhookUrl), message: + $"The given webhook Url was not in a valid format. {reason}"); var match = WebhookUrlRegex.Match(webhookUrl); if (match != null) { // ensure that the first group is a ulong, set the _webhookId // 0th group is always the entire match, so start at index 1 if (!(match.Groups[1].Success && ulong.TryParse(match.Groups[1].Value, out _webhookId))) - throw ex(); + throw ex("The webhook Id could not be parsed."); if (!match.Groups[2].Success) - throw ex(); + throw ex("The webhook token could not be parsed."); ApiClient.LoginAsync(TokenType.Webhook, match.Groups[2].Value).GetAwaiter().GetResult(); Webhook = WebhookClientHelper.GetWebhookAsync(this, _webhookId).GetAwaiter().GetResult();