/
ParsingException.cs
61 lines (52 loc) · 2.06 KB
/
ParsingException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
namespace DTDLParser
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
/// <summary>
/// Indicates that one or more model errors were discovered during DTDL parsing.
/// </summary>
public class ParsingException : Exception
{
/// <summary>
/// Initializes a new instance of the <see cref="ParsingException"/> class.
/// </summary>
/// <param name="errors">A list of the errors that were discovered.</param>
internal ParsingException(IList<ParsingError> errors)
: base("Parsing exception -- " + errors.Count + " errors in model -- see Errors property for details on each")
{
this.Errors = errors;
}
/// <summary>
/// Gets a list of the errors that were discovered during DTDL parsing.
/// </summary>
/// <value>A list of <see cref="ParsingError"/>.</value>
public IList<ParsingError> Errors { get; }
/// <summary>
/// Returns a string that represents the current object.
/// </summary>
/// <returns>A string that represents the current object.</returns>
public override string ToString()
{
return this.Message + " -- first error includes message: " + this.Errors.First().Message;
}
/// <summary>
/// Write a JSON representation of the parsing exception.
/// </summary>
/// <param name="jsonWriter">A <c>Utf8JsonWriter</c> object with which to write the JSON representation.</param>
internal virtual void WriteToJson(Utf8JsonWriter jsonWriter)
{
jsonWriter.WriteStartObject();
jsonWriter.WriteString("ExceptionKind", "Parsing");
jsonWriter.WritePropertyName("Errors");
jsonWriter.WriteStartArray();
foreach (ParsingError parsingError in this.Errors)
{
parsingError.WriteToJson(jsonWriter);
}
jsonWriter.WriteEndArray();
jsonWriter.WriteEndObject();
}
}
}