/src/HotChocolate/Core/src/Abstractions/IError.cs

https://github.com/ChilliCream/hotchocolate · C# · 223 lines · 29 code · 21 blank · 173 comment · 0 complexity · c394c56927b3b8c58ae90d50b7a037c8 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. #nullable enable
  4. namespace HotChocolate
  5. {
  6. /// <summary>
  7. /// Represents a schema or query error.
  8. /// </summary>
  9. public interface IError
  10. {
  11. /// <summary>
  12. /// Gets the error message.
  13. /// This property is mandatory and cannot be null.
  14. /// </summary>
  15. string Message { get; }
  16. /// <summary>
  17. /// Gets an error code that can be used to automatically
  18. /// process an error.
  19. /// This property is optional and can be null.
  20. /// </summary>
  21. string? Code { get; }
  22. /// <summary>
  23. /// Gets the path to the object that caused the error.
  24. /// This property is optional and can be null.
  25. /// </summary>
  26. Path? Path { get; }
  27. /// <summary>
  28. /// Gets the source text positions to which this error refers to.
  29. /// This property is optional and can be null.
  30. /// </summary>
  31. IReadOnlyList<Location>? Locations { get; }
  32. /// <summary>
  33. /// Gets non-spec error properties.
  34. /// This property is optional and can be null.
  35. /// </summary>
  36. IReadOnlyDictionary<string, object?>? Extensions { get; }
  37. /// <summary>
  38. /// Gets the exception associated with this error.
  39. /// </summary>
  40. Exception? Exception { get; }
  41. /// <summary>
  42. /// Creates a new error that contains all properties of this error
  43. /// but with the specified <paramref name="message" />.
  44. /// </summary>
  45. /// <param name="message">
  46. /// The error message.
  47. /// </param>
  48. /// <returns>
  49. /// Returns a new error that contains all properties of this error
  50. /// but with the specified <paramref name="message" />.
  51. /// </returns>
  52. /// <exception cref="ArgumentNullException">
  53. /// The <paramref name="message" /> is null or empty.
  54. /// </exception>
  55. IError WithMessage(string message);
  56. /// <summary>
  57. /// Creates a new error that contains all properties of this error
  58. /// but with the specified <paramref name="code" />.
  59. /// </summary>
  60. /// <param name="code">
  61. /// An error code that is specified as custom error property.
  62. /// </param>
  63. /// <returns>
  64. /// Returns a new error that contains all properties of this error
  65. /// but with the specified <paramref name="code" />.
  66. /// </returns>
  67. IError WithCode(string? code);
  68. /// <summary>
  69. /// Creates a new error that contains all properties of this error
  70. /// but with <see cref="Code"/> removed.
  71. /// </summary>
  72. /// <returns>
  73. /// Returns a new error that contains all properties of this error
  74. /// but with <see cref="Code"/> removed.
  75. /// </returns>
  76. IError RemoveCode();
  77. /// <summary>
  78. /// Creates a new error that contains all properties of this error
  79. /// but with the specified <paramref name="path" />.
  80. /// </summary>
  81. /// <param name="path">
  82. /// A path representing a certain syntax node of a query or schema.
  83. /// </param>
  84. /// <returns>
  85. /// Returns a new error that contains all properties of this error
  86. /// but with the specified <paramref name="path" />.
  87. /// </returns>
  88. IError WithPath(Path? path);
  89. /// <summary>
  90. /// Creates a new error that contains all properties of this error
  91. /// but with the specified <paramref name="path" />.
  92. /// </summary>
  93. /// <param name="path">
  94. /// A path representing a certain syntax node of a query or schema.
  95. /// </param>
  96. /// <returns>
  97. /// Returns a new error that contains all properties of this error
  98. /// but with the specified <paramref name="path" />.
  99. /// </returns>
  100. IError WithPath(IReadOnlyList<object>? path);
  101. /// <summary>
  102. /// Creates a new error that contains all properties of this error
  103. /// but with the <see cref="Path"/> removed.
  104. /// </summary>
  105. /// <returns>
  106. /// Returns a new error that contains all properties of this error
  107. /// but with the <see cref="Path"/> removed.
  108. /// </returns>
  109. IError RemovePath();
  110. /// <summary>
  111. /// Creates a new error that contains all properties of this error
  112. /// but with the specified <paramref name="locations" />.
  113. /// </summary>
  114. /// <param name="locations">
  115. /// A collection of locations referring to certain
  116. /// syntax nodes of a query or schema.
  117. /// </param>
  118. /// <returns>
  119. /// Returns a new error that contains all properties of this error
  120. /// but with the specified <paramref name="locations" />.
  121. /// </returns>
  122. IError WithLocations(IReadOnlyList<Location>? locations);
  123. /// <summary>
  124. /// Creates a new error that contains all properties of this error
  125. /// but with the <see cref="Locations"/> removed.
  126. /// </summary>
  127. /// <returns>
  128. /// Returns a new error that contains all properties of this error
  129. /// but with the <see cref="Locations"/> removed.
  130. /// </returns>
  131. IError RemoveLocations();
  132. /// <summary>
  133. /// Creates a new error that contains all properties of this error
  134. /// but with the specified <paramref name="extensions" />.
  135. /// </summary>
  136. /// <param name="extensions">
  137. /// A collection of custom error properties.
  138. /// </param>
  139. /// <returns>
  140. /// Returns a new error that contains all properties of this error
  141. /// but with the specified <paramref name="extensions" />.
  142. /// </returns>
  143. IError WithExtensions(IReadOnlyDictionary<string, object?> extensions);
  144. /// <summary>
  145. /// Creates a new error that contains all properties of this error
  146. /// but with the <see cref="Extensions"/> removed.
  147. /// </summary>
  148. /// <returns>
  149. /// Returns a new error that contains all properties of this error
  150. /// but with the <see cref="Extensions"/> removed.
  151. /// </returns>
  152. IError RemoveExtensions();
  153. /// <summary>
  154. /// Creates a new error that contains all properties of this error
  155. /// but with and additional custom error property.
  156. /// </summary>
  157. /// <param name="key">The custom error property name.</param>
  158. /// <param name="value">The value of the custom error property.</param>
  159. /// <returns>
  160. /// Returns a new error that contains all properties of this error
  161. /// but with and additional custom error property.
  162. /// </returns>
  163. /// <exception cref="ArgumentNullException">
  164. /// The <paramref name="key" /> is null or empty.
  165. /// </exception>
  166. IError SetExtension(string key, object? value);
  167. /// <summary>
  168. /// Creates a new error that contains all properties of this error
  169. /// but with the specified additional custom error property removed.
  170. /// </summary>
  171. /// <param name="key">The custom error property name.</param>
  172. /// <returns>
  173. /// Returns a new error that contains all properties of this error
  174. /// but with the specified additional custom error property removed.
  175. /// </returns>
  176. /// <exception cref="ArgumentNullException">
  177. /// The <paramref name="key" /> is null or empty.
  178. /// </exception>
  179. IError RemoveExtension(string key);
  180. /// <summary>
  181. /// Creates a new error that contains all properties of this error
  182. /// but with the specified <paramref name="exception" />.
  183. /// </summary>
  184. /// <param name="exception">
  185. /// The .net exception that caused this error.
  186. /// </param>
  187. /// <returns>
  188. /// Returns a new error that contains all properties of this error
  189. /// but with the specified <paramref name="exception" />.
  190. /// </returns>
  191. IError WithException(Exception? exception);
  192. /// <summary>
  193. /// Creates a new error that contains all properties of this error
  194. /// but removed the exception from it.
  195. /// </summary>
  196. /// <returns>
  197. /// Returns a new error that contains all properties of this error
  198. /// but without any exception details.
  199. /// </returns>
  200. IError RemoveException();
  201. }
  202. }