Skip to content

Commit

Permalink
prevent stage information from getting lost in the log
Browse files Browse the repository at this point in the history
  • Loading branch information
itsankit-google committed Jan 30, 2025
1 parent 71536cc commit 9f20a76
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package io.cdap.cdap.internal.app.runtime;

import com.google.common.base.Throwables;
import com.google.common.util.concurrent.Service;
import io.cdap.cdap.api.exception.WrappedStageException;
import io.cdap.cdap.app.runtime.ProgramController;
import io.cdap.cdap.common.conf.Constants;
import io.cdap.cdap.common.logging.Loggers;
Expand Down Expand Up @@ -94,7 +94,7 @@ public void running() {

@Override
public void failed(Service.State from, Throwable failure) {
Throwable rootCause = Throwables.getRootCause(failure);
Throwable rootCause = getRootCause(failure);
LOG.error("{} Program '{}' failed.", getProgramRunId().getType(),
getProgramRunId().getProgram(), failure);
USER_LOG.error(
Expand All @@ -104,6 +104,18 @@ public void failed(Service.State from, Throwable failure) {
error(failure);
}

private Throwable getRootCause(Throwable failure) {
Throwable cause;
while ((cause = failure.getCause()) != null) {
failure = cause;
if (WrappedStageException.class.isAssignableFrom(failure.getClass())) {
// to prevent stage information from getting lost from the log.
break;
}
}
return failure;
}

@Override
public void terminated(Service.State from) {
if (from != Service.State.STOPPING) {
Expand Down

0 comments on commit 9f20a76

Please sign in to comment.