Skip to content
Draft
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
Expand Up @@ -2,7 +2,10 @@

import java.lang.reflect.*;
import java.util.*;
import java.util.logging.Level;

import com.microsoft.azure.functions.worker.WorkerLogManager;
import com.microsoft.azure.functions.worker.exception.UserFunctionException;
import org.apache.commons.lang3.exception.*;

interface InstanceSupplier {
Expand All @@ -18,8 +21,12 @@ private JavaMethodInvokeInfo() {}

Object invoke(InstanceSupplier instanceSupplier) throws Exception {
Object instance = Modifier.isStatic(this.m.getModifiers()) ? null : instanceSupplier.get();

try {
return this.m.invoke(instance, this.args);
} catch (InvocationTargetException ex) {
WorkerLogManager.getSystemLogger().severe(String.format("exception happens in customer function: %s : %s", this.m.getName(), ex.getMessage()));
return ExceptionUtils.rethrow(new UserFunctionException(this.m.getName(), ex.getCause()));
} catch (Exception ex) {
return ExceptionUtils.rethrow(ex);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.microsoft.azure.functions.worker.exception;

public class UserFunctionException extends WorkerBaseException{

private static final String message = "exception happens in customer function: ";
public UserFunctionException() {
super();
}

public UserFunctionException(String message) {
super(message);
}

public UserFunctionException(String input, Throwable cause) {
super(message + input, cause);
}

public UserFunctionException(Throwable cause) {
super(cause);
}

public UserFunctionException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.microsoft.azure.functions.worker.exception;

public class WorkerBaseException extends RuntimeException{
public WorkerBaseException() {
super();
}

public WorkerBaseException(String message) {
super(message);
}

public WorkerBaseException(String message, Throwable cause) {
super(message, cause);
}

public WorkerBaseException(Throwable cause) {
super(cause);
}

public WorkerBaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.microsoft.azure.functions.worker.handler;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.logging.*;

import com.google.protobuf.*;
import com.microsoft.azure.functions.worker.exception.UserFunctionException;
import org.apache.commons.lang3.*;
import org.apache.commons.lang3.exception.*;

Expand Down Expand Up @@ -46,10 +48,17 @@ public void handle() {
if (statusMessage != null) {
this.getLogger().info(statusMessage);
}
} catch (UserFunctionException ex) {
status = StatusResult.Status.Failure;
statusMessage = ExceptionUtils.getRootCauseMessage(ex);
rpcException = RpcException.newBuilder().setMessage(statusMessage).setIsUserException(true)
.setType(ExceptionUtils.getRootCause(ex).getClass().getName())
.setStackTrace(ExceptionUtils.getStackTrace(ex)).build();
} catch (Exception ex) {
status = StatusResult.Status.Failure;
statusMessage = ExceptionUtils.getRootCauseMessage(ex);
rpcException = RpcException.newBuilder().setMessage(statusMessage).setStackTrace(ExceptionUtils.getStackTrace(ex)).build();
rpcException = RpcException.newBuilder().setMessage(statusMessage)
.setStackTrace(ExceptionUtils.getStackTrace(ex)).build();
}
if (this.responseStatusMarshaller != null) {
StatusResult.Builder result = StatusResult.newBuilder().setStatus(status).setResult(statusMessage);
Expand Down