Search in sources :

Example 16 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class SkyframeActionExecutor method printError.

/**
   * For the action 'action' that failed due to 'ex' with the output
   * 'actionOutput', notify the user about the error. To notify the user, the
   * method first displays the output of the action and then reports an error
   * via the reporter. The method ensures that the two messages appear next to
   * each other by locking the outErr object where the output is displayed.
   *
   * @param message The reason why the action failed
   * @param action The action that failed, must not be null.
   * @param actionOutput The output of the failed Action.
   *     May be null, if there is no output to display
   */
private void printError(String message, Action action, FileOutErr actionOutput) {
    synchronized (reporter) {
        if (keepGoing) {
            message = "Couldn't " + describeAction(action) + ": " + message;
        }
        Event event = Event.error(action.getOwner().getLocation(), message);
        dumpRecordedOutErr(event, actionOutput);
        recordExecutionError();
    }
}
Also used : ActionStartedEvent(com.google.devtools.build.lib.actions.ActionStartedEvent) ActionCompletionEvent(com.google.devtools.build.lib.actions.ActionCompletionEvent) ActionMiddlemanEvent(com.google.devtools.build.lib.actions.ActionMiddlemanEvent) CachedActionEvent(com.google.devtools.build.lib.actions.CachedActionEvent) ActionExecutedEvent(com.google.devtools.build.lib.actions.ActionExecutedEvent) Event(com.google.devtools.build.lib.events.Event)

Example 17 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class EventCollectorTest method collectsEvents.

@Test
public void collectsEvents() {
    EventCollector collector = new EventCollector();
    collector.handle(event);
    Iterator<Event> collectedEventIt = collector.iterator();
    Event onlyEvent = collectedEventIt.next();
    assertEquals(event.getMessage(), onlyEvent.getMessage());
    assertSame(location, onlyEvent.getLocation());
    assertEquals(event.getKind(), onlyEvent.getKind());
    assertEquals(event.getLocation().getStartOffset(), onlyEvent.getLocation().getStartOffset());
    assertFalse(collectedEventIt.hasNext());
}
Also used : Event(com.google.devtools.build.lib.events.Event) Test(org.junit.Test)

Example 18 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class ValidationTest method testDollarErrorDoesNotLeak.

@Test
public void testDollarErrorDoesNotLeak() throws Exception {
    setFailFast(false);
    parseFile("def GenerateMapNames():", "  a = 2", "  b = [3, 4]", "  if a not b:", "    print(a)");
    assertContainsError("syntax error at 'b': expected in");
    // It should not be used in error messages.
    for (Event event : getEventCollector()) {
        assertThat(event.getMessage()).doesNotContain("$error$");
    }
}
Also used : Event(com.google.devtools.build.lib.events.Event) Test(org.junit.Test)

Example 19 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class BuildFileASTTest method testImplicitStringConcatenationAcrossLinesIsIllegal.

@Test
public void testImplicitStringConcatenationAcrossLinesIsIllegal() throws Exception {
    setFailFast(false);
    BuildFileAST buildFileAST = parseBuildFile("a = 'foo'\n  'bar'");
    Event event = assertContainsError("indentation error");
    assertEquals("/a/build/file/BUILD", event.getLocation().getPath().toString());
    assertEquals(2, event.getLocation().getStartLineAndColumn().getLine());
    assertEquals(2, event.getLocation().getStartLineAndColumn().getColumn());
    assertTrue(buildFileAST.containsErrors());
}
Also used : Event(com.google.devtools.build.lib.events.Event) Test(org.junit.Test)

Example 20 with Event

use of com.google.devtools.build.lib.events.Event in project bazel by bazelbuild.

the class BuildFileASTTest method testFailsIfNewlinesAreMissing.

@Test
public void testFailsIfNewlinesAreMissing() throws Exception {
    setFailFast(false);
    BuildFileAST buildFileAST = parseBuildFile("foo() bar() something = baz() bar()");
    Event event = assertContainsError("syntax error at \'bar\': expected newline");
    assertEquals("/a/build/file/BUILD", event.getLocation().getPath().toString());
    assertEquals(1, event.getLocation().getStartLineAndColumn().getLine());
    assertTrue(buildFileAST.containsErrors());
}
Also used : Event(com.google.devtools.build.lib.events.Event) Test(org.junit.Test)

Aggregations

Event (com.google.devtools.build.lib.events.Event)28 Test (org.junit.Test)15 EventHandler (com.google.devtools.build.lib.events.EventHandler)4 EventBus (com.google.common.eventbus.EventBus)3 ActionExecutedEvent (com.google.devtools.build.lib.actions.ActionExecutedEvent)3 Reporter (com.google.devtools.build.lib.events.Reporter)3 MoreAsserts.assertContainsEvent (com.google.devtools.build.lib.testutil.MoreAsserts.assertContainsEvent)3 StringValue (com.google.devtools.build.skyframe.GraphTester.StringValue)3 ArrayList (java.util.ArrayList)3 ActionCompletionEvent (com.google.devtools.build.lib.actions.ActionCompletionEvent)2 ActionMiddlemanEvent (com.google.devtools.build.lib.actions.ActionMiddlemanEvent)2 ActionStartedEvent (com.google.devtools.build.lib.actions.ActionStartedEvent)2 CachedActionEvent (com.google.devtools.build.lib.actions.CachedActionEvent)2 SpawnActionContext (com.google.devtools.build.lib.actions.SpawnActionContext)2 EventCollector (com.google.devtools.build.lib.events.EventCollector)2 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Supplier (com.google.common.base.Supplier)1 ImmutableList (com.google.common.collect.ImmutableList)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1