@tracecode/harness 0.6.5 → 0.6.6

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.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project are documented here.
4
4
 
5
5
  This repo uses Git tags as release boundaries. Version notes below summarize what shipped in each tagged release.
6
6
 
7
+ ## [0.6.6] - 2026-04-27
8
+
9
+ ### Fixed
10
+
11
+ - Improved Java worker rewrite-failure handling so parser failures are surfaced as user-facing syntax errors instead of opaque Java object strings.
12
+ - Added a compile probe fallback when Java source rewriting fails, allowing harness clients to receive compiler stderr/stdout diagnostics in the standard failed execution payload.
13
+
7
14
  ## [0.6.5] - 2026-04-26
8
15
 
9
16
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tracecode/harness",
3
- "version": "0.6.5",
3
+ "version": "0.6.6",
4
4
  "license": "AGPL-3.0-only",
5
5
  "homepage": "https://tracecode.app",
6
6
  "repository": {
@@ -68,13 +68,19 @@ function formatWorkerErrorMessage(error) {
68
68
  } catch {}
69
69
  try {
70
70
  const tag = Object.prototype.toString.call(error);
71
- if (tag && tag !== '[object Object]') {
71
+ if (tag && tag.includes('ParseProblemException')) {
72
+ return 'Java syntax error.';
73
+ }
74
+ if (tag && tag !== '[object Object]' && !tag.startsWith('[object ')) {
72
75
  return tag;
73
76
  }
74
77
  } catch {}
75
78
  try {
76
79
  if (typeof error.toString === 'function' && error.toString !== Object.prototype.toString) {
77
80
  const value = error.toString();
81
+ if (value.includes('ParseProblemException')) {
82
+ return 'Java syntax error.';
83
+ }
78
84
  if (typeof value === 'string' && value.length > 0 && value !== '[object Object]') {
79
85
  return value;
80
86
  }
@@ -83,6 +89,9 @@ function formatWorkerErrorMessage(error) {
83
89
  }
84
90
  try {
85
91
  const stringified = String(error);
92
+ if (stringified.includes('ParseProblemException')) {
93
+ return 'Java syntax error.';
94
+ }
86
95
  if (stringified && stringified !== '[object Object]') {
87
96
  return stringified;
88
97
  }
@@ -1200,6 +1209,88 @@ async function rewriteSource(payload, requestId) {
1200
1209
  );
1201
1210
  }
1202
1211
 
1212
+ function normalizePublicClassDeclarations(source) {
1213
+ return String(source).replace(/(^|\n)\s*public\s+class\s+/g, '$1class ');
1214
+ }
1215
+
1216
+ async function collectCompileProbeDiagnostics(source, requestId, options) {
1217
+ const probeClassName = buildExportsClassName(`${requestId}RewriteProbe`);
1218
+ const probePackageName = buildPackageName(`${requestId}RewriteProbe`);
1219
+ const sourcePath = `/str/${probeClassName}.java`;
1220
+ const classesDir = `/files/java-worker/${requestId}/rewrite-probe/classes`;
1221
+
1222
+ let compileLibraryClass;
1223
+ try {
1224
+ compileLibraryClass = await getCompileLibraryClass();
1225
+ } catch (error) {
1226
+ return {
1227
+ consoleOutput: [],
1228
+ error: null,
1229
+ hostCallMs: 0,
1230
+ diagnosticError: formatWorkerErrorMessage(error),
1231
+ };
1232
+ }
1233
+
1234
+ try {
1235
+ await self.cheerpOSAddStringFile(sourcePath, normalizePublicClassDeclarations(source));
1236
+ } catch (error) {
1237
+ return {
1238
+ consoleOutput: [],
1239
+ error: null,
1240
+ hostCallMs: 0,
1241
+ diagnosticError: formatWorkerErrorMessage(error),
1242
+ };
1243
+ }
1244
+
1245
+ const startedAt = performance.now();
1246
+ let reportText;
1247
+ try {
1248
+ reportText = await compileLibraryClass.compileAndTrace(
1249
+ sourcePath,
1250
+ classesDir,
1251
+ `${probePackageName}.${probeClassName}`,
1252
+ HELPER_JAR_PATH,
1253
+ DEFAULT_COMPILER_DEBUG_PROFILE,
1254
+ String(resolveMaxStoredEvents(options))
1255
+ );
1256
+ } catch (error) {
1257
+ return {
1258
+ consoleOutput: [],
1259
+ error: null,
1260
+ hostCallMs: performance.now() - startedAt,
1261
+ diagnosticError: formatWorkerErrorMessage(error),
1262
+ };
1263
+ }
1264
+
1265
+ let report;
1266
+ try {
1267
+ report = JSON.parse(reportText);
1268
+ } catch (error) {
1269
+ return {
1270
+ consoleOutput: [],
1271
+ error: null,
1272
+ hostCallMs: performance.now() - startedAt,
1273
+ diagnosticError: `Invalid compile probe report: ${formatWorkerErrorMessage(error)}`,
1274
+ };
1275
+ }
1276
+
1277
+ const consoleOutput = [report.compilerStdout, report.compilerStderr].filter(
1278
+ (entry) => typeof entry === 'string' && entry.trim().length > 0
1279
+ );
1280
+ const surfacedError =
1281
+ report.runtimeError ||
1282
+ report.compilerStderr ||
1283
+ report.compilerStdout ||
1284
+ null;
1285
+
1286
+ return {
1287
+ consoleOutput,
1288
+ error: surfacedError,
1289
+ hostCallMs: performance.now() - startedAt,
1290
+ diagnosticError: null,
1291
+ };
1292
+ }
1293
+
1203
1294
  function normalizeScriptTraceEvents(events, scriptMode, userCodeLineCount, sourceLineMap) {
1204
1295
  if (!scriptMode || !Array.isArray(events)) return events;
1205
1296
  return events.map((event) => {
@@ -1302,7 +1393,31 @@ async function runJavaRequest(payload, requestId) {
1302
1393
  rewrittenSource = self.TraceCodeJavaSourceAugmentations.augmentJavaCollectionOperations(rewrittenSource);
1303
1394
  rewrittenSource = augmentTraceReturnValueSnapshots(rewrittenSource);
1304
1395
  } catch (error) {
1305
- throw makeWorkerStageError('source rewrite', error);
1396
+ const rewriteError = formatWorkerErrorMessage(error);
1397
+ const diagnosticProbe = await collectCompileProbeDiagnostics(
1398
+ normalizedPayload.code,
1399
+ requestId,
1400
+ payload.options
1401
+ );
1402
+ const totalEnd = performance.now();
1403
+ const surfacedError =
1404
+ diagnosticProbe.error ??
1405
+ (rewriteError === 'Java syntax error.'
1406
+ ? 'Java syntax error. Check Code Assist for parser details.'
1407
+ : `Java source rewrite failed: ${rewriteError}`);
1408
+ return {
1409
+ success: false,
1410
+ events: [],
1411
+ ...(normalizedPayload.sourceText ? { sourceText: normalizedPayload.sourceText } : {}),
1412
+ executionTimeMs: totalEnd - totalStart,
1413
+ consoleOutput: diagnosticProbe.consoleOutput,
1414
+ error: surfacedError,
1415
+ timings: {
1416
+ rewriteMs: totalEnd - rewriteStart,
1417
+ hostCallMs: diagnosticProbe.hostCallMs,
1418
+ totalMs: totalEnd - totalStart,
1419
+ },
1420
+ };
1306
1421
  }
1307
1422
  const rewriteEnd = performance.now();
1308
1423