transform-hub
transform-hub copied to clipboard
Parse errors do not show up in logs
Describe the bug This bug is linked with issue #601 , where after getting an error message in STH logs:
2022-07-19T12:27:33.417Z ERROR CSIC:217f804-... Instance promise rejected [ { message: 'Sequence failed on start', exitcode: 22 } ]
2022-07-19T12:27:33.417Z INFO CSIC:217f804-... Instance status: errored [ { message: 'Sequence failed on start', exitcode: 22 } ]
we do not know what caused the sequence start failure. It could be determined after running the app in node (node index.js
)
Steps to Reproduce Create a Sequence and run it with node so that SyntaxError could be seen:
- Create a Sequence:
- index.js:
import https from "https";
async function wait(timeInMs) {
await new Promise(res => setTimeout(res, timeInMs));
}
async function getPageFromAPI() {
const options = {
method: "GET",
hostname: "thecocktaildb.com",
port: null,
path: "/api/json/v1/1/search.php?s=margarita",
};
const req = https.request(options, function(res) {
let chunks = "";
res.on("data", function(chunk) {
chunks += chunk;
});
res.on("end", function() {
const json = JSON.parse(chunks);
console.log(json);
});
});
req.on("error", (e) => {
console.error(e);
});
req.end();
};
async function app (_stream) {
try {
while (true) {
await getPageFromAPI();
await wait(5000);
}
} catch (e) {
console.error(e);
}
};
app();
- package.json:
{
"name": "@scramjet/app",
"version": "0.1.0",
"description": "",
"license": "ISC",
"author": "Scramjet <[email protected]>",
"main": "index.js",
"engines": {
"node": "^14.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/scramjetorg/transform-hub.git"
}
}
- Run the app:
node index.js
- You should receive the error:
$ node index.js
(node:3597756) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/home/atylenda/shared/platform-samples/javascript/json-url-app/index.js:1
import https from "https";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
- Now send this sequence to STH, but first in
index.js
remove the function call and addmodule.exports
toasync function app ()
, like this:
import https from "https";
async function wait(timeInMs) {
await new Promise(res => setTimeout(res, timeInMs));
}
async function getPageFromAPI() {
const options = {
method: "GET",
hostname: "thecocktaildb.com",
port: null,
path: "/api/json/v1/1/search.php?s=margarita",
};
const req = https.request(options, function(res) {
let chunks = "";
res.on("data", function(chunk) {
chunks += chunk;
});
res.on("end", function() {
const json = JSON.parse(chunks);
console.log(json);
});
});
req.on("error", (e) => {
console.error(e);
});
req.end();
};
module.exports = async function app (_stream) {
try {
while (true) {
await getPageFromAPI();
await wait(5000);
}
} catch (e) {
console.error(e);
}
};
- start
sth
&si seq deploy seq-name
-
si
command will return an error:
$ si seq deploy /home/atylenda/shared/platform-samples/javascript/json-url-app
Error: { message: 'Sequence failed on start', exitcode: 22 }
STH logs should show:
2022-07-19T13:41:31.495Z ERROR CSIC:264d924-... Sequence finished with error [ 22 ]
2022-07-19T13:41:31.495Z ERROR CSIC:264d924-... Crashlog [
[
'',
'{"level":"TRACE","msg":"Monitoring interval removed","ts":1658238091268,"from":"Runner","Runner":{"id":"264d9242-866e-4a72-8b4d-6408c9a536ab"}}\n' +
'{"level":"INFO","msg":"Cleaning up streams","ts":1658238091268,"from":"Runner","Runner":{"id":"264d9242-866e-4a72-8b4d-6408c9a536ab"}}\n' +
'{"level":"TRACE","msg":"Disconnecting from host","ts":1658238091268,"from":"HostClient","Runner":{"id":"264d9242-866e-4a72-8b4d-6408c9a536ab"}}\n'
]
]
2022-07-19T13:41:31.495Z INFO CSIC:264d924-... Cleanup completed
2022-07-19T13:41:31.496Z ERROR CSIC:264d924-... Instance promise rejected [ { message: 'Sequence failed on start', exitcode: 22 } ]
2022-07-19T13:41:31.496Z INFO CSIC:264d924-... Instance status: errored [ { message: 'Sequence failed on start', exitcode: 22 } ]
2022-07-19T13:41:31.496Z ERROR Host CSIController errored [ 'Sequence failed on start', 22 ]
2022-07-19T13:41:31.497Z TRACE Auditor Requestor, tx, rx [ 'system', 26, 0 ]
2022-07-19T13:41:31.497Z DEBUG Host Request [
'date: 2022-07-19T13:41:28.989Z, method: POST, url: /api/v1/sequence/1cade31d-240d-4fd3-baa5-f966aa38827e/start, status: 400'
]
Expected behavior
The error message shown in node index.js
execution should be seen in STH logs, si
command should also return more info about the error.
The Sequence works just fine when use const https = require("https");
instead of import https from "https";
Version (please complete the following information):
- STH version:
0.26.1
- node version:
v16.13.2
- os: Ubuntu 20.4
2022-07-19T13:41:31.496Z ERROR Host CSIController errored [ 'Sequence failed on start', 22 ]
https://github.com/scramjetorg/transform-hub/blob/70b378d933e25064523d087a3fac2b0ff27dce23/packages/symbols/src/runner-exit-code.ts#L4
one of the reasons of 22
is a syntax error.