Skip to content

Commit

Permalink
feat: Added new speckle exceptions and split into single files (#136)
Browse files Browse the repository at this point in the history
* feat: Added new speckle exceptions and split into single files

* fix: Run format
  • Loading branch information
AlanRynne authored Oct 7, 2024
1 parent 1435933 commit 0d7805d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 108 deletions.
108 changes: 0 additions & 108 deletions src/Speckle.Sdk/Common/Exceptions.cs

This file was deleted.

19 changes: 19 additions & 0 deletions src/Speckle.Sdk/Common/Exceptions/ConversionException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace Speckle.Sdk.Common.Exceptions;

/// <summary>
/// Exception thrown when conversion of an object was not successful
/// </summary>
/// <remarks>
/// Ideally this exception contains a meaningful message.
/// This exception can be used for both ToSpeckle and ToNative conversion
/// </remarks>
public class ConversionException : SpeckleException
{
public ConversionException(string? message, Exception? innerException)
: base(message, innerException) { }

public ConversionException(string? message)
: base(message) { }

public ConversionException() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Speckle.Sdk.Common.Exceptions;

/// <summary>
/// Exception used when an object could not be converted, because we don't support a specific conversion.
/// </summary>
/// <remarks>
/// This Exception should be thrown only when a top-level converter does not exist.</remarks>
/// <example>
/// It should <b>NOT</b> be used for:
/// <ul>
/// <li> objects who's <see cref="Type"/> we don't support (e.g. <c>"Walls are not supported"</c>)</li>
/// <li> objects with a property whose value we don't support (e.g. <c>"Beams with shape type of Circular are not supported"</c>)</li>
/// <li> complex object requirements (e.g. <c>"We don't support walls with zero width and no displayValue"</c>)</li>
/// <li> Invalid Speckle Objects (e.g. <c>"We don't support walls with null lines"</c>)</li>
/// <li> Objects that we have already converted, and therefore now skip (e.g. <c>"A Wall with the same name was already converted"</c>)</li>
/// <li> Reactive error handling (e.g. "Failed to convert wall, I guess it wasn't supported")</li>
/// </ul>
/// </example>
public class ConversionNotSupportedException : ConversionException
{
public ConversionNotSupportedException(string message, Exception innerException)
: base(message, innerException) { }

public ConversionNotSupportedException(string message)
: base(message) { }

public ConversionNotSupportedException() { }
}
15 changes: 15 additions & 0 deletions src/Speckle.Sdk/Common/Exceptions/UnitNotSupportedException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Speckle.Sdk.Common.Exceptions;

/// <summary>
/// Exception thrown when a unit is encountered that is not supported, either by Speckle or the host app.
/// </summary>
public class UnitNotSupportedException : SpeckleException
{
public UnitNotSupportedException() { }

public UnitNotSupportedException(string message)
: base(message) { }

public UnitNotSupportedException(string message, Exception innerException)
: base(message, innerException) { }
}
30 changes: 30 additions & 0 deletions src/Speckle.Sdk/Common/Exceptions/ValidationException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Speckle.Sdk.Common.Exceptions;

/// <summary>
/// Exception thrown when conversion cannot be performed
/// </summary>
/// <remarks>Ideally, this exception should be thrown when we can pre-emptively check for invalid data that is known to cause an exception under normal circumstances</remarks>
/// <example>
/// It can be used for:
/// <ul>
/// <li> Invalid Speckle Objects (e.g. <c>"We don't support walls with null lines"</c>)</li>
/// <li> objects with a property whose value we don't support (e.g. <c>"Beams with shape type of Circular are not supported"</c>)</li>
/// <li> complex object requirements (e.g. <c>"We don't support walls with zero width and no displayValue"</c>)</li>
/// </ul>
/// It should <b>NOT</b> be used for:
/// <ul>
/// <li> Objects we have no top-level converter for</li>
/// <li> Objects that we have already converted, and therefore now skip (e.g. <c>"A Wall with the same name was already converted"</c>)</li>
/// <li> Reactive error handling (e.g. "Failed to convert wall, I guess it wasn't supported")</li>
/// </ul>
/// </example>
public class ValidationException : SpeckleException
{
public ValidationException() { }

public ValidationException(string message)
: base(message) { }

public ValidationException(string message, Exception innerException)
: base(message, innerException) { }
}

0 comments on commit 0d7805d

Please sign in to comment.