fix: throw exception when accessing result props incorrectly
This commit is contained in:
@@ -5,21 +5,54 @@ namespace AnthropicClient.Models;
|
||||
/// </summary>
|
||||
public class ToolCallResult<T>
|
||||
{
|
||||
private T? _value = default!;
|
||||
|
||||
/// <summary>
|
||||
/// The value of the tool call result. Can be null if the call failed, the call was successful but the return type is void or Task, or the call was successful but the return value is null
|
||||
/// </summary>
|
||||
public T? Value { get; }
|
||||
/// <exception cref="InvalidOperationException">Thrown when the result is not successful.</exception>
|
||||
public T? Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsSuccess ? _value : throw new InvalidOperationException("The result is not successful. Check the error property for more information.");
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
}
|
||||
|
||||
private Exception _error = default!;
|
||||
|
||||
/// <summary>
|
||||
/// The error of the tool call result.
|
||||
/// </summary>
|
||||
public Exception Error { get; }
|
||||
/// <exception cref="InvalidOperationException">Thrown when the result is successful.</exception>
|
||||
public Exception Error
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsSuccess ? throw new InvalidOperationException("The result is successful. Check the value property for more information.") : _error;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
_error = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the tool call was successful.
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the tool call failed.
|
||||
/// </summary>
|
||||
public bool IsFailure => !IsSuccess;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ToolCallResult{T}"/> class.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user