Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import {
ToServerSchema,
} from "@/schemas/client-protocol-zod/mod";
import { deserializeWithEncoding } from "@/serde";
import { assertUnreachable, bufferToArrayBuffer } from "../../utils";
import {
assertUnreachable,
bufferToArrayBuffer,
getEnvUniversal,
} from "../../utils";
import { CONN_SEND_MESSAGE_SYMBOL, type Conn } from "../conn/mod";
import { ActionContext } from "../contexts";
import type { ActorInstance } from "../instance/mod";
Expand Down Expand Up @@ -284,6 +288,8 @@ export async function processMessage<
actionId,
actionName,
},
getEnvUniversal("RIVET_EXPOSE_ERRORS") === "1" ||
getEnvUniversal("NODE_ENV") === "development",
);

actor.rLog.debug({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
deserializeWithEncoding,
serializeWithEncoding,
} from "@/serde";
import { bufferToArrayBuffer } from "@/utils";
import { bufferToArrayBuffer, getEnvUniversal } from "@/utils";
import { createHttpDriver } from "./conn/drivers/http";
import { createRawRequestDriver } from "./conn/drivers/raw-request";
import type { ActorDriver } from "./driver";
Expand Down Expand Up @@ -198,9 +198,15 @@ export function getRequestEncoding(req: HonoRequest): Encoding {
return result.data;
}

/**
* Determines whether internal errors should be exposed to the client.
* Returns true if RIVET_EXPOSE_ERRORS=1 or NODE_ENV=development.
*/
export function getRequestExposeInternalError(_req: Request): boolean {
// Unipmlemented
return false;
return (
getEnvUniversal("RIVET_EXPOSE_ERRORS") === "1" ||
getEnvUniversal("NODE_ENV") === "development"
);
}

export function getRequestQuery(c: HonoContext): unknown {
Expand Down
37 changes: 36 additions & 1 deletion website/src/content/docs/actors/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,42 @@ try {
</Tab>
</Tabs>

The original error message and stack trace are logged server-side for debugging. Check your server logs to see the full error details.
### Server-Side Logging

**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.

The client receives only a generic "Internal error" message for security, but you can find the full error details in your server logs including:

- Complete error message
- Stack trace
- Request context (actor ID, action name, connection ID, etc.)
- Timestamp

**Always check your server logs to see the actual error details when debugging internal errors.**

### Exposing Errors to Clients (Development Only)

**Warning:** Only enable error exposure in development environments. In production, this will leak sensitive internal details to clients.

For faster debugging during development, you can automatically expose internal error details to clients. This is enabled when:

- `NODE_ENV=development` - Automatically enabled in development mode
- `RIVET_EXPOSE_ERRORS=1` - Explicitly enable error exposure

With error exposure enabled, clients will see the full error message instead of the generic "Internal error" response:

```typescript
// With NODE_ENV=development or RIVET_EXPOSE_ERRORS=1
try {
await paymentActor.processPayment(100);
} catch (error) {
if (error instanceof ActorError) {
console.log(error.message);
// "Payment API returned 402: Insufficient funds"
// Instead of: "Internal error. Read the server logs for more details."
}
}
```

## API Reference

Expand Down
Loading