@xuda.io/xuda-worker-bundle 1.3.2697 → 1.3.2699

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +369 -75
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5231,7 +5231,17 @@ func.datasource.run_events_functions = async function (SESSION_ID, dataSourceSes
5231
5231
  resolve(job_num);
5232
5232
  }
5233
5233
  if (i > 200) {
5234
- console.error('deadlock detected');
5234
+ func.utils.report_issue(SESSION_ID, {
5235
+ code: 'RUN_MSG_DSC_050',
5236
+ source: 'func.datasource.run_events_functions',
5237
+ message: 'deadlock detected',
5238
+ type: 'E',
5239
+ details: {
5240
+ job_num,
5241
+ event_id,
5242
+ dsSessionP,
5243
+ },
5244
+ });
5235
5245
  clearInterval(interval);
5236
5246
  resolve(job_num);
5237
5247
  }
@@ -6642,7 +6652,19 @@ func.datasource.get_value = async function (SESSION_ID, fieldIdP, dsSessionP, ro
6642
6652
  }
6643
6653
  }
6644
6654
  } catch (err) {
6645
- // console.error(err);
6655
+ await func.utils.report_issue(SESSION_ID, {
6656
+ code: 'RUN_MSG_DSC_060',
6657
+ source: 'Datasource get value',
6658
+ message: 'Datasource row lookup failed',
6659
+ type: 'W',
6660
+ err,
6661
+ details: {
6662
+ dsSessionP,
6663
+ field_id: _field_id,
6664
+ record_id: recordId,
6665
+ },
6666
+ skip_log: false,
6667
+ });
6646
6668
  }
6647
6669
  }
6648
6670
 
@@ -6652,7 +6674,21 @@ func.datasource.get_value = async function (SESSION_ID, fieldIdP, dsSessionP, ro
6652
6674
  if (typeof _ds.data_feed?.rows?.[row_idx]?.[_field_id] !== 'undefined') {
6653
6675
  return await return_value(_field_id, _ds.data_feed.rows[row_idx][_field_id]);
6654
6676
  }
6655
- } catch (error) {}
6677
+ } catch (error) {
6678
+ await func.utils.report_issue(SESSION_ID, {
6679
+ code: 'RUN_MSG_DSC_060',
6680
+ source: 'Datasource get value',
6681
+ message: 'Datasource row lookup failed',
6682
+ type: 'W',
6683
+ err: error,
6684
+ details: {
6685
+ dsSessionP,
6686
+ field_id: _field_id,
6687
+ record_id: _ds.currentRecordId,
6688
+ },
6689
+ skip_log: false,
6690
+ });
6691
+ }
6656
6692
 
6657
6693
  return await search_in_parameters(fieldIdP);
6658
6694
  };
@@ -7969,11 +8005,213 @@ func.utils.get_drive_url = function (SESSION_ID, val, wrap) {
7969
8005
  }
7970
8006
  };
7971
8007
 
