Skip to content

Commit ad3bcfe

Browse files
committed
chore(rivetkit): RIVET_EXPOSE_ERRORS
1 parent b716026 commit ad3bcfe

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

rivetkit-typescript/packages/rivetkit/src/actor/protocol/old.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ import {
2121
ToServerSchema,
2222
} from "@/schemas/client-protocol-zod/mod";
2323
import { deserializeWithEncoding } from "@/serde";
24-
import { assertUnreachable, bufferToArrayBuffer } from "../../utils";
24+
import {
25+
assertUnreachable,
26+
bufferToArrayBuffer,
27+
getEnvUniversal,
28+
} from "../../utils";
2529
import { CONN_SEND_MESSAGE_SYMBOL, type Conn } from "../conn/mod";
2630
import { ActionContext } from "../contexts";
2731
import type { ActorInstance } from "../instance/mod";
@@ -284,6 +288,8 @@ export async function processMessage<
284288
actionId,
285289
actionName,
286290
},
291+
getEnvUniversal("RIVET_EXPOSE_ERRORS") === "1" ||
292+
getEnvUniversal("NODE_ENV") === "development",
287293
);
288294

289295
actor.rLog.debug({

rivetkit-typescript/packages/rivetkit/src/actor/router-endpoints.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
deserializeWithEncoding,
3232
serializeWithEncoding,
3333
} from "@/serde";
34-
import { bufferToArrayBuffer } from "@/utils";
34+
import { bufferToArrayBuffer, getEnvUniversal } from "@/utils";
3535
import { createHttpDriver } from "./conn/drivers/http";
3636
import { createRawRequestDriver } from "./conn/drivers/raw-request";
3737
import type { ActorDriver } from "./driver";
@@ -186,9 +186,15 @@ export function getRequestEncoding(req: HonoRequest): Encoding {
186186
return result.data;
187187
}
188188

189+
/**
190+
* Determines whether internal errors should be exposed to the client.
191+
* Returns true if RIVET_EXPOSE_ERRORS=1 or NODE_ENV=development.
192+
*/
189193
export function getRequestExposeInternalError(_req: Request): boolean {
190-
// Unipmlemented
191-
return false;
194+
return (
195+
getEnvUniversal("RIVET_EXPOSE_ERRORS") === "1" ||
196+
getEnvUniversal("NODE_ENV") === "development"
197+
);
192198
}
193199

194200
export function getRequestQuery(c: HonoContext): unknown {

website/src/content/docs/actors/errors.mdx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,42 @@ try {
327327
</Tab>
328328
</Tabs>
329329

330-
The original error message and stack trace are logged server-side for debugging. Check your server logs to see the full error details.
330+
### Server-Side Logging
331+
332+
**All internal errors are logged server-side with full details.** When an internal error occurs, the complete error message, stack trace, and context are written to your server logs. This is where you should look first when debugging internal errors in production.
333+
334+
The client receives only a generic "Internal error" message for security, but you can find the full error details in your server logs including:
335+
336+
- Complete error message
337+
- Stack trace
338+
- Request context (actor ID, action name, connection ID, etc.)
339+
- Timestamp
340+
341+
**Always check your server logs to see the actual error details when debugging internal errors.**
342+
343+
### Exposing Errors to Clients (Development Only)
344+
345+
**Warning:** Only enable error exposure in development environments. In production, this will leak sensitive internal details to clients.
346+
347+
For faster debugging during development, you can automatically expose internal error details to clients. This is enabled when:
348+
349+
- `NODE_ENV=development` - Automatically enabled in development mode
350+
- `RIVET_EXPOSE_ERRORS=1` - Explicitly enable error exposure
351+
352+
With error exposure enabled, clients will see the full error message instead of the generic "Internal error" response:
353+
354+
```typescript
355+
// With NODE_ENV=development or RIVET_EXPOSE_ERRORS=1
356+
try {
357+
await paymentActor.processPayment(100);
358+
} catch (error) {
359+
if (error instanceof ActorError) {
360+
console.log(error.message);
361+
// "Payment API returned 402: Insufficient funds"
362+
// Instead of: "Internal error. Read the server logs for more details."
363+
}
364+
}
365+
```
331366

332367
## API Reference
333368

0 commit comments

Comments
 (0)