Skip to content

Commit bdfa7d4

Browse files
committed
Log error message of protogen.exe so user knows what's wrong
1 parent 6efd3eb commit bdfa7d4

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

ProtoBuf.MSBuildTask/ProtoGen.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,52 @@ public override bool Execute()
4343
}
4444

4545
Log.LogCommandLine(ProtoGenExecutable + " " + sb.ToString());
46-
var process = Process.Start(new ProcessStartInfo(ProtoGenExecutable, sb.ToString()) { CreateNoWindow = true, UseShellExecute = false });
46+
var process = Process.Start(new ProcessStartInfo(ProtoGenExecutable, sb.ToString()) { CreateNoWindow = true, UseShellExecute = false, RedirectStandardError = true });
47+
string error = process.StandardError.ReadToEnd();
4748
process.WaitForExit();
49+
if (process.ExitCode == 0)
50+
{
51+
if (error.Length > 0)
52+
Log.LogWarning(error);
53+
}
54+
else
55+
{
56+
Log.LogError("protogen failed with exit code {0}", process.ExitCode);
57+
var reader = new StringReader(error);
58+
string line;
59+
while ((line = reader.ReadLine()) != null)
60+
{
61+
bool parsed = false;
62+
do
63+
{
64+
int i1 = line.IndexOf(':');
65+
if (i1 < 0)
66+
continue;
67+
int i2 = line.IndexOf(':', i1 + 1);
68+
if (i2 < 0)
69+
continue;
70+
int i3 = line.IndexOf(':', i2 + 1);
71+
if (i3 < 0)
72+
continue;
73+
string filename = line.Substring(0, i1);
74+
string slineNum = line.Substring(i1 + 1, i2 - i1 - 1);
75+
int lineNum;
76+
if (!int.TryParse(slineNum, out lineNum))
77+
continue;
78+
string scolNum = line.Substring(i2 + 1, i3 - i2 - 1);
79+
int colNum;
80+
if (!int.TryParse(scolNum, out colNum))
81+
continue;
82+
string message = i3 + 1 < line.Length ? line.Substring(i3 + 1) : "";
83+
Log.LogError("", "", "", filename, lineNum, colNum, lineNum, colNum, message);
84+
parsed = true;
85+
}
86+
while (false);
87+
if (!parsed)
88+
Log.LogError("protogen error: {0}", line);
89+
}
90+
}
91+
4892
list.Add(new TaskItem(output));
4993
GeneratedCodeFiles = list.ToArray();
5094
return true;

0 commit comments

Comments
 (0)