8008
+ func.utils._error_registry_module = func.utils._error_registry_module || null;
8009
+ func.utils._error_registry_pending = func.utils._error_registry_pending || null;
8010
+
8011
+ func.utils.get_error_registry = async function (SESSION_ID) {
8012
+ if (func.utils._error_registry_module) {
8013
+ return func.utils._error_registry_module;
8014
+ }
8015
+
8016
+ if (func.utils._error_registry_pending) {
8017
+ return await func.utils._error_registry_pending;
8018
+ }
8019
+
8020
+ if (!SESSION_ID || !SESSION_OBJ?.[SESSION_ID]) {
8021
+ return null;
8022
+ }
8023
+
8024
+ func.utils._error_registry_pending = func.common
8025
+ .get_module(SESSION_ID, 'xuda-error-registry-module.mjs')
8026
+ .then((module) => {
8027
+ func.utils._error_registry_module = module;
8028
+ return module;
8029
+ })
8030
+ .catch((err) => {
8031
+ console.warn('XUDA WARNING RUN_MSG_NET_010', 'Failed to load error registry module', err);
8032
+ return null;
8033
+ })
8034
+ .finally(() => {
8035
+ func.utils._error_registry_pending = null;
8036
+ });
8037
+
8038
+ return await func.utils._error_registry_pending;
8039
+ };
8040
+
8041
+ func.utils._normalize_issue_severity = function (type, fallback = 'error') {
8042
+ if (!type) return fallback;
8043
+ const normalized = type.toString().toLowerCase();
8044
+ if (['w', 'warn', 'warning'].includes(normalized)) return 'warning';
8045
+ if (['i', 'info', 'log'].includes(normalized)) return 'info';
8046
+ return 'error';
8047
+ };
8048
+
8049
+ func.utils._serialize_issue_value = function (value, seen = new WeakSet()) {
8050
+ if (value instanceof Error) {
8051
+ return {
8052
+ name: value.name,
8053
+ message: value.message,
8054
+ stack: value.stack,
8055
+ cause: value.cause,
8056
+ };
8057
+ }
8058
+
8059
+ if (typeof value === 'undefined' || value === null) {
8060
+ return value;
8061
+ }
8062
+
8063
+ if (typeof value === 'function') {
8064
+ return `[Function ${value.name || 'anonymous'}]`;
8065
+ }
8066
+
8067
+ if (typeof value !== 'object') {
8068
+ return value;
8069
+ }
8070
+
8071
+ if (seen.has(value)) {
8072
+ return '[Circular]';
8073
+ }
8074
+
8075
+ seen.add(value);
8076
+
8077
+ if (Array.isArray(value)) {
8078
+ return value.map((item) => func.utils._serialize_issue_value(item, seen));
8079
+ }
8080
+
8081
+ const ret = {};
8082
+ for (const [key, val] of Object.entries(value)) {
8083
+ ret[key] = func.utils._serialize_issue_value(val, seen);
8084
+ }
8085
+ return ret;
8086
+ };
8087
+
8088
+ func.utils._stringify_issue_message = function (value) {
8089
+ if (typeof value === 'undefined' || value === null) {
8090
+ return '';
8091
+ }
8092
+
8093
+ if (typeof value === 'string') {
8094
+ return value;
8095
+ }
8096
+
8097
+ if (value instanceof Error) {
8098
+ return value.message || value.toString();
8099
+ }
8100
+
8101
+ try {
8102
+ return JSON.stringify(func.utils._serialize_issue_value(value));
8103
+ } catch (error) {
8104
+ return value?.toString?.() || '';
8105
+ }
8106
+ };
8107
+
8108
+ func.utils._build_fallback_issue_definition = function (payload = {}) {
8109
+ const code = payload.code || 'RUN_MSG_GEN_000';
8110
+ const severity = func.utils._normalize_issue_severity(payload.type || payload.severity, code.startsWith('CHK_MSG_') ? 'warning' : 'error');
8111
+
8112
+ return {
8113
+ code,
8114
+ title: payload.title || (code.startsWith('CHK_MSG_') ? 'Studio Checker Validation Issue' : 'Runtime Error'),
8115
+ severity,
8116
+ domain: code.startsWith('CHK_MSG_') ? 'checker' : 'runtime',
8117
+ category: payload.category || 'general',
8118
+ summary: payload.message || 'The runtime reported an issue.',
8119
+ help_slug: payload.help_slug || code.toLowerCase().replace(/_/g, '-'),
8120
+ };
8121
+ };
8122
+
8123
+ func.utils.report_issue = async function (SESSION_ID, payload = {}) {
8124
+ const err = payload.err instanceof Error ? payload.err : payload.error instanceof Error ? payload.error : null;
8125
+ const source = payload.source || payload.method || 'runtime';
8126
+ const message = func.utils._stringify_issue_message(
8127
+ typeof payload.message !== 'undefined' ? payload.message : typeof payload.msg !== 'undefined' ? payload.msg : err || payload.details || 'Unknown runtime issue',
8128
+ );
8129
+
8130
+ try {
8131
+ const registry = await func.utils.get_error_registry(SESSION_ID);
8132
+ const registry_payload = {
8133
+ code: payload.code,
8134
+ source,
8135
+ message,
8136
+ type: payload.type || payload.severity,
8137
+ err,
8138
+ details: payload.details,
8139
+ category: payload.category,
8140
+ };
8141
+
8142
+ let definition = null;
8143
+ if (registry?.get_error_definition && payload.code) {
8144
+ definition = registry.get_error_definition(payload.code, registry_payload);
8145
+ }
8146
+ if (!definition && registry?.get_runtime_report_definition) {
8147
+ definition = registry.get_runtime_report_definition(registry_payload);
8148
+ }
8149
+ if (!definition) {
8150
+ definition = func.utils._build_fallback_issue_definition({
8151
+ ...payload,
8152
+ source,
8153
+ message,
8154
+ });
8155
+ }
8156
+
8157
+ const severity = func.utils._normalize_issue_severity(payload.type || payload.severity, definition.severity || 'error');
8158
+ const error_code = definition.code || payload.code || 'RUN_MSG_GEN_000';
8159
+ const error_title = definition.title || payload.title || 'Runtime Error';
8160
+ const help_slug = definition.help_slug || error_code.toLowerCase().replace(/_/g, '-');
8161
+ const console_method = severity === 'warning' ? 'warn' : severity === 'info' ? 'log' : 'error';
8162
+ const _session = SESSION_OBJ?.[SESSION_ID];
8163
+ const report = {
8164
+ error_code,
8165
+ error_title,
8166
+ help_slug,
8167
+ severity,
8168
+ error_domain: definition.domain || 'runtime',
8169
+ error_category: definition.category || payload.category || 'general',
8170
+ source,
8171
+ message,
8172
+ stack: err?.stack || null,
8173
+ app_id: _session?.app_id || payload.app_id || null,
8174
+ session_id: SESSION_ID || null,
8175
+ worker: !!glb?.IS_WORKER,
8176
+ summary: definition.summary || message,
8177
+ };
8178
+ const details = {
8179
+ report,
8180
+ error: func.utils._serialize_issue_value(err),
8181
+ context: func.utils._serialize_issue_value(payload.details),
8182
+ extra: func.utils._serialize_issue_value(payload.extra),
8183
+ };
8184
+ const console_prefix = `XUDA ${console_method.toUpperCase()} ${error_code}`;
8185
+ const console_summary = `${error_title}: ${source}${message ? ' | ' + message : ''}`;
8186
+
8187
+ if (glb?.debug_js && console.groupCollapsed) {
8188
+ console.groupCollapsed(console_prefix, console_summary);
8189
+ console[console_method](report);
8190
+ if (details.context) console.log('context', details.context);
8191
+ if (err) console.error(err);
8192
+ console.groupEnd();
8193
+ } else {
8194
+ console[console_method](console_prefix, console_summary, {
8195
+ help_slug,
8196
+ });
8197
+ }
8198
+
8199
+ if (!payload.skip_log && SESSION_ID && _session) {
8200
+ await func.utils.write_log(SESSION_ID, source, message || error_title, console_method, payload.log_source || 'runtime', details, report);
8201
+ }
8202
+
8203
+ return report;
8204
+ } catch (report_err) {
8205
+ console.error('XUDA ERROR RUN_MSG_GEN_000', 'Failed to report runtime issue', report_err, {
8206
+ source,
8207
+ message,
8208
+ payload,
8209
+ });
8210
+ return null;
8211
+ }
8212
+ };
8213
+
7972
8214
  func.utils.debug_report = async function (SESSION_ID, sourceP, msgP, typeP, errP, objP) {
7973
- var _session = SESSION_OBJ[SESSION_ID];
7974
- var details = [sourceP];
7975
- if (errP) details.push(errP);
7976
- if (objP) details.push(objP);
7977
8215
  if (!typeP || typeP === 'E') {
7978
8216
  setTimeout(() => {
7979
8217
  // if (
@@ -7985,52 +8223,15 @@ func.utils.debug_report = async function (SESSION_ID, sourceP, msgP, typeP, errP
7985
8223
  // func.index.delete_pouch(SESSION_ID);
7986
8224
  // }
7987
8225
  }, 1000);
7988
-
7989
- // // temp inactive cause to loop
7990
-
7991
- // func.utils.alerts.invoke(
7992
- // SESSION_ID,
7993
- // "system_msg",
7994
- // "SYS_MSG_1240",
7995
- // "debug",
7996
- // null,
7997
- // msgP,
7998
- // sourceP //arguments.callee.caller.toString()- deprecated es6
7999
- // );
8000
- console.error('XUDA', 'ERROR', sourceP, msgP, details);
8001
-
8002
- if (typeof IS_API_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
8003
- return __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id, 'error', 'worker', 'runtime', msgP, null, objP, sourceP);
8004
- }
8005
-
8006
- if (glb.IS_WORKER) {
8007
- let obj = {
8008
- service: 'write_log',
8009
- data: msgP,
8010
- log_type: 'error',
8011
- id: STUDIO_WEBSOCKET_CONNECTION_ID,
8012
- uid: _session.USR_OBJ._id,
8013
- source: 'runtime',
8014
- app_id: _session.app_id,
8015
- gtp_token: _session.gtp_token,
8016
- app_token: _session.app_token,
8017
- };
8018
-
8019
- return func.utils.post_back_to_client(SESSION_ID, 'write_log', _session.worker_id, obj);
8020
- }
8021
-
8022
- // // temp inactive cause to loop
8023
- // if (!glb.IS_WORKER) {
8024
- // await func.common.db(SESSION_ID, "write_log", {
8025
- // client_id: _session?.SYS_GLOBAL_OBJ_CLIENT_INFO?.fingerprint,
8026
- // source: sourceP,
8027
- // log_type: "error",
8028
- // msg: msgP,
8029
- // });
8030
- // }
8031
8226
  }
8032
- if (typeP === 'W') console.warn('XUDA', 'WARNING', msgP, details);
8033
- if (typeP === 'I') console.log('XUDA', 'INFO', msgP, details);
8227
+
8228
+ await func.utils.report_issue(SESSION_ID, {
8229
+ source: sourceP,
8230
+ message: msgP,
8231
+ type: typeP,
8232
+ err: errP,
8233
+ details: objP,
8234
+ });
8034
8235
  };
