Made error messages more accurate when we (I) mess up with X# compiler patterns. Inner exceptions are now displayed which allow for more context aware error messages.

This commit is contained in:
BlueSkeye_cp 2012-10-08 16:30:27 +00:00
parent b9e88a4e21
commit d0f674a4e5
3 changed files with 32 additions and 14 deletions

View file

@ -78,8 +78,11 @@ namespace XSharp.Test {
{
xProcess.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e)
{
errorEncountered = true;
if (null != e.Data) { resultCollector.WriteLine("ERROR : " + e.Data); }
if (null != e.Data)
{
errorEncountered = true;
resultCollector.WriteLine("ERROR : " + e.Data);
}
};
xProcess.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e)
{
@ -158,24 +161,28 @@ namespace XSharp.Test {
xOutputCode.WriteLine("============================");
xOutputCode.WriteLine("Compiling");
compilationError = !LaunchNasm(inputFile.FullName, xOutputCode);
if (compilationError) { xOutputCode.WriteLine("Some compilation error."); }
else { xOutputCode.WriteLine("Successfully compiled."); }
}
finally
{
inputFile.Refresh();
if (!compilationError)
{
xOutputCode.WriteLine("Successfully compiled.");
if (inputFile.Exists) { inputFile.Delete(); }
}
if (!compilationError && inputFile.Exists) { inputFile.Delete(); }
}
}
}
xTbox.Text = xOutputData.ToString() + "\r\n" + xOutputCode.ToString();
} catch (Exception ex) {
xTab.Text = "* " + xTab.Text;
xTbox.Text = xOutputData.ToString() + "\r\n"
+ xOutputCode.ToString() + "\r\n"
+ ex.Message + "\r\n";
StringBuilder builder = new StringBuilder();
builder.AppendLine(xOutputData.ToString());
builder.AppendLine(xOutputCode.ToString());
for (Exception e = ex; null != e; e = e.InnerException)
{
builder.AppendLine(e.Message);
}
xTbox.Text = builder.ToString();
}
}
}

View file

@ -817,7 +817,12 @@ namespace Cosmos.Compiler.XSharp {
/// pattern reserved syntax.</param>
/// <param name="aCode">The associated code transformation handler.</param>
protected void AddPattern(string aPattern, CodeFunc aCode) {
var xParser = new Parser(aPattern, 1, false, true);
Parser xParser = null;
try { new Parser(aPattern, 1, false, true); }
catch (Exception e)
{
throw new Exception(string.Format("Invalid pattern '{0}'", aPattern ?? "NULL"), e);
}
var xPattern = new Pattern(xParser.Tokens, aCode);
mPatterns.Add(xPattern);
}

View file

@ -29,9 +29,15 @@ namespace Cosmos.VS.XSharp {
xResult = xOutputData.ToString() + "\r\n"
+ xOutputCode.ToString() + "\r\n";
} catch (Exception ex) {
xResult = xOutputData.ToString() + "\r\n"
+ xOutputCode.ToString() + "\r\n"
+ ex.Message + "\r\n";
StringBuilder builder = new StringBuilder();
builder.AppendLine(xOutputData.ToString());
builder.AppendLine(xOutputCode.ToString());
for (Exception e = ex; null != e; e = e.InnerException)
{
builder.AppendLine(e.Message);
}
xResult = builder.ToString();
}
}
}