Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"packages/components/*",
"packages/misc/*",
"packages/frameworks/*",
"examples/*"
"examples/*",
"templates/*"
],
"scripts": {
"start": "npx turbo watch build",
Expand Down
11 changes: 7 additions & 4 deletions packages/actor-core-cli/src/utils/platforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const PLATFORMS = {
...pkgJson,
scripts: {
...pkgJson.scripts,
deploy: "actor-core deploy rivet actors/app.ts",
deploy: "npx @actor-core/cli deploy rivet actors/app.ts",
},
devDependencies: {
"@actor-core/cli": version,
Expand Down Expand Up @@ -256,9 +256,12 @@ serve(app);
},
},
noop: {
modify: ({ files }) => {
// Do nothing
return { files };
modify: ({ files, pkgJson }) => {
files["package.json"] = stringifyJson(pkgJson);

return {
files,
};
},
},
} satisfies Record<string, PlatformConfig>;
Expand Down
14 changes: 7 additions & 7 deletions packages/actor-core/src/actor/instance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PersistedConn } from "./connection";
import type { Logger } from "@/common//log";
import { type ActorTags, isJsonSerializable } from "@/common//utils";
import { type ActorTags, isJsonSerializable, stringifyError } from "@/common//utils";
import onChange from "on-change";
import type { ActorConfig } from "./config";
import { Conn, type ConnId } from "./connection";
Expand Down Expand Up @@ -346,7 +346,7 @@ export class ActorInstance<S, CP, CS, V> {
this.#config.onStateChange(this.actorContext, this.#persistRaw.s);
} catch (error) {
logger().error("error in `_onStateChange`", {
error: `${error}`,
error: stringifyError(error),
});
}
}
Expand Down Expand Up @@ -473,13 +473,13 @@ export class ActorInstance<S, CP, CS, V> {
// Handle promise but don't await it to prevent blocking
result.catch((error) => {
logger().error("error in `onDisconnect`", {
error: `${error}`,
error: stringifyError(error),
});
});
}
} catch (error) {
logger().error("error in `onDisconnect`", {
error: `${error}`,
error: stringifyError(error),
});
}
}
Expand Down Expand Up @@ -591,7 +591,7 @@ export class ActorInstance<S, CP, CS, V> {
}
} catch (error) {
logger().error("error in `onConnect`", {
error: `${error}`,
error: stringifyError(error),
});
conn?.disconnect("`onConnect` failed");
}
Expand Down Expand Up @@ -768,7 +768,7 @@ export class ActorInstance<S, CP, CS, V> {
}
} catch (error) {
logger().error("error in `onBeforeRpcResponse`", {
error: `${error}`,
error: stringifyError(error),
});
}
}
Expand Down Expand Up @@ -908,7 +908,7 @@ export class ActorInstance<S, CP, CS, V> {
})
.catch((error) => {
logger().error("background promise failed", {
error: `${error}`,
error: stringifyError(error),
});
});
this.#backgroundPromises.push(nonfailablePromise);
Expand Down
10 changes: 6 additions & 4 deletions packages/actor-core/src/actor/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { type SSEStreamingApi, streamSSE } from "hono/streaming";
import { cors } from "hono/cors";
import { assertUnreachable } from "./utils";
import { handleRouteError, handleRouteNotFound } from "@/common/router";
import { deconstructError } from "@/common/utils";
import { deconstructError, stringifyError } from "@/common/utils";
import type { DriverConfig } from "@/driver-helpers/config";
import type { AppConfig } from "@/app/config";
import {
Expand Down Expand Up @@ -186,7 +186,9 @@ export function createActorRouter(

// Actors don't need to know about this, since it's abstracted
// away
logger().warn("websocket error", { error: `${error}` });
logger().warn("websocket error", {
error: stringifyError(error),
});
} catch (error) {
deconstructError(error, logger(), { wsEvent: "error" });
}
Expand Down Expand Up @@ -238,7 +240,7 @@ export function createActorRouter(
async (error) => {
// Actors don't need to know about this, since it's abstracted
// away
logger().warn("sse error", { error: `${error}` });
logger().warn("sse error", { error: stringifyError(error) });
},
);
});
Expand Down Expand Up @@ -407,7 +409,7 @@ function getRequestConnParams(
return typeof paramsStr === "string" ? JSON.parse(paramsStr) : undefined;
} catch (error) {
logger().warn("malformed connection parameters", {
error: `${error}`,
error: stringifyError(error),
});
throw new errors.MalformedConnParams(error);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/actor-core/src/actor/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { AnyActorInstance } from "./instance";
import type { ActorDriver } from "./driver";
import { KEYS } from "./keys";
import { logger } from "./log";
import { stringifyError } from "@/common/utils";

interface ScheduleState {
// Sorted by timestamp asc
Expand Down Expand Up @@ -151,15 +152,15 @@ export class Schedule {
} catch (err) {
logger().error("failed to run scheduled event", {
fn: event.fn,
error: `${err}`,
error: stringifyError(err),
});

// Write internal error
await this.#driver.kvPut(
this.#actor.id,
KEYS.SCHEDULE.alarmError(event.fn),
{
error: `${err}`,
error: stringifyError(err),
timestamp: now,
},
);
Expand Down
4 changes: 2 additions & 2 deletions packages/actor-core/src/client/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Encoding } from "@/actor/protocol/serde";
import type * as wsToClient from "@/actor/protocol/message/to-client";
import type * as wsToServer from "@/actor/protocol/message/to-server";
import { MAX_CONN_PARAMS_SIZE } from "@/common/network";
import { assertUnreachable } from "@/common/utils";
import { assertUnreachable, stringifyError } from "@/common/utils";
import * as cbor from "cbor-x";
import * as errors from "./errors";
import { logger } from "./log";
Expand Down Expand Up @@ -186,7 +186,7 @@ enc
onFailedAttempt: (error) => {
logger().warn("failed to reconnect", {
attempt: error.attemptNumber,
error: `${error}`,
error: stringifyError(error),
});
},

Expand Down
20 changes: 20 additions & 0 deletions packages/actor-core/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,23 @@ export function deconstructError(

return { statusCode, code, message, metadata };
}

export function stringifyError(error: unknown): string {
if (error instanceof Error) {
if (process.env._ACTOR_CORE_ERROR_STACK === "1") {
return `${error.name}: ${error.message}${error.stack ? `\n${error.stack}` : ""}`;
} else {
return `${error.name}: ${error.message}`;
}
} else if (typeof error === "string") {
return error;
} else if (typeof error === "object" && error !== null) {
try {
return `${JSON.stringify(error)}`;
} catch {
return "[cannot stringify error]";
}
} else {
return `Unknown error: ${String(error)}`;
}
}
Loading
Loading