8035
8236
 
8036
8237
  func.utils.request_error = function (SESSION_ID, type, e) {
@@ -9017,19 +9218,53 @@ func.utils.get_plugin_npm_cdn = async function (SESSION_ID, plugin_name, resourc
9017
9218
  return get_path(resource);
9018
9219
  };
9019
9220
 
9020
- func.utils.write_log = async function (SESSION_ID, method = '', msg = '', log_type = 'error', source = 'runtime', details) {
9221
+ func.utils.write_log = async function (SESSION_ID, method = '', msg = '', log_type = 'error', source = 'runtime', details, meta = {}) {
9021
9222
  const _session = SESSION_OBJ[SESSION_ID];
9022
- if (typeof IS_API_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
9023
- return __.rpi.write_log(_session.app_id, log_type, source, msg, details);
9024
- }
9025
-
9026
- await func.common.db(SESSION_ID, 'write_log', {
9223
+ const body = {
9027
9224
  msg,
9028
9225
  log_type,
9029
9226
  source,
9030
9227
  details,
9031
9228
  method,
9032
- });
9229
+ ...meta,
9230
+ };
9231
+
9232
+ if (typeof IS_API_SERVER !== 'undefined' || typeof IS_DOCKER !== 'undefined' || typeof IS_PROCESS_SERVER !== 'undefined') {
9233
+ return __.rpi.write_log(
9234
+ _session?.app_id,
9235
+ log_type,
9236
+ source,
9237
+ msg,
9238
+ details,
9239
+ null,
9240
+ body,
9241
+ method,
9242
+ _session?.SYS_GLOBAL_OBJ_CLIENT_INFO?.fingerprint,
9243
+ );
9244
+ }
9245
+
9246
+ if (glb.IS_WORKER) {
9247
+ let obj = {
9248
+ service: 'write_log',
9249
+ data: body,
9250
+ log_type,
9251
+ id: STUDIO_WEBSOCKET_CONNECTION_ID,
9252
+ uid: _session?.USR_OBJ?._id,
9253
+ source,
9254
+ app_id: _session?.app_id,
9255
+ gtp_token: _session?.gtp_token,
9256
+ app_token: _session?.app_token,
9257
+ };
9258
+
9259
+ return func.utils.post_back_to_client(SESSION_ID, 'write_log', _session.worker_id, obj);
9260
+ }
9261
+
9262
+ await func.common.db(SESSION_ID, 'write_log', body);
9263
+ };
9264
+
9265
+ func.utils.get_error_catalog_manifest = async function (SESSION_ID) {
9266
+ const registry = await func.utils.get_error_registry(SESSION_ID);
9267
+ return registry?.get_error_catalog_manifest?.() || null;
9033
9268
  };
9034
9269
 
9035
9270
  func.utils.get_resource_filename = function (build, filename) {
@@ -10368,7 +10603,16 @@ func.events.execute_PENDING_OPEN_URL_EVENTS = async function () {
10368
10603
 
10369
10604
  const params_obj = func.common.getObjectFromUrl(url, glb.ROOT_ELEMENT_ATTRIBUTES);
10370
10605
  if (!params_obj.prog) {
10371
- return console.warn('prog empty');
10606
+ await func.utils.report_issue(SESSION_ID, {
10607
+ code: 'RUN_MSG_EVT_030',
10608
+ source: 'func.events.execute_PENDING_OPEN_URL_EVENTS',
10609
+ message: 'prog empty',
10610
+ type: 'W',
10611
+ details: {
10612
+ url,
10613
+ },
10614
+ });
10615
+ return;
10372
10616
  }
10373
10617
 
10374
10618
  await func.utils.TREE_OBJ.get(SESSION_ID, params_obj.prog);
@@ -10389,18 +10633,37 @@ func.events.execute_PENDING_OPEN_URL_EVENTS = async function () {
10389
10633
  source_functionP: 'pendingUrlEvent_embed',
10390
10634
  });
10391
10635
  } else {
10392
- console.error('Program not exist', params_obj.prog_id);
10636
+ await func.utils.report_issue(SESSION_ID, {
10637
+ code: 'RUN_MSG_EVT_010',
10638
+ source: 'func.events.execute_PENDING_OPEN_URL_EVENTS',
10639
+ message: 'Program not exist',
10640
+ type: 'E',
10641
+ details: {
10642
+ prog_id: params_obj.prog_id,
10643
+ prog: params_obj.prog,
10644
+ },
10645
+ });
10393
10646
  func.UI.utils.progressScreen.show(SESSION_ID, 'Program not exist', null, true);
10394
10647
  }
10395
10648
  } else {
10396
- console.warn('url empty');
10649
+ await func.utils.report_issue(SESSION_ID, {
10650
+ code: 'RUN_MSG_EVT_030',
10651
+ source: 'func.events.execute_PENDING_OPEN_URL_EVENTS',
10652
+ message: 'url empty',
10653
+ type: 'W',
10654
+ });
10397
10655
  }
10398
10656
  }
