Skip to content

Commit 01b22c4

Browse files
authored
[Fusion] Renamed SyntaxException to FieldSelectionMapSyntaxException (#7947)
1 parent ae043bc commit 01b22c4

File tree

6 files changed

+53
-36
lines changed

6 files changed

+53
-36
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace HotChocolate.Fusion;
2+
3+
[Serializable]
4+
public sealed class FieldSelectionMapSyntaxException : Exception
5+
{
6+
internal FieldSelectionMapSyntaxException(
7+
FieldSelectionMapReader reader,
8+
string message)
9+
: base(message)
10+
{
11+
Position = reader.Position;
12+
Line = reader.Line;
13+
Column = reader.Column;
14+
}
15+
16+
internal FieldSelectionMapSyntaxException(
17+
FieldSelectionMapReader reader,
18+
string message,
19+
params object[] args)
20+
: this(reader, string.Format(message, args))
21+
{
22+
}
23+
24+
public int Position { get; }
25+
26+
public int Line { get; }
27+
28+
public int Column { get; }
29+
}

src/HotChocolate/Fusion-vnext/src/Fusion.Language/Exceptions/SyntaxException.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/HotChocolate/Fusion-vnext/src/Fusion.Language/Parsers/FieldSelectionMapParser.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ private SelectedValueEntryNode ParseSelectedValueEntry()
109109
break;
110110

111111
default:
112-
throw new SyntaxException(_reader, UnexpectedToken, _reader.TokenKind);
112+
throw new FieldSelectionMapSyntaxException(
113+
_reader,
114+
UnexpectedToken,
115+
_reader.TokenKind);
113116
}
114117

115118
var location = CreateLocation(in start);
@@ -335,7 +338,7 @@ private TokenInfo Start()
335338
{
336339
if (++_parsedNodes > _options.MaxAllowedNodes)
337340
{
338-
throw new SyntaxException(
341+
throw new FieldSelectionMapSyntaxException(
339342
_reader,
340343
string.Format(MaxAllowedNodesExceeded, _options.MaxAllowedNodes));
341344
}
@@ -353,7 +356,11 @@ private void Expect(TokenKind tokenKind)
353356
{
354357
if (!_reader.Skip(tokenKind))
355358
{
356-
throw new SyntaxException(_reader, InvalidToken, tokenKind, _reader.TokenKind);
359+
throw new FieldSelectionMapSyntaxException(
360+
_reader,
361+
InvalidToken,
362+
tokenKind,
363+
_reader.TokenKind);
357364
}
358365
}
359366

@@ -368,7 +375,11 @@ private string ExpectName()
368375
return name;
369376
}
370377

371-
throw new SyntaxException(_reader, InvalidToken, TokenKind.Name, _reader.TokenKind);
378+
throw new FieldSelectionMapSyntaxException(
379+
_reader,
380+
InvalidToken,
381+
TokenKind.Name,
382+
_reader.TokenKind);
372383
}
373384

374385
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/HotChocolate/Fusion-vnext/src/Fusion.Language/Readers/FieldSelectionMapReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public FieldSelectionMapReader(
7878
/// <returns>
7979
/// Returns a boolean indicating if the read was successful.
8080
/// </returns>
81-
/// <exception cref="SyntaxException">
81+
/// <exception cref="FieldSelectionMapSyntaxException">
8282
/// The source text contains an invalid syntax token.
8383
/// </exception>
8484
public bool Read()
@@ -100,7 +100,7 @@ public bool Read()
100100

101101
if (_tokenCount > _maxAllowedTokens)
102102
{
103-
throw new SyntaxException(
103+
throw new FieldSelectionMapSyntaxException(
104104
this,
105105
string.Format(MaxAllowedTokensExceeded, _maxAllowedTokens));
106106
}
@@ -121,7 +121,7 @@ public bool Read()
121121
return true;
122122
}
123123

124-
throw new SyntaxException(this, UnexpectedCharacter, code);
124+
throw new FieldSelectionMapSyntaxException(this, UnexpectedCharacter, code);
125125
}
126126

127127
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/HotChocolate/Fusion-vnext/test/Fusion.Language.Tests/FieldSelectionMapParserTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void Parse_PathSegmentWithTypeNameNoNestedField_ThrowsSyntaxException()
6363
// assert
6464
Assert.Equal(
6565
"Expected a `Period`-token, but found a `EndOfFile`-token.",
66-
Assert.Throws<SyntaxException>(Act).Message);
66+
Assert.Throws<FieldSelectionMapSyntaxException>(Act).Message);
6767
}
6868

6969
[Fact]
@@ -101,7 +101,7 @@ public void Parse_PathWithTypeNameNoPathSegment_ThrowsSyntaxException()
101101
// assert
102102
Assert.Equal(
103103
"Expected a `Period`-token, but found a `EndOfFile`-token.",
104-
Assert.Throws<SyntaxException>(Act).Message);
104+
Assert.Throws<FieldSelectionMapSyntaxException>(Act).Message);
105105
}
106106

107107
[Fact]
@@ -143,7 +143,7 @@ public void Parse_SelectedListValueInvalidExamples_ThrowsSyntaxException(string
143143
// assert
144144
Assert.Equal(
145145
"Expected a `RightSquareBracket`-token, but found a `Name`-token.",
146-
Assert.Throws<SyntaxException>(Act).Message);
146+
Assert.Throws<FieldSelectionMapSyntaxException>(Act).Message);
147147
}
148148

149149
[Fact]
@@ -268,6 +268,6 @@ static void Act()
268268
// assert
269269
Assert.Equal(
270270
"Source text contains more than 2 nodes. Parsing aborted.",
271-
Assert.Throws<SyntaxException>(Act).Message);
271+
Assert.Throws<FieldSelectionMapSyntaxException>(Act).Message);
272272
}
273273
}

src/HotChocolate/Fusion-vnext/test/Fusion.Language.Tests/FieldSelectionMapReaderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void Act()
188188
// assert
189189
Assert.Equal(
190190
"Source text contains more than 2 tokens. Parsing aborted.",
191-
Assert.Throws<SyntaxException>(Act).Message);
191+
Assert.Throws<FieldSelectionMapSyntaxException>(Act).Message);
192192
}
193193

194194
[Fact]
@@ -205,6 +205,6 @@ static void Act()
205205
// assert
206206
Assert.Equal(
207207
"Unexpected character `*`.",
208-
Assert.Throws<SyntaxException>(Act).Message);
208+
Assert.Throws<FieldSelectionMapSyntaxException>(Act).Message);
209209
}
210210
}

0 commit comments

Comments
 (0)