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 }) { async function compile(...args) {
const config = getConfig(commonArgs); try {
const { imports = [] } = commonArgs; const res = await Aqua.compile(...args);
return Aqua.compile(new Input(code), imports, config); 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 }) { export function compileFromString({ code, imports = [], ...commonArgs }) {
const config = getConfig(commonArgs); return compile(new Input(code), imports, getConfig(commonArgs));
const { imports = [] } = commonArgs; }
return Aqua.compile(new Path(filePath), imports, config);
export function compileFromPath({ filePath, imports = [], ...commonArgs }) {
return compile(new Path(filePath), imports, getConfig(commonArgs));
} }
export function compileAquaCallFromString({ export function compileAquaCallFromString({
code, code,
funcCall, funcCall,
data, data,
imports = [],
...commonArgs ...commonArgs
}) { }) {
const config = getConfig(commonArgs); return compile(
const { imports = [] } = commonArgs;
return Aqua.compile(
new Call(funcCall, data, new Input(code)), new Call(funcCall, data, new Input(code)),
imports, imports,
config, getConfig(commonArgs),
); );
} }
@ -53,13 +65,12 @@ export function compileAquaCallFromPath({
filePath, filePath,
funcCall, funcCall,
data, data,
imports = [],
...commonArgs ...commonArgs
}) { }) {
const config = getConfig(commonArgs); return compile(
const { imports = [] } = commonArgs;
return Aqua.compile(
new Call(funcCall, data, new Input(filePath)), new Call(funcCall, data, new Input(filePath)),
imports, imports,
config, getConfig(commonArgs),
); );
} }