Skip to content

Commit e51c31b

Browse files
feat(game-bridge): enhance error diagnostics and consolidate build output
- Add extensive debug logging with [GAME-BRIDGE] prefix for easier troubleshooting - Enrich USER_REGISTRATION_ERROR messages with HTTP status, URL, trace IDs, request IDs, cf-ray, and response snippets - Create fixUnityBuild.js script to consolidate all parcel-generated JS files into a single inline index.html - Update build scripts to call fixUnityBuild.js after parcel build - Ensure enriched error messages (with httpStatus/url/trace/reqId/resp) are returned to Unity for CI visibility - Add browser feature detection logging (BigInt, fetch, ErrorCause, etc.) - Log detailed HTTP error context when network failures occur (especially for IMX offchain registration) - Update target browser to Chrome 137 for Unity and Unreal builds
1 parent 9ff1bde commit e51c31b

7 files changed

Lines changed: 1000 additions & 530 deletions

File tree

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ examples/**/*
2020
packages/internal/generated-clients/src/
2121

2222
# put module specific ignore paths here
23+
packages/game-bridge/scripts/**/*.js

packages/auth/src/errors.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,14 @@ export function isAPIError(error: any): error is imx.APIError {
3636

3737
type AxiosLikeError = {
3838
response?: {
39+
status?: number;
3940
data?: unknown;
4041
};
42+
config?: {
43+
url?: string;
44+
baseURL?: string;
45+
method?: string;
46+
};
4147
};
4248

4349
const extractApiError = (error: unknown): imx.APIError | undefined => {
@@ -59,6 +65,23 @@ const extractApiError = (error: unknown): imx.APIError | undefined => {
5965
return undefined;
6066
};
6167

68+
const appendHttpDebugInfo = (message: string, error: unknown): string => {
69+
const e = error as AxiosLikeError;
70+
const status = e?.response?.status;
71+
const url = e?.config?.url;
72+
const baseURL = e?.config?.baseURL;
73+
const fullUrl = (
74+
typeof url === 'string' && typeof baseURL === 'string' && !/^https?:\/\//i.test(url)
75+
? `${baseURL}${url}`
76+
: url
77+
);
78+
79+
if (status == null && fullUrl == null) return message;
80+
if (message.includes('[httpStatus=')) return message;
81+
82+
return `${message} [httpStatus=${status ?? 'unknown'} url=${fullUrl ?? 'unknown'}]`;
83+
};
84+
6285
export class PassportError extends Error {
6386
public type: PassportErrorType;
6487

@@ -88,6 +111,11 @@ export const withPassportError = async <T>(
88111
errorMessage = (error as Error).message;
89112
}
90113

114+
// Debug aid: preserve which HTTP endpoint/status failed for IMX offchain registration.
115+
if (customErrorType === PassportErrorType.USER_REGISTRATION_ERROR) {
116+
errorMessage = appendHttpDebugInfo(errorMessage, error);
117+
}
118+
91119
throw new PassportError(errorMessage, customErrorType);
92120
}
93121
};

packages/game-bridge/package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"parcel": "^2.13.3"
1515
},
1616
"scripts": {
17-
"build": "parcel build --no-cache --no-scope-hoist",
18-
"build:local": "parcel build --no-cache --no-scope-hoist && pnpm updateSdkVersion",
17+
"build": "parcel build --no-cache --no-scope-hoist && node scripts/fixUnityBuild.js",
18+
"build:local": "parcel build --no-cache --no-scope-hoist && node scripts/fixUnityBuild.js && pnpm updateSdkVersion",
1919
"lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0",
2020
"start": "parcel",
2121
"updateSdkVersion": "./scripts/updateSdkVersion.sh"
@@ -25,17 +25,25 @@
2525
"unity": {
2626
"context": "browser",
2727
"source": "src/index.html",
28+
"outputFormat": "global",
29+
"scopeHoist": false,
30+
"isLibrary": false,
2831
"engines": {
29-
"browsers": "Chrome 90"
32+
"browsers": "Chrome 137"
3033
}
3134
},
3235
"unreal": {
3336
"outputFormat": "global",
3437
"context": "browser",
3538
"source": "src/index.ts",
39+
"scopeHoist": false,
40+
"isLibrary": false,
3641
"engines": {
37-
"browsers": "Chrome 90"
42+
"browsers": "Chrome 137"
3843
}
3944
}
40-
}
45+
},
46+
"browserslist": [
47+
"Chrome 137"
48+
]
4149
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
const DIST_DIR = path.join(__dirname, '..', 'dist');
7+
const HTML_FILE = path.join(DIST_DIR, 'index.html');
8+
9+
console.log('🔧 Fixing Unity build...');
10+
console.log(`📁 Dist directory: ${DIST_DIR}`);
11+
12+
if (!fs.existsSync(DIST_DIR)) {
13+
console.error('❌ Dist directory not found!');
14+
process.exit(1);
15+
}
16+
17+
// Find all JS files (excluding .map files)
18+
const jsFiles = fs.readdirSync(DIST_DIR)
19+
.filter(f => f.endsWith('.js') && !f.endsWith('.map'))
20+
.sort((a, b) => {
21+
// Main bundle first
22+
if (a.startsWith('game-bridge')) return -1;
23+
if (b.startsWith('game-bridge')) return 1;
24+
return a.localeCompare(b);
25+
});
26+
27+
console.log(`📦 Found ${jsFiles.length} JS file(s):`, jsFiles);
28+
29+
if (jsFiles.length === 0) {
30+
console.error('❌ No JS files found to inline!');
31+
process.exit(1);
32+
}
33+
34+
// Combine all JS files
35+
let combinedJs = '';
36+
for (const jsFile of jsFiles) {
37+
const jsPath = path.join(DIST_DIR, jsFile);
38+
const jsContent = fs.readFileSync(jsPath, 'utf8');
39+
combinedJs += jsContent + '\n';
40+
console.log(` ✅ ${jsFile}: ${jsContent.length} bytes`);
41+
}
42+
43+
console.log(`📊 Total combined JavaScript: ${combinedJs.length} bytes`);
44+
45+
// Create new HTML with inlined JavaScript
46+
const html = `<!DOCTYPE html>
47+
<html lang="en">
48+
<head>
49+
<meta charset="utf-8">
50+
<title>GameSDK Bridge</title>
51+
<script>${combinedJs}</script>
52+
</head>
53+
<body>
54+
</body>
55+
</html>`;
56+
57+
// Write the new HTML file
58+
fs.writeFileSync(HTML_FILE, html, 'utf8');
59+
console.log(`✅ Unity build fixed successfully!`);
60+
console.log(`📄 Output: ${HTML_FILE} (${html.length} bytes)`);
61+
62+
// Clean up: remove JS files and source maps
63+
console.log('🧹 Cleaning up external JS files...');
64+
for (const jsFile of jsFiles) {
65+
const jsPath = path.join(DIST_DIR, jsFile);
66+
fs.unlinkSync(jsPath);
67+
console.log(` 🗑️ Removed ${jsFile}`);
68+
69+
const mapPath = jsPath + '.map';
70+
if (fs.existsSync(mapPath)) {
71+
fs.unlinkSync(mapPath);
72+
console.log(` 🗑️ Removed ${jsFile}.map`);
73+
}
74+
}
75+
76+
console.log('✨ Done!');
77+

packages/game-bridge/src/index.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
<head>
55
<meta charset="utf-8">
66
<title>GameSDK Bridge</title>
7-
<script type="module">
8-
import "./index.ts";
9-
</script>
7+
<script type="module" src="./index.ts"></script>
108
</head>
119

1210
<body>
13-
<h1>Bridge Running</h1>
1411
</body>
1512

1613
</html>

0 commit comments

Comments
 (0)