Conversation
|
This is the Claude analysis about the Bun issue @josephjclark JSDoc/Bun Compatibility Error AnalysisThe ErrorPython Side (job_chat service)Server Side (TypeScript)Root Cause AnalysisThe Error Chain
Core IssueBun Node.js Compatibility Gap: Bun's Node.js compatibility layer doesn't implement the Suggested FixesFix 1: Improve Python Error Handling (Immediate Fix)Problem: The Location: services/util.py:87-97 Current Code: def apollo(name, payload):
global apollo_port
url = f"http://127.0.0.1:{apollo_port}/services/{name}"
r = requests.post(url, json = payload)
return r.json()Proposed Fix: def apollo(name, payload):
"""
Call out to an Apollo service through HTTP.
:param name: Name of the service.
:param payload: Payload to send in the POST request.
:return: JSON response.
"""
global apollo_port
url = f"http://127.0.0.1:{apollo_port}/services/{name}"
try:
r = requests.post(url, json=payload)
r.raise_for_status() # Raise HTTPError for bad status codes
return r.json()
except requests.exceptions.JSONDecodeError as e:
# Response was not valid JSON
raise ApolloError(
500,
f"Service {name} returned invalid JSON response. Response text: {r.text[:200]}",
type="SERVICE_ERROR"
)
except requests.exceptions.HTTPError as e:
# HTTP error status code
try:
error_data = r.json()
raise ApolloError(
r.status_code,
error_data.get("message", str(e)),
type=error_data.get("type", "HTTP_ERROR")
)
except requests.exceptions.JSONDecodeError:
raise ApolloError(
r.status_code,
f"Service {name} failed: {r.text[:200]}",
type="HTTP_ERROR"
)
except requests.exceptions.RequestException as e:
# Connection error, timeout, etc.
raise ApolloError(
500,
f"Failed to connect to service {name}: {str(e)}",
type="CONNECTION_ERROR"
)Benefits:
Fix 2: Add Try-Catch to TypeScript Service Handler (Defense in Depth)Problem: Exceptions in TypeScript services aren't caught, leading to unclear error responses. Location: platform/src/middleware/services.ts:35-49 Current Code: app.post(name, async (ctx) => {
console.log(`POST to /services/${name}`);
const payload = ctx.body;
const result = await callService(m, port, payload as any);
if (isApolloError(result)) {
return new Response(JSON.stringify(result), {
status: result.code,
headers: {
"Content-Type": "application/json",
},
});
}
return result;
});Proposed Fix: app.post(name, async (ctx) => {
console.log(`POST to /services/${name}`);
const payload = ctx.body;
try {
const result = await callService(m, port, payload as any);
if (isApolloError(result)) {
return new Response(JSON.stringify(result), {
status: result.code,
headers: {
"Content-Type": "application/json",
},
});
}
return result;
} catch (error) {
console.error(`Error in service ${name}:`, error);
const errorResponse = {
code: 500,
type: "SERVICE_ERROR",
message: error instanceof Error ? error.message : String(error),
};
return new Response(JSON.stringify(errorResponse), {
status: 500,
headers: {
"Content-Type": "application/json",
},
});
}
});Benefits:
Fix 3: Run JSDoc Under Node.js (Root Cause Fix)Problem: JSDoc doesn't work under Bun due to Option A: Use Node.js to run adaptor_apis service Create a wrapper script that invokes Node.js for this specific service: New file: #!/bin/bash
# Run the adaptor_apis TypeScript service using Node.js instead of Bun
exec node --loader ts-node/esm services/adaptor_apis/adaptor_apis.ts "$@"Modify: The service loader to detect this and use Node.js Option B: Use a different JSDoc approach Replace
Option C: Run entire server with Node.js instead of Bun Change the start command in {
"scripts": {
"start": "NODE_ENV=production node --loader tsx platform/src/index.ts",
"dev": "NODE_ENV=development node --loader tsx --watch platform/src/index.ts"
}
}Trade-offs:
|
|
Thank you @hanna-paasivirta I'm not really convinced of this. It's totally fine locally - I don't see this error at all. After a few searches I can't find anything about this incompatibility. And yet so far as I can tell, production is consistently failing |
|
I've got a stack trace on staging and it does seem to lean towards what Claude is saying Really don't understand why I'm not seeing this locally 🤔 If it is because bun.js is missing some features, it should fail consistently |
Fixes #377
AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to know!):
You can read more details in our Responsible AI Policy