Skip to content

Commit 4fd5ce8

Browse files
NathanFlurryjog1t
authored andcommitted
chore(rivetkit): RIVET_EXPOSE_ERRORS
1 parent f96b9d8 commit 4fd5ce8

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
@@ -30,7 +30,7 @@ import {
3030
deserializeWithEncoding,
3131
serializeWithEncoding,
3232
} from "@/serde";
33-
import { bufferToArrayBuffer } from "@/utils";
33+
import { bufferToArrayBuffer, getEnvUniversal } from "@/utils";
3434
import { createHttpDriver } from "./conn/drivers/http";
3535
import { createRawRequestDriver } from "./conn/drivers/raw-request";
3636
import type { ActorDriver } from "./driver";
@@ -198,9 +198,15 @@ export function getRequestEncoding(req: HonoRequest): Encoding {
198198
return result.data;
199199
}
200200

201+
/**
202+
* Determines whether internal errors should be exposed to the client.
203+
* Returns true if RIVET_EXPOSE_ERRORS=1 or NODE_ENV=development.
204+
*/
201205
export function getRequestExposeInternalError(_req: Request): boolean {
202-
// Unipmlemented
203-
return false;
206+
return (
207+
getEnvUniversal("RIVET_EXPOSE_ERRORS") === "1" ||
208+
getEnvUniversal("NODE_ENV") === "development"
209+
);
204210
}
205211

206212
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)