From bd8a19d9ead0656a5870e66aacf583bf26442c7f Mon Sep 17 00:00:00 2001 From: bsrdjan Date: Tue, 2 Feb 2021 11:11:37 +0100 Subject: [PATCH] closes #8, closes #9; Fix exceptions raised for non-mandatory configurations --- abap-api-tools/package-lock.json | 4 ++-- abap-api-tools/package.json | 2 +- abap-api-tools/src/ts/backend.ts | 25 +++++++++++++++++-------- abap-api-tools/src/ts/constants.ts | 10 ++++++---- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/abap-api-tools/package-lock.json b/abap-api-tools/package-lock.json index 736c574b..d425c397 100644 --- a/abap-api-tools/package-lock.json +++ b/abap-api-tools/package-lock.json @@ -1,11 +1,11 @@ { "name": "abap-api-tools", - "version": "1.2.1", + "version": "1.2.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "1.2.1", + "version": "1.2.2", "cpu": [ "!arm" ], diff --git a/abap-api-tools/package.json b/abap-api-tools/package.json index 60475023..f37ee65e 100644 --- a/abap-api-tools/package.json +++ b/abap-api-tools/package.json @@ -1,7 +1,7 @@ { "name": "abap-api-tools", "description": "ABAP api tools", - "version": "1.2.1", + "version": "1.2.2", "homepage": "https://github.com/sap/fundamental-tools", "author": "SAP", "license": "Apache-2.0", diff --git a/abap-api-tools/src/ts/backend.ts b/abap-api-tools/src/ts/backend.ts index 3c343f34..b2b18035 100644 --- a/abap-api-tools/src/ts/backend.ts +++ b/abap-api-tools/src/ts/backend.ts @@ -198,18 +198,27 @@ export class Backend { this.client = new Client(connectionParameters); try { - const systemYmlPath = path.join(DefaultFolder.userConfig, "systems.yaml"); - const systems = yamlLoad(systemYmlPath) as SystemsYamlType; - if (this.argv.dest && systems[this.argv.dest]) { + const systemYamlPath = path.join( + DefaultFolder.userConfig, + "systems.yaml" + ); + const systems = yamlLoad(systemYamlPath) as SystemsYamlType; + if ( + this.argv.dest && + systems[this.argv.dest] && + systems[this.argv.dest].search_help_api + ) { this.search_help_api = systems[this.argv.dest].search_help_api; - for (const k of Object.keys(this.search_help_api)) { - if (!["determine", "dom_values"].includes(k)) { - throw new Error(`Invalid key "${k}" found in ${systemYmlPath}`); + for (const [apiKey, apiName] of Object.entries(this.search_help_api)) { + if (!["determine", "dom_values"].includes(apiKey)) { + throw new Error( + `Invalid key "${apiKey}" found in ${systemYamlPath}` + ); } - if (this.search_help_api[k].length > 30) { + if (apiName.length > 30) { throw new Error( - `Too long API name: ${this.search_help_api[k]}, found in ${systemYmlPath}[${this.argv.dest}][${k}]` + `Too long API name "${apiName}" found in ${systemYamlPath}` ); } } diff --git a/abap-api-tools/src/ts/constants.ts b/abap-api-tools/src/ts/constants.ts index f701179b..665ef6d1 100644 --- a/abap-api-tools/src/ts/constants.ts +++ b/abap-api-tools/src/ts/constants.ts @@ -140,10 +140,12 @@ export const DefaultFolder = Object.freeze({ }); const localFrameworks: string[] = []; -for (const fileName of fs.readdirSync(DefaultFolder.userConfig)) { - const m = fileName.match(/-abap.yaml$/); - if (m !== null) { - localFrameworks.push(fileName.substring(0, m.index)); +if (fs.existsSync(DefaultFolder.userConfig)) { + for (const fileName of fs.readdirSync(DefaultFolder.userConfig)) { + const m = fileName.match(/-abap.yaml$/); + if (m !== null) { + localFrameworks.push(fileName.substring(0, m.index)); + } } } export const UIFrameworksLocal = Object.freeze(localFrameworks);