Skip to content

Commit

Permalink
Merge pull request #40898 from phillip-kruger/dev-ui-error
Browse files Browse the repository at this point in the history
Fix onError for Dev UI streaming
  • Loading branch information
phillip-kruger authored May 30, 2024
2 parents 8d30b16 + 000f6c7 commit ba50144
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,14 @@ void createBuildTimeData(BuildProducer<BuildTimeConstBuildItem> buildTimeConstPr
ExtensionsBuildItem extensionsBuildItem,
NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem,
LaunchModeBuildItem launchModeBuildItem,
Optional<EffectiveIdeBuildItem> effectiveIdeBuildItem) {
Optional<EffectiveIdeBuildItem> effectiveIdeBuildItem,
DevUIConfig devUIConfig) {

BuildTimeConstBuildItem internalBuildTimeData = new BuildTimeConstBuildItem(AbstractDevUIBuildItem.DEV_UI);

addThemeBuildTimeData(internalBuildTimeData, themeVarsProducer);
addMenuSectionBuildTimeData(internalBuildTimeData, internalPages, extensionsBuildItem);
addFooterTabBuildTimeData(internalBuildTimeData, extensionsBuildItem);
addFooterTabBuildTimeData(internalBuildTimeData, extensionsBuildItem, devUIConfig);
addVersionInfoBuildTimeData(internalBuildTimeData, curateOutcomeBuildItem, nonApplicationRootPathBuildItem);
addIdeBuildTimeData(internalBuildTimeData, effectiveIdeBuildItem, launchModeBuildItem);
buildTimeConstProducer.produce(internalBuildTimeData);
Expand Down Expand Up @@ -490,7 +491,7 @@ private void addMenuSectionBuildTimeData(BuildTimeConstBuildItem internalBuildTi
}

private void addFooterTabBuildTimeData(BuildTimeConstBuildItem internalBuildTimeData,
ExtensionsBuildItem extensionsBuildItem) {
ExtensionsBuildItem extensionsBuildItem, DevUIConfig devUIConfig) {
// Add the Footer tabs
@SuppressWarnings("unchecked")
List<Page> footerTabs = new ArrayList();
Expand All @@ -509,7 +510,7 @@ private void addFooterTabBuildTimeData(BuildTimeConstBuildItem internalBuildTime
footerTabs.add(testLog);

// This is only needed when extension developers work on an extension, so we only included it if you build from source.
if (Version.getVersion().equalsIgnoreCase("999-SNAPSHOT")) {
if (Version.getVersion().equalsIgnoreCase("999-SNAPSHOT") || devUIConfig.showJsonRpcLog) {
Page devUiLog = Page.webComponentPageBuilder().internal()
.namespace("devui-jsonrpcstream")
.title("Dev UI")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public class DevUIConfig {
@ConfigItem(defaultValue = "50")
public int historySize;

/**
* Show the JsonRPC Log. Useful for extension developers
*/
@ConfigItem(defaultValue = "false")
public boolean showJsonRpcLog;

/**
* CORS configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,19 +249,22 @@ export class JsonRpc {
JsonRpc.webSocket.onmessage = function (event) {
var response = JSON.parse(event.data);
var devUiResponse = response.result;

var devUiError = response.error;
if (!devUiResponse && response.error) {
if (JsonRpc.promiseQueue.has(response.id)) {
var saved = JsonRpc.promiseQueue.get(response.id);
var promise = saved.promise;
var log = saved.log;

promise.reject_ex(response);
JsonRpc.promiseQueue.delete(response.id);
if (log) {
var jsonrpcpayload = JSON.stringify(response);
JsonRpc.dispatchMessageLogEntry(Level.Error, MessageDirection.Down, jsonrpcpayload);
JsonRpc.log(saved,response);
}else if(JsonRpc.observerQueue.has(response.id)){
var saved = JsonRpc.observerQueue.get(response.id);
var observer = saved.observer;
response.error = devUiError;
if (typeof observer.onErrorCallback === "function") {
observer.onErrorCallback(response);
}
JsonRpc.log(saved,response);
}

return;
Expand All @@ -279,31 +282,23 @@ export class JsonRpc {
if (JsonRpc.promiseQueue.has(response.id)) {
var saved = JsonRpc.promiseQueue.get(response.id);
var promise = saved.promise;
var log = saved.log;
var userData = devUiResponse.object;
response.result = userData;

promise.resolve_ex(response);
JsonRpc.promiseQueue.delete(response.id);
if(log){
var jsonrpcpayload = JSON.stringify(response);
JsonRpc.dispatchMessageLogEntry(Level.Info, MessageDirection.Down, jsonrpcpayload);
}
JsonRpc.log(saved,response);
} else {
JsonRpc.dispatchMessageLogEntry(Level.Warning, MessageDirection.Down, "Initial normal request not found [ " + devUiResponse.messageType + "], " + event.data);
}
} else if (messageType === MessageType.SubscriptionMessage.toString()) { // Subscription message
if (JsonRpc.observerQueue.has(response.id)) {
var saved = JsonRpc.observerQueue.get(response.id);
var observer = saved.observer;
var log = saved.log;
var userData = devUiResponse.object;
response.result = userData;
observer.onNextCallback(response);
if(log){
var jsonrpcpayload = JSON.stringify(response);
JsonRpc.dispatchMessageLogEntry(Level.Info, MessageDirection.Down, jsonrpcpayload);
}
JsonRpc.log(saved,response);
} else {
// Let's cancel as we do not have someone interested in this anymore
JsonRpc.cancelSubscription(response.id);
Expand Down Expand Up @@ -342,4 +337,12 @@ export class JsonRpc {
const event = new CustomEvent('jsonRPCLogEntryEvent', {detail: logEntry});
document.dispatchEvent(event);
}

static log(o, response){
var log = o.log;
if(log){
var jsonrpcpayload = JSON.stringify(response);
JsonRpc.dispatchMessageLogEntry(Level.Info, MessageDirection.Down, jsonrpcpayload);
}
}
}

0 comments on commit ba50144

Please sign in to comment.