Improve data extension pattern checking

This commit is contained in:
Koen Vlaswinkel
2023-04-12 08:54:51 +02:00
parent 62619b2364
commit 656e7d6d8a

View File

@@ -133,14 +133,24 @@ async function pickNewModelFile(
return undefined;
}
const dataExtensionPatterns = qlpack.dataExtensions ?? [];
if (!Array.isArray(dataExtensionPatterns)) {
const dataExtensionPatternsValue = qlpack.dataExtensions ?? [];
if (
!(
Array.isArray(dataExtensionPatternsValue) ||
typeof dataExtensionPatternsValue === "string"
)
) {
void showAndLogErrorMessage(
`Expected 'dataExtensions' to be an array in ${qlpackPath}`,
`Expected 'dataExtensions' to be a string or an array in ${qlpackPath}`,
);
return undefined;
}
// The YAML allows either a string or an array of strings
const dataExtensionPatterns = Array.isArray(dataExtensionPatternsValue)
? dataExtensionPatternsValue
: [dataExtensionPatternsValue];
const filename = await window.showInputBox(
{
title: "Enter the name of the new model file",
@@ -152,10 +162,11 @@ async function pickNewModelFile(
return "File already exists";
}
const isInExtensionPack = !relative(extensionPackPath, path).startsWith(
"..",
);
if (!isInExtensionPack) {
const notInExtensionPack = !relative(
extensionPackPath,
path,
).startsWith("..");
if (notInExtensionPack) {
return "File must be in the extension pack";
}