Skip to content

Commit 381c459

Browse files
committed
Converted OpenApiExceptions to OpenApiReaderExceptions
1 parent c664ea5 commit 381c459

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

src/Microsoft.OpenApi.Readers/Exceptions/OpenApiReaderException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ public OpenApiReaderException(string message, YamlNode node) : base(message)
5151
/// <param name="message">Plain text error message for this exception.</param>
5252
/// <param name="innerException">Inner exception that caused this exception to be thrown.</param>
5353
public OpenApiReaderException(string message, Exception innerException) : base(message, innerException) { }
54+
5455
}
5556
}

src/Microsoft.OpenApi.Readers/ParseNodes/ListNode.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.OpenApi.Exceptions;
1010
using Microsoft.OpenApi.Interfaces;
1111
using Microsoft.OpenApi.Models;
12+
using Microsoft.OpenApi.Readers.Exceptions;
1213
using SharpYaml.Serialization;
1314

1415
namespace Microsoft.OpenApi.Readers.ParseNodes
@@ -27,8 +28,8 @@ public override List<T> CreateList<T>(Func<MapNode, T> map)
2728
{
2829
if (_nodeList == null)
2930
{
30-
throw new OpenApiException(
31-
$"Expected list at line {_nodeList.Start.Line} while parsing {typeof(T).Name}");
31+
throw new OpenApiReaderException(
32+
$"Expected list at line {_nodeList.Start.Line} while parsing {typeof(T).Name}", _nodeList);
3233
}
3334

3435
return _nodeList.Select(n => map(new MapNode(Context, n as YamlMappingNode)))
@@ -47,8 +48,8 @@ public override List<T> CreateSimpleList<T>(Func<ValueNode, T> map)
4748
{
4849
if (_nodeList == null)
4950
{
50-
throw new OpenApiException(
51-
$"Expected list at line {_nodeList.Start.Line} while parsing {typeof(T).Name}");
51+
throw new OpenApiReaderException(
52+
$"Expected list at line {_nodeList.Start.Line} while parsing {typeof(T).Name}", _nodeList);
5253
}
5354

5455
return _nodeList.Select(n => map(new ValueNode(Context, n))).ToList();

src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public override Dictionary<string, T> CreateMap<T>(Func<MapNode, T> map)
6363
var yamlMap = _node;
6464
if (yamlMap == null)
6565
{
66-
throw new OpenApiException($"Expected map at line {yamlMap.Start.Line} while parsing {typeof(T).Name}");
66+
throw new OpenApiReaderException($"Expected map at line {yamlMap.Start.Line} while parsing {typeof(T).Name}", yamlMap);
6767
}
6868

6969
var nodes = yamlMap.Select(
@@ -99,7 +99,7 @@ public override Dictionary<string, T> CreateMapWithReference<T>(
9999
var yamlMap = _node;
100100
if (yamlMap == null)
101101
{
102-
throw new OpenApiException($"Expected map at line {yamlMap.Start.Line} while parsing {typeof(T).Name}");
102+
throw new OpenApiReaderException($"Expected map at line {yamlMap.Start.Line} while parsing {typeof(T).Name}", yamlMap);
103103
}
104104

105105
var nodes = yamlMap.Select(
@@ -134,7 +134,7 @@ public override Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
134134
var yamlMap = _node;
135135
if (yamlMap == null)
136136
{
137-
throw new OpenApiException($"Expected map at line {yamlMap.Start.Line} while parsing {typeof(T).Name}");
137+
throw new OpenApiReaderException($"Expected map at line {yamlMap.Start.Line} while parsing {typeof(T).Name}", yamlMap);
138138
}
139139

140140
var nodes = yamlMap.Select(
@@ -189,7 +189,7 @@ public string GetScalarValue(ValueNode key)
189189
var scalarNode = _node.Children[new YamlScalarNode(key.GetScalarValue())] as YamlScalarNode;
190190
if (scalarNode == null)
191191
{
192-
throw new OpenApiException($"Expected scalar at line {_node.Start.Line} for key {key.GetScalarValue()}");
192+
throw new OpenApiReaderException($"Expected scalar at line {_node.Start.Line} for key {key.GetScalarValue()}", _node);
193193
}
194194

195195
return scalarNode.Value;

src/Microsoft.OpenApi/Exceptions/OpenApiException.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ public OpenApiException(string message, Exception innerException)
3939
}
4040

4141
/// <summary>
42-
/// The reference pointer.
42+
/// The reference pointer. This is a fragment identifier used to point to where the error occurred in the document.
43+
/// If the document has been parsed as JSON/YAML then the identifier will be a
44+
/// JSON Pointer as per https://tools.ietf.org/html/rfc6901
45+
/// If the document fails to parse as JSON/YAML then the fragment will be based on
46+
/// a text/plain pointer as defined in https://tools.ietf.org/html/rfc5147
47+
/// Currently only line= is provided because using char= causes tests to break due to CR/LF & LF differences
4348
/// </summary>
4449
public string Pointer { get; set; }
50+
4551
}
4652
}

0 commit comments

Comments
 (0)