Skip to content

Commit 6fa83ef

Browse files
Fix unhandled exception System.IndexOutOfRangeException Index was outside the bounds of the array at CSharpInteractive.Core.ProcessInFlowRunner.RunAsync
1 parent 479cd3d commit 6fa83ef

File tree

2 files changed

+127
-1
lines changed

2 files changed

+127
-1
lines changed

CSharpInteractive/Composition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ private static void Setup()
216216
.Bind().To<FlowIdGenerator>()
217217
.Bind().To<TimestampUpdater>()
218218
.Bind().To((ITeamCityServiceMessages teamCityServiceMessages, IConsole console)
219-
=> teamCityServiceMessages.CreateWriter(str => console.WriteToOut((null, str + "\n"))))
219+
=> new SafeTeamCityWriter(teamCityServiceMessages.CreateWriter(str => console.WriteToOut((null, str + "\n")))))
220220
.Bind().To<ServiceMessageParser>();
221221
}
222222
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
namespace CSharpInteractive.Core;
2+
3+
using JetBrains.TeamCity.ServiceMessages;
4+
using JetBrains.TeamCity.ServiceMessages.Write.Special;
5+
6+
internal class SafeTeamCityWriter(ITeamCityWriter writer): ITeamCityWriter
7+
{
8+
private readonly object _lockObject = new();
9+
10+
public ITeamCityWriter OpenBlock(string blockName)
11+
{
12+
lock (_lockObject)
13+
{
14+
return writer.OpenBlock(blockName);
15+
}
16+
}
17+
18+
public ITeamCityWriter OpenFlow()
19+
{
20+
lock (_lockObject)
21+
{
22+
return writer.OpenFlow();
23+
}
24+
}
25+
26+
public void WriteMessage(string text)
27+
{
28+
lock (_lockObject)
29+
{
30+
writer.WriteMessage(text);
31+
}
32+
}
33+
34+
public void WriteWarning(string text)
35+
{
36+
writer.WriteWarning(text);
37+
}
38+
39+
public void WriteError(string text, string? errorDetails = null)
40+
{
41+
lock (_lockObject)
42+
{
43+
writer.WriteError(text, errorDetails);
44+
}
45+
}
46+
47+
public ITeamCityTestsSubWriter OpenTestSuite(string suiteName)
48+
{
49+
lock (_lockObject)
50+
{
51+
return writer.OpenTestSuite(suiteName);
52+
}
53+
}
54+
55+
public ITeamCityTestWriter OpenTest(string testName)
56+
{
57+
lock (_lockObject)
58+
{
59+
return writer.OpenTest(testName);
60+
}
61+
}
62+
63+
public ITeamCityWriter OpenCompilationBlock(string compilerName)
64+
{
65+
lock (_lockObject)
66+
{
67+
return writer.OpenCompilationBlock(compilerName);
68+
}
69+
}
70+
71+
public void PublishArtifact(string rules)
72+
{
73+
lock (_lockObject)
74+
{
75+
writer.PublishArtifact(rules);
76+
}
77+
}
78+
79+
public void WriteBuildNumber(string buildNumber)
80+
{
81+
lock (_lockObject)
82+
{
83+
writer.WriteBuildNumber(buildNumber);
84+
}
85+
}
86+
87+
public void WriteBuildProblem(string identity, string description)
88+
{
89+
lock (_lockObject)
90+
{
91+
writer.WriteBuildProblem(identity, description);
92+
}
93+
}
94+
95+
public void WriteBuildParameter(string parameterName, string parameterValue)
96+
{
97+
lock (_lockObject)
98+
{
99+
writer.WriteBuildParameter(parameterName, parameterValue);
100+
}
101+
}
102+
103+
public void WriteBuildStatistics(string statisticsKey, string statisticsValue)
104+
{
105+
lock (_lockObject)
106+
{
107+
writer.WriteBuildStatistics(statisticsKey, statisticsValue);
108+
}
109+
}
110+
111+
public void Dispose()
112+
{
113+
lock (_lockObject)
114+
{
115+
writer.Dispose();
116+
}
117+
}
118+
119+
public void WriteRawMessage(IServiceMessage message)
120+
{
121+
lock (_lockObject)
122+
{
123+
writer.WriteRawMessage(message);
124+
}
125+
}
126+
}

0 commit comments

Comments
 (0)