ak
(Ak )
November 3, 2021, 6:00pm
1
Me again. Sorry for posting so much! But I ran into a thing I don’t understand.
This is the structure of my source:
export default {
name: "foo",
version: "1",
description: "bar",
key: "fooBar",
props: {
http: {
type: "$.interface.http",
customResponse: true
}
},
methods: { main },
async run(event) {
this.http.respond({
immediately: true,
status: 200,
body: { succes: true }
});
const emmited = await this.main(event.body)
this.$emit(emmited);
},
};
async function main(data) {
//code here
return `BAZ!`
}
this all works well and good.
then I thought I would run a quick test of main()
in the same file:
if (process.argv.includes(`test`)) {
const result = await main();
log(result)
}
and node foo.js test
runs the test as expected.
but when i try to sync this code back to pipedream with pd dev
… i get a parsing failure:
filechange | /Users/ak/code/foo.js
error | parse failure (Expected ";" but found "main" at foo.js:1175)
something is happening “behind the scenes” that I don’t understand… is main
a reserved keyword somewhere? can someone enlighten me?
<3
dylburger
(Dylan Sather)
November 3, 2021, 6:14pm
2
@ak I tried copying your example, and added a main
function definition to the file, like so:
async function main() {
console.log("foo")
}
export default {
name: "foo",
version: "1",
description: "bar",
key: "fooBar",
props: {
http: {
type: "$.interface.http",
customResponse: true
}
},
methods: { main },
async run(event) {
this.http.respond({
immediately: true,
status: 200,
body: { success: true }
});
const emmited = await this.main(event.body)
this.$emit(emmited);
},
};
When I run pd dev
on this file, the source deploys correctly and the main
method runs when I send an HTTP request to its endpoint.
It seems like there may be a syntax error in the code, probably outside of the component definition. Do you use ESLint or another linter that checks for syntax errors or surfaces them in your editor? If you can’t spot it, are you able to share the full code here / in a sample GitHub repo?
Thanks,
Dylan
ak
(Ak )
November 3, 2021, 6:28pm
3
@dylburger yea this works for me too.
it seems the problem is in using process.argv
to run a test outside of pipedream.
in that SAME file, outside the scope of the export
try:
if (process.argv.includes(`test`)) {
await main();
}
now run your script (locally) as node yourFile.js test
find that your test runs
then observe that pd dev
can’t parse it.
dylburger
(Dylan Sather)
November 3, 2021, 6:48pm
4
Thanks, I totally missed you mentioning that worked above.
Top-level await should theoretically work, but the parser is complaining for that specific reason. I’m chatting with the team about how to address, but for now, wrapping in an async IIFE should work. Can you try this and let me know if it works for you?
if (process.argv.includes(`test`)) {
(async () => {
await foo();
})();
}
ak
(Ak )
November 3, 2021, 7:15pm
5
HA! @dylburger
that totally worked!
btw that syntax works locally because my package.json
has:
"type": "module"
but i guess that trips up your typechecker.
Thanks for unblocking me, once again! You’re the man!
EDIT: spoke too soon…
Updating...
error | bailing due to observation errors
1 Like
ak
(Ak )
November 3, 2021, 7:48pm
6
whoa… i definitely busted this… can’t even delete the component now:
can reach out via support@ if that’s a more appropriate place.
dylburger
(Dylan Sather)
November 3, 2021, 7:52pm
7
Could you try ticking the Force switch and attempting deletion one more time?
ak
(Ak )
November 3, 2021, 11:18pm
8
@dylburger this is resolved. im good now.
fwiw (in case it helps) the client side typechecker of pd
didn’t like this construction:
if (process.argv.includes(`test`)) {
await main(testData)
}
the server-side typechecker of pd
didn’t like this construction:
if (process.argv.includes(`test`)) {
(async () => {
const result = await main(testData);
log(result);
})();
}
both seem to be fine with these statements:
if (process.argv.includes(`test`)) {
(async () => {
log(await main(testData));
})();
}
Now i have testing and CI - in a single file! YAY!
dylburger
(Dylan Sather)
November 4, 2021, 12:08am
9
Thank you for the deep dive. I’ll pass the info on to our team to see if we can address