From d0f674a4e5b049f2467fed8d021006c75c0365bf Mon Sep 17 00:00:00 2001 From: BlueSkeye_cp <7a9a8e0be1356805ba39aaefd2f72a2ce9bd2015XwR8pJkz> Date: Mon, 8 Oct 2012 16:30:27 +0000 Subject: [PATCH] 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. --- XSharp/source/XSharp.Test/MainForm.cs | 27 ++++++++++++------- .../Compiler/Cosmos.XSharp/TokenPatterns.cs | 7 ++++- .../VSIP/Cosmos.VS.XSharp/FileGenerator.cs | 12 ++++++--- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/XSharp/source/XSharp.Test/MainForm.cs b/XSharp/source/XSharp.Test/MainForm.cs index 05df47b84..e81a16820 100644 --- a/XSharp/source/XSharp.Test/MainForm.cs +++ b/XSharp/source/XSharp.Test/MainForm.cs @@ -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(); } } } diff --git a/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs b/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs index 3e2840f53..02c7be2d8 100644 --- a/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs +++ b/source2/Compiler/Cosmos.XSharp/TokenPatterns.cs @@ -817,7 +817,12 @@ namespace Cosmos.Compiler.XSharp { /// pattern reserved syntax. /// The associated code transformation handler. 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); } diff --git a/source2/VSIP/Cosmos.VS.XSharp/FileGenerator.cs b/source2/VSIP/Cosmos.VS.XSharp/FileGenerator.cs index 43fbe895b..7cf258be0 100644 --- a/source2/VSIP/Cosmos.VS.XSharp/FileGenerator.cs +++ b/source2/VSIP/Cosmos.VS.XSharp/FileGenerator.cs @@ -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(); } } }