/// <summary> /// Constructs an error from parameters. /// </summary> /// <param name="error">The GOLANG error string.</param> /// <param name="type">Optionally specifies the error type. This defaults to <see cref="CadenceErrorType.Custom"/>.</param> public CadenceError(string error, CadenceErrorType type = CadenceErrorType.Custom) { Covenant.Requires <ArgumentNullException>(!string.IsNullOrEmpty(error), nameof(error)); this.String = error; this.SetErrorType(type); }
/// <summary> /// Converts an <see cref="CadenceErrorType"/> into a error string. /// </summary> /// <param name="type">the error type.</param> /// <returns>The error string.</returns> internal static string ErrorTypeToString(CadenceErrorType type) { switch (type) { case CadenceErrorType.Cancelled: return("cancelled"); case CadenceErrorType.Custom: return("custom"); case CadenceErrorType.Generic: return("generic"); case CadenceErrorType.Panic: return("panic"); case CadenceErrorType.Terminated: return("terminated"); case CadenceErrorType.Timeout: return("timeout"); default: throw new NotImplementedException(); } }
/// <summary> /// Sets the error type. /// </summary> /// <param name="type">The new type.</param> internal void SetErrorType(CadenceErrorType type) { Type = ErrorTypeToString(type); }