// Copyright (c) The Geekeey Authors
// SPDX-License-Identifier: EUPL-1.2
#pragma warning disable CA1716
namespace Geekeey.Request.Result;
///
/// An error containing a simple message. Makes up the other half of a which might be an error.
///
///
/// An error is conceptually very similar to an exception but without the ability to be thrown, meant to be a more
/// lightweight type meant to be wrapped in a .
/// An error fundamentally only contains a single string message, however other more concrete types such as
/// or may define other properties.
/// Errors are meant to be small, specific, and descriptive, such that they are easy to match over and provide specific
/// handling for specific kinds of errors.
///
public abstract class Error
{
///
/// A statically accessible default "Result has no value." error.
///
internal static Error DefaultValueError { get; } = new StringError("The result has no value.");
///
/// The message used to display the error.
///
public abstract string Message { get; }
///
/// Gets a string representation of the error. Returns by default.
///
public override string ToString()
{
return Message;
}
///
/// Implicitly converts a string into a .
///
/// The message of the error.
public static implicit operator Error(string message)
{
return new StringError(message);
}
///
/// Implicitly converts an exception into an .
///
/// The exception to convert.
public static implicit operator Error(Exception exception)
{
return new ExceptionError(exception);
}
}