Skip to content

Commit

Permalink
Fix background functions in functions:shell (firebase#3491)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern authored and devpeerapong committed Dec 14, 2021
1 parent 0182205 commit 2f928b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Fixes import/export bug with Storage emulator download tokens (#3414)
- Improves errors when failing to start Storage emulator (#3443)
- Fixes missing download tokens in Storage Emulator (#3451)
- Fixes `functions:shell` error with background functions (#3490)
18 changes: 9 additions & 9 deletions src/emulator/functionsEmulatorShell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export class FunctionsEmulatorShell implements FunctionsShellController {
}
}

call(id: string, data: any, opts: any): void {
const trigger = this.getTrigger(id);
logger.debug(`shell:${id}: trigger=${JSON.stringify(trigger)}`);
logger.debug(`shell:${id}: opts=${JSON.stringify(opts)}, data=${JSON.stringify(data)}`);
call(name: string, data: any, opts: any): void {
const trigger = this.getTrigger(name);
logger.debug(`shell:${name}: trigger=${JSON.stringify(trigger)}`);
logger.debug(`shell:${name}: opts=${JSON.stringify(opts)}, data=${JSON.stringify(data)}`);

if (!trigger.eventTrigger) {
throw new FirebaseError(`Function ${id} is not a background function`);
throw new FirebaseError(`Function ${name} is not a background function`);
}

const eventType = trigger.eventTrigger.eventType;
Expand All @@ -64,16 +64,16 @@ export class FunctionsEmulatorShell implements FunctionsShellController {
data,
};

this.emu.startFunctionRuntime(id, trigger.name, EmulatedTriggerType.BACKGROUND, proto);
this.emu.startFunctionRuntime(trigger.id, trigger.name, EmulatedTriggerType.BACKGROUND, proto);
}

private getTrigger(id: string): EmulatedTriggerDefinition {
private getTrigger(name: string): EmulatedTriggerDefinition {
const result = this.triggers.find((trigger) => {
return trigger.id === id;
return trigger.name === name;
});

if (!result) {
throw new FirebaseError(`Could not find trigger ${id}`);
throw new FirebaseError(`Could not find trigger ${name}`);
}

return result;
Expand Down

0 comments on commit 2f928b0

Please sign in to comment.