10399
10657
  };
10400
10658
  func.events.invoke = async function (event_id) {
10401
10659
  var _session = SESSION_OBJ[SESSION_ID];
10402
10660
  if (!event_id) {
10403
- console.warn('event_id Cannot be empty');
10661
+ await func.utils.report_issue(SESSION_ID, {
10662
+ code: 'RUN_MSG_EVT_060',
10663
+ source: 'func.events.invoke',
10664
+ message: 'event_id Cannot be empty',
10665
+ type: 'W',
10666
+ });
10404
10667
  return false;
10405
10668
  }
10406
10669
  var ds;
@@ -10417,7 +10680,15 @@ func.events.invoke = async function (event_id) {
10417
10680
  }
10418
10681
 
10419
10682
  if (!ds) {
10420
- console.warn('event_id not found');
10683
+ await func.utils.report_issue(SESSION_ID, {
10684
+ code: 'RUN_MSG_EVT_060',
10685
+ source: 'func.events.invoke',
10686
+ message: 'event_id not found',
10687
+ type: 'W',
10688
+ details: {
10689
+ event_id,
10690
+ },
10691
+ });
10421
10692
  return false;
10422
10693
  }
10423
10694
 
@@ -11362,11 +11633,23 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
11362
11633
  try {
11363
11634
  return eval(val);
11364
11635
  } catch (err) {
11636
+ if (sourceP === 'javascript' && !ignore_errors) {
11637
+ await func.utils.report_issue(SESSION_ID, {
11638
+ code: 'RUN_MSG_EXP_010',
11639
+ source: 'func.expression.secure_eval',
11640
+ message: 'Execution error',
11641
+ type: 'E',
11642
+ err,
11643
+ details: {
11644
+ sourceP,
11645
+ dsSessionP,
11646
+ job_id,
11647
+ },
11648
+ });
11649
+ }
11365
11650
  try {
11366
- if (sourceP === 'javascript' && !ignore_errors) console.error(err);
11367
11651
  return JSON5.parse(val);
11368
- } catch (err) {
11369
- if (sourceP === 'javascript' && !ignore_errors) console.error(err);
11652
+ } catch (json_error) {
11370
11653
  return val;
11371
11654
  }
11372
11655
  }
@@ -11383,13 +11666,22 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
11383
11666
  ...(sourceP === 'javascript' ? { axios, got, FormData } : {}),
11384
11667
  };
