shy-finland-77998
12/22/2018, 9:09 PMerror: Error serializing '(ev, ctx, cb) => { let body; ...': api.js(189,21)
'(ev, ctx, cb) => { let body; ...': api.js(189,21): captured
variable 'handlers' which indirectly referenced
function '<anonymous>': organizations.ts(5,14): which could not be serialized because
arrow function captured 'this'. Assign 'this' to another name outside function and capture that.
Function code:
(req, res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const results = yield organization_1.getOrganizations();
res.status(200).json({
results: results
Looking at the compiled JS, it looks like TS is doing this:
exports.all = (req, res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
And Pulumi isn’t liking the this
that it adds in there.white-balloon-205
this
in a serialized function currently, but I’m curious what this case is where TS is generating something that triggers this.shy-finland-77998
12/22/2018, 9:13 PMthis
here…TS is generating it.ts
file:
import { getOrganizations } from '../data/models/organization'
export let all = async (req: any, res: any) => {
try {
const results = await getOrganizations();
res.status(200).json({
results: results
});
} catch (e) {
res.status(400).json({ e });
}
};
And the compiled version of it:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const organization_1 = require("../data/models/organization");
exports.all = (req, res) => tslib_1.__awaiter(this, void 0, void 0, function* () {
try {
const results = yield organization_1.getOrganizations();
res.status(200).json({
results: results
});
}
catch (e) {
res.status(400).json({ e });
}
});
await/asyc
keywords and the tslib awaiter
helper that is used__awaiter
which drops this
in as a param…which causes pulumi to choke while serializing the functionthis
isn’t in the module’s scope.export class OrganizationEndpoint {
async all(req: any, res: any) {
import('../data/models/organization');
try {
const model = new OrganizationModel();
const results = await model.all();
res.status(200).json({
results: results
});
} catch (e) {
res.status(400).json({ e });
}
};
}
all
so that “this” is not in the module scope. Then I still have to use that weird import
inside the method so it will work too.error: Error serializing '(ev, ctx, cb) => { let body; ...': api.js(189,21)
'(ev, ctx, cb) => { let body; ...': api.js(189,21): captured
variable 'handlers' which indirectly referenced
function 'all': organizations.ts(6,7): which captured
module './packages/api/data/models/organization.ts' which indirectly referenced
function 'OrganizationModel': organization.ts(7,15): which captured
module './packages/api/data/connection.ts' which indirectly referenced
function '<anonymous>': domain.js(431,38): which captured
'ERR_UNHANDLED_ERROR', a function defined at
function 'NodeError': errors.js(158,15): which referenced
function 'getMessage': errors.js(213,19): which captured
variable 'messages' which indirectly referenced
function 'get': which could not be serialized because
it was a native code function.
Function code:
function get() { [native code] }
cold-coat-35200
12/23/2018, 9:27 AMshy-finland-77998
12/23/2018, 8:50 PMcold-coat-35200
12/23/2018, 8:54 PMshy-finland-77998
12/23/2018, 8:55 PMthis
isn’t inside the module scope__awaiter
helper so that this
doesn’t screw things upwhite-balloon-205
shy-finland-77998
12/23/2018, 11:24 PM