Пример #1
0
        private void HandleRuntimeError(SprakRuntimeException e, IComputerScreen screen)
        {
            // First, consider assertions - the error could be expected, in which case the executor can log
            // a success and move on. Or it could be a different error to what was expected, so that the
            // assertion fails.

            ErrorTest test = null;

            if (Instructions.HasCurrent)
            {
                test = Instructions.CurrentInfo.Tests?.OfType <ErrorTest>().FirstOrDefault();
            }

            if (test != null && _runTestCommands)
            {
                if (test.ErrorName == e.Template.Name)
                {
                    // Success! The error was expected.
                    screen.SetPrintColor(Color.Green);
                    screen.Print($"Assertion passed: error '{test.ErrorName}' occured.");
                    Instructions.Step();
                }
                // This name comparison is a bit awkward, but doesn't seem worth rewriting
                else if (e.Template.Name != nameof(Messages.AssertionFailed))
                {
                    // An error occurred as expected, but it was the wrong one!
                    screen.SetPrintColor(Color.Red);
                    screen.Print("Runtime error: Assertion Failed.");
                    screen.Print($"Expected error: '{test.ErrorName}'. Found error: '{e.Template.Name}'");
                    screen.Print("Found error details:");

                    DisplayRuntimeError(e, screen);
                    _breakRequested = true;
                }
                else
                {
                    DisplayRuntimeError(e, screen);
                    _breakRequested = true;
                }
            }
            else
            {
                // If there was no error test, then this is a runtime error
                // to display and pause on.
                DisplayRuntimeError(e, screen);
                _breakRequested = true;
            }

            screen.SetPrintColor(Color.White);
        }
Пример #2
0
        private void DisplayRuntimeError(SprakRuntimeException e, IComputerScreen screen)
        {
            screen.SetPrintColor(Color.Red);
            screen.Print("Runtime Error: " + e.Template.Title);

            screen.Print("Detail: " + e.Template.Render(e.Args));

            string sourceTrace = GetCurrentTrace();

            if (sourceTrace != null)
            {
                screen.Print("At: " + sourceTrace);
            }

            screen.Print("Execution paused at error location.");
            screen.SetPrintColor(Color.White);
        }