Skip to content

Commit

Permalink
Add utils method for handle system exit
Browse files Browse the repository at this point in the history
  • Loading branch information
warunalakshitha committed Dec 10, 2024
1 parent 4ab4995 commit 539e396
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.isEnum;
import static io.ballerina.stdlib.graphql.runtime.engine.EngineUtils.isIgnoreType;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.INTERNAL_NODE;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.handleBErrorAndExit;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.isContext;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.isField;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.isFileUpload;
Expand Down Expand Up @@ -545,12 +546,7 @@ private void addConstraintValidationErrors(Environment environment, BArray error
environment.getRuntime().callMethod(this.responseGenerator, ADD_CONSTRAINT_ERRORS_METHOD, null,
arguments);
} catch (BError bError) {
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
handleBErrorAndExit(bError);
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BTypedesc;

import static io.ballerina.stdlib.graphql.runtime.utils.Utils.handleBErrorAndExit;

/**
* This class provides native implementations of the Ballerina DataLoader class.
*/
Expand All @@ -38,12 +40,7 @@ public static Object get(Environment env, BObject dataLoader, Object key, BTyped
try {
return env.getRuntime().callMethod(dataLoader, DATA_LOADER_PROCESSES_GET_METHOD_NAME, null, paramFeed);
} catch (BError bError) {
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
handleBErrorAndExit(bError);
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.ERROR_TYPE;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.INTERNAL_NODE;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.createError;
import static io.ballerina.stdlib.graphql.runtime.utils.Utils.handleBErrorAndExit;

/**
* This handles Ballerina GraphQL Engine.
Expand Down Expand Up @@ -135,12 +136,7 @@ private static Object getResultObject(Environment environment, BObject context,
try {
return callResourceMethod(environment.getRuntime(), service, methodName, args);
} catch (BError bError) {
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
handleBErrorAndExit(bError);
}
return null;
});
Expand Down Expand Up @@ -187,12 +183,7 @@ public static Object executeInterceptor(Environment environment, BObject interce
try {
return callResourceMethod(environment.getRuntime(), interceptor, remoteMethod.getName(), arguments);
} catch (BError bError) {
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
handleBErrorAndExit(bError);
}
return null;
});
Expand Down Expand Up @@ -289,12 +280,7 @@ public static void executePrefetchMethod(Environment environment, BObject contex
try {
return callResourceMethod(environment.getRuntime(), service, resourceMethod.getName(), arguments);
} catch (BError bError) {
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
handleBErrorAndExit(bError);
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,13 @@ private static boolean hasExpectedModuleName(Type type, String expectedModuleNam
public static BString getHashCode(BObject object) {
return StringUtils.fromString(Integer.toString(object.hashCode()));
}

public static void handleBErrorAndExit(BError bError) {
bError.printStackTrace();
// Service level `panic` is captured in this method.
// Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the
// application.
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
}
}
2 changes: 2 additions & 0 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
</Match>
<Match>
<And>
<Class name="io.ballerina.stdlib.graphql.runtime.utils.Utils" />
<Method name = "handleBErrorAndExit" />
<Bug pattern="DM_EXIT" />
</And>
</Match>
Expand Down

0 comments on commit 539e396

Please sign in to comment.