feat: rethrow errors to capture stacktrace (#907)

* feat: rethrow errors to capture stacktrace

* add null check
This commit is contained in:
shamsartem 2023-09-20 18:56:09 +02:00 committed by GitHub
parent 8741c910be
commit 66638afa2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,30 +22,42 @@ function getConfig({
);
}
export function compileFromString({ code, ...commonArgs }) {
const config = getConfig(commonArgs);
const { imports = [] } = commonArgs;
return Aqua.compile(new Input(code), imports, config);
async function compile(...args) {
try {
const res = await Aqua.compile(...args);
return res;
} catch (error) {
if (
typeof error === "object" &&
error !== null &&
"message" in error &&
typeof error.message === "string"
) {
throw new Error(error.message);
}
throw error;
}
}
export function compileFromPath({ filePath, ...commonArgs }) {
const config = getConfig(commonArgs);
const { imports = [] } = commonArgs;
return Aqua.compile(new Path(filePath), imports, config);
export function compileFromString({ code, imports = [], ...commonArgs }) {
return compile(new Input(code), imports, getConfig(commonArgs));
}
export function compileFromPath({ filePath, imports = [], ...commonArgs }) {
return compile(new Path(filePath), imports, getConfig(commonArgs));
}
export function compileAquaCallFromString({
code,
funcCall,
data,
imports = [],
...commonArgs
}) {
const config = getConfig(commonArgs);
const { imports = [] } = commonArgs;
return Aqua.compile(
return compile(
new Call(funcCall, data, new Input(code)),
imports,
config,
getConfig(commonArgs),
);
}
@ -53,13 +65,12 @@ export function compileAquaCallFromPath({
filePath,
funcCall,
data,
imports = [],
...commonArgs
}) {
const config = getConfig(commonArgs);
const { imports = [] } = commonArgs;
return Aqua.compile(
return compile(
new Call(funcCall, data, new Input(filePath)),
imports,
config,
getConfig(commonArgs),
);
}