11385
11668
 
11386
- const handleError = (err) => {
11387
- console.error('Execution error:', err);
11669
+ const handleError = async (err) => {
11670
+ await func.utils.report_issue(SESSION_ID, {
11671
+ code: 'RUN_MSG_EXP_010',
11672
+ source: 'func.expression.secure_eval',
11673
+ message: 'Execution error',
11674
+ type: 'E',
11675
+ err,
11676
+ details: {
11677
+ sourceP,
11678
+ dsSessionP,
11679
+ job_id,
11680
+ },
11681
+ });
11388
11682
  func.events.delete_job(SESSION_ID, job_id);
11389
11683
  if (isServer && !SESSION_OBJ[SESSION_ID].crawler) {
11390
- if (sourceP === 'javascript') {
11391
- __.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id, 'error', 'worker', 'vm error', err, null, val, 'func.expression.get.secure_eval');
11392
- } else {
11684
+ if (sourceP !== 'javascript') {
11393
11685
  __.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id, 'api', err);
11394
11686
  }
11395
11687
  }
@@ -11397,10 +11689,12 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
11397
11689
  };
11398
11690
 
11399
11691
  if (sourceP === 'javascript') {
11400
- process.on('uncaughtException', handleError);
11692
+ process.on('uncaughtException', function (uncaught_error) {
11693
+ handleError(uncaught_error);
11694
+ });
11401
11695
  try {
11402
11696
  const dir = path.join(_conf.studio_drive_path, SESSION_OBJ[SESSION_ID].app_id, 'node_modules');
11403
- const script = new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`, { filename: dir, dirname: dir });
11697
+ const script = new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); throw e; }`, { filename: dir, dirname: dir });
11404
11698
  const vm = new NodeVM({
11405
11699
  require: { external: true },
11406
11700
  sandbox,
@@ -11408,7 +11702,7 @@ func.expression.secure_eval = async function (SESSION_ID, sourceP, val, job_id,
11408
11702
  });
11409
11703
  return await vm.run(script, { filename: dir, dirname: dir });
11410
11704
  } catch (err) {
11411
- return handleError(err);
11705
+ return await handleError(err);
11412
11706
  }
11413
11707
  }
11414
11708
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle",
3
- "version": "1.3.2697",
3
+ "version": "1.3.2699",
4
4
  "description": "xuda framework",
5
5
  "main": "index.js",
6
6
  "scripts": {