Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added log with error detail when execution failed and also rollback failed (non transactional execution). #670

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.mongock.api.exception;

/**
*
*/
public class MongockRollbackException extends MongockException {

private MongockException executionException;
private MongockException rollbackException;

public MongockRollbackException(MongockException executionException, MongockException rollbackException) {
super();
this.executionException = executionException;
this.rollbackException = rollbackException;
}

public MongockException getExecutionException() {
return executionException;
}

public MongockException getRollbackException() {
return rollbackException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.mongock.api.config.TransactionStrategy;
import io.mongock.api.config.executor.ChangeExecutorConfiguration;
import io.mongock.api.exception.MongockException;
import io.mongock.api.exception.MongockRollbackException;
import io.mongock.driver.api.common.SystemChange;
import io.mongock.driver.api.driver.ConnectionDriver;
import io.mongock.driver.api.entry.ChangeEntry;
Expand Down Expand Up @@ -125,10 +126,17 @@ protected void processSingleChangeLog(String executionId, String executionHostna
changeLog.getType().getAnnotation(SystemChange.class).updatesSystemTable()) {
loadExecutedChangeEntries();
}
} catch (Exception e) {
} catch (Exception executionEx) {
if (changeLog.isFailFast()) {
rollbackProcessedChangeSetsIfApply(executionId, executionHostname, changeSetsToRollBack);
throw e;
try {
rollbackProcessedChangeSetsIfApply(executionId, executionHostname, changeSetsToRollBack);
}
catch (Exception rollbackEx) {
MongockException mongockExecutionEx = MongockException.class.isAssignableFrom(executionEx.getClass()) ? (MongockException) executionEx : new MongockException(executionEx);
MongockException mongockRollbackEx = MongockException.class.isAssignableFrom(rollbackEx.getClass()) ? (MongockException) rollbackEx : new MongockException(rollbackEx);
throw new MongockRollbackException(mongockExecutionEx, mongockRollbackEx);
}
throw executionEx;
}
} finally {
clearChangeSetsToRollbackIfApply(isStrategyPerChangeUnit());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.mongock.runner.core.executor;

import io.mongock.api.exception.MongockException;
import io.mongock.api.exception.MongockRollbackException;
import io.mongock.driver.api.lock.LockCheckException;
import io.mongock.runner.core.event.EventPublisher;
import io.mongock.runner.core.event.result.MigrationSuccessResult;
Expand Down Expand Up @@ -68,11 +69,20 @@ public void execute() throws MongockException {
}

} catch (Exception ex) {
MongockException exWrapper = MongockException.class.isAssignableFrom(ex.getClass()) ? (MongockException) ex : new MongockException(ex);
logger.error("Error in mongock process. ABORTED OPERATION", exWrapper);
eventPublisher.publishMigrationFailedEvent(exWrapper);
throw exWrapper;

if (MongockRollbackException.class.isAssignableFrom(ex.getClass())) {
MongockRollbackException mongockRollbackException = (MongockRollbackException)ex;
logger.error("Error in mongock process. ABORTED OPERATION");
logger.error("EXECUTION error detail:", mongockRollbackException.getExecutionException());
logger.error("ROLLBACK error detail:", mongockRollbackException.getRollbackException());
eventPublisher.publishMigrationFailedEvent(mongockRollbackException.getRollbackException());
throw mongockRollbackException.getRollbackException();
}
else {
MongockException exWrapper = MongockException.class.isAssignableFrom(ex.getClass()) ? (MongockException) ex : new MongockException(ex);
logger.error("Error in mongock process. ABORTED OPERATION", exWrapper);
eventPublisher.publishMigrationFailedEvent(exWrapper);
throw exWrapper;
}
}
}
}
Expand Down
Loading