Skip to content

Commit

Permalink
[dotnet] link exceptions to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jun 7, 2023
1 parent cb9cdc1 commit b30ec03
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 9 deletions.
21 changes: 18 additions & 3 deletions dotnet/src/webdriver/InvalidSelectorException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ namespace OpenQA.Selenium
[Serializable]
public class InvalidSelectorException : WebDriverException
{
/// <summary>
/// Link to the documentation for this error
/// </summary>
private static string supportUrl = baseSupportUrl + "#invalid-selector-exception";

/// <summary>
/// Initializes a new instance of the <see cref="InvalidSelectorException"/> class.
/// </summary>
public InvalidSelectorException()
: base()
: base(GetMessage(""))
{
}

Expand All @@ -41,7 +46,7 @@ public InvalidSelectorException()
/// </summary>
/// <param name="message">The message that describes the error.</param>
public InvalidSelectorException(string message)
: base(message)
: base(GetMessage(message))
{
}

Expand All @@ -54,7 +59,7 @@ public InvalidSelectorException(string message)
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public InvalidSelectorException(string message, Exception innerException)
: base(message, innerException)
: base(GetMessage(message), innerException)
{
}

Expand All @@ -69,5 +74,15 @@ protected InvalidSelectorException(SerializationInfo info, StreamingContext cont
: base(info, context)
{
}

/// <summary>
/// Add information about obtaining additional support from documentation to this exception.
/// </summary>
/// <param name="message">The original message for exception</param>
/// <returns>The final message for exception</returns>
protected static string GetMessage(string message)
{
return message + "; " + supportMsg + supportUrl;
}
}
}
22 changes: 19 additions & 3 deletions dotnet/src/webdriver/NoSuchElementException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,17 @@ namespace OpenQA.Selenium
[Serializable]
public class NoSuchElementException : NotFoundException
{

/// <summary>
/// Link to the documentation for this error
/// </summary>
private static string supportUrl = baseSupportUrl + "#no-such-element-exception";

/// <summary>
/// Initializes a new instance of the <see cref="NoSuchElementException"/> class.
/// </summary>
public NoSuchElementException()
: base()
: base(GetMessage(""))
{
}

Expand All @@ -41,7 +47,7 @@ public NoSuchElementException()
/// </summary>
/// <param name="message">The message that describes the error.</param>
public NoSuchElementException(string message)
: base(message)
: base(GetMessage(message))
{
}

Expand All @@ -54,7 +60,7 @@ public NoSuchElementException(string message)
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public NoSuchElementException(string message, Exception innerException)
: base(message, innerException)
: base(GetMessage(message), innerException)
{
}

Expand All @@ -69,5 +75,15 @@ protected NoSuchElementException(SerializationInfo info, StreamingContext contex
: base(info, context)
{
}

/// <summary>
/// Add information about obtaining additional support from documentation to this exception.
/// </summary>
/// <param name="message">The original message for exception</param>
/// <returns>The final message for exception</returns>
protected static string GetMessage(string message)
{
return message + "; " + supportMsg + supportUrl;
}
}
}
21 changes: 18 additions & 3 deletions dotnet/src/webdriver/StaleElementReferenceException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ namespace OpenQA.Selenium
[Serializable]
public class StaleElementReferenceException : WebDriverException
{
/// <summary>
/// Link to the documentation for this error
/// </summary>
private static string supportUrl = baseSupportUrl + "#stale-element-reference-exception";

/// <summary>
/// Initializes a new instance of the <see cref="StaleElementReferenceException"/> class.
/// </summary>
public StaleElementReferenceException()
: base()
: base(GetMessage(""))
{
}

Expand All @@ -41,7 +46,7 @@ public StaleElementReferenceException()
/// </summary>
/// <param name="message">The message that describes the error.</param>
public StaleElementReferenceException(string message)
: base(message)
: base(GetMessage(message))
{
}

Expand All @@ -54,7 +59,7 @@ public StaleElementReferenceException(string message)
/// <param name="innerException">The exception that is the cause of the current exception,
/// or <see langword="null"/> if no inner exception is specified.</param>
public StaleElementReferenceException(string message, Exception innerException)
: base(message, innerException)
: base(GetMessage(message), innerException)
{
}

Expand All @@ -69,5 +74,15 @@ protected StaleElementReferenceException(SerializationInfo info, StreamingContex
: base(info, context)
{
}

/// <summary>
/// Add information about obtaining additional support from documentation to this exception.
/// </summary>
/// <param name="message">The original message for exception</param>
/// <returns>The final message for exception</returns>
protected static string GetMessage(string message)
{
return message + "; " + supportMsg + supportUrl;
}
}
}
10 changes: 10 additions & 0 deletions dotnet/src/webdriver/WebDriverException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ namespace OpenQA.Selenium
[Serializable]
public class WebDriverException : Exception
{
/// <summary>
/// Intro comment for pointing to documentation
/// </summary>
protected static string supportMsg = "For documentation on this error, please visit: ";

/// <summary>
/// Location of errors in documentation
/// </summary>
protected static string baseSupportUrl = "https://www.selenium.dev/documentation/webdriver/troubleshooting/errors";

/// <summary>
/// Initializes a new instance of the <see cref="WebDriverException"/> class.
/// </summary>
Expand Down

0 comments on commit b30ec03

Please sign in to comment.