-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunner.js
More file actions
44 lines (37 loc) · 1.23 KB
/
runner.js
File metadata and controls
44 lines (37 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import 'dotenv/config';
import { run } from './code.js';
async function main() {
try {
// Get the JSON input from command line arguments
const args = process.argv.slice(2);
if (args.length === 0) {
console.error('Error: No input provided');
console.error('Usage: npm start -- \'{"key": "value"}\'');
process.exit(1);
}
// Parse the JSON input
const inputString = args.join(' ');
let input;
try {
input = JSON.parse(inputString);
} catch (parseError) {
console.error('Error: Invalid JSON input');
console.error('Received:', inputString);
console.error('Error:', parseError.message);
process.exit(1);
}
// Run the function
const result = await run(input);
// Print the result as JSON
console.log(JSON.stringify(result, null, 2));
} catch (error) {
console.error('\n❌ Exception thrown from code.js:\n');
console.error('Error:', error.message);
console.error('\nStack trace:');
console.error(error.stack);
console.error('\nℹ️ Note: In Glide, throwing an exception triggers an automatic retry.');
console.error(' This is useful for transient errors like API 500 responses.\n');
process.exit(1);
}
}
main();