Skip to content

Commit 0cc5887

Browse files
authored
Merge pull request #2470 from KathleenDollard/m-errors-in-pipelineresult
Add error tracking in PipelineResult
2 parents dd15949 + 83855a5 commit 0cc5887

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/System.CommandLine.Subsystems/PipelineResult.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4+
using System.CommandLine.Parsing;
5+
46
namespace System.CommandLine;
57

68
public class PipelineResult(ParseResult? parseResult, string rawInput, Pipeline? pipeline, ConsoleHack? consoleHack = null)
79
{
10+
private readonly List<ParseError> errors = [];
811
public ParseResult? ParseResult { get; } = parseResult;
912
public string RawInput { get; } = rawInput;
1013
public Pipeline Pipeline { get; } = pipeline ?? Pipeline.CreateEmpty();
@@ -13,6 +16,22 @@ public class PipelineResult(ParseResult? parseResult, string rawInput, Pipeline?
1316
public bool AlreadyHandled { get; set; }
1417
public int ExitCode { get; set; }
1518

19+
public void AddErrors(IEnumerable<ParseError> errors)
20+
{
21+
if (errors is not null)
22+
{
23+
this.errors.AddRange(errors);
24+
}
25+
}
26+
27+
public void AddError(ParseError error)
28+
=> errors.Add(error);
29+
30+
public IEnumerable<ParseError> GetErrors(bool excludeParseErrors = false)
31+
=> excludeParseErrors || ParseResult is null
32+
? errors
33+
: ParseResult.Errors.Concat(errors);
34+
1635
public void NotRun(ParseResult? parseResult)
1736
{
1837
// no op because defaults are false and 0

0 commit comments

Comments
 (0)