Skip to content

Commit 70465f7

Browse files
authored
fix: ensure the Actor instance is initialized while calling its methods (#471)
Adds a warning on a non-initialized Actor on `useState`, `exit`, `reboot` and `setStatusMessage` method calls.
1 parent 04a949a commit 70465f7

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/apify/src/actor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ export class Actor<Data extends Dictionary = Dictionary> {
534534
options.exit ??= true;
535535
options.exitCode ??= EXIT_CODES.SUCCESS;
536536
options.timeoutSecs ??= 30;
537+
538+
this._ensureActorInit('exit');
539+
537540
const client = this.config.getStorageClient();
538541
const events = this.config.getEventManager();
539542

@@ -807,6 +810,8 @@ export class Actor<Data extends Dictionary = Dictionary> {
807810
* @ignore
808811
*/
809812
async reboot(options: RebootOptions = {}): Promise<void> {
813+
this._ensureActorInit('reboot');
814+
810815
if (!this.isAtHome()) {
811816
log.warning(
812817
'Actor.reboot() is only supported when running on the Apify platform.',
@@ -916,6 +921,8 @@ export class Actor<Data extends Dictionary = Dictionary> {
916921
ow(statusMessage, ow.string);
917922
ow(isStatusMessageTerminal, ow.optional.boolean);
918923

924+
this._ensureActorInit('setStatusMessage');
925+
919926
const loggedStatusMessage = `[Status message]: ${statusMessage}`;
920927

921928
switch (level) {
@@ -1523,6 +1530,8 @@ export class Actor<Data extends Dictionary = Dictionary> {
15231530
defaultValue = {} as State,
15241531
options?: UseStateOptions,
15251532
) {
1533+
this._ensureActorInit('useState');
1534+
15261535
const kvStore = await KeyValueStore.open(options?.keyValueStoreName, {
15271536
config: options?.config || Configuration.getGlobalConfig(),
15281537
});

0 commit comments

Comments
 (0)