From b072fda83ac4775f0948480f7a6be1ad35162eba Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Sun, 12 Dec 2021 21:03:12 +0000 Subject: [PATCH 1/3] fix(deploy): handle SAS9 execution error gracefully --- src/commands/deploy/deploy.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/commands/deploy/deploy.ts b/src/commands/deploy/deploy.ts index 404864e86..76185bfe1 100644 --- a/src/commands/deploy/deploy.ts +++ b/src/commands/deploy/deploy.ts @@ -1,6 +1,6 @@ import path from 'path' import os from 'os' -import SASjs from '@sasjs/adapter/node' +import SASjs, { JobExecutionError } from '@sasjs/adapter/node' import { getAuthConfig, getStreamConfig } from '../../utils/config' import { displaySasjsRunnerError, executeShellScript } from '../../utils/utils' import { @@ -252,16 +252,27 @@ async function deployToSas9( }) const executionResult = await sasjs .executeScriptSAS9(linesToExecute, username, password) - .catch((err) => { - process.logger?.log(formatErrorString(err)) + .catch(async (err) => { if (err && err.errorCode === 404) { displaySasjsRunnerError(username) + } else if (err instanceof JobExecutionError) { + process.logger?.error('Deployment completed with errors.') + const errorLogPath = path.join( + logFilePath || process.cwd(), + `${path.basename(deployScript).replace('.sas', '')}.error.log` + ) + await createFile( + errorLogPath, + err.result + ) + process.logger?.info(`Error log is available at ${errorLogPath}`) + throw new Error() + } else { + process.logger?.error(formatErrorString(err)) } }) - if (!executionResult) { - process.logger?.error('Error getting execution log') - } else if (logFilePath) { + if (executionResult && logFilePath) { await createFile( path.join( logFilePath, From 2a076dd14d4e1a6b3e480d3a68290b676e95fb01 Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Sun, 12 Dec 2021 21:12:40 +0000 Subject: [PATCH 2/3] fix(deploy): change error log path --- src/commands/deploy/deploy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/deploy/deploy.ts b/src/commands/deploy/deploy.ts index 76185bfe1..a76ad7b90 100644 --- a/src/commands/deploy/deploy.ts +++ b/src/commands/deploy/deploy.ts @@ -259,7 +259,7 @@ async function deployToSas9( process.logger?.error('Deployment completed with errors.') const errorLogPath = path.join( logFilePath || process.cwd(), - `${path.basename(deployScript).replace('.sas', '')}.error.log` + `${path.basename(deployScript).replace('.sas', '')}.log` ) await createFile( errorLogPath, From fdaac3146e1ae674537bff97cd93be907e85858f Mon Sep 17 00:00:00 2001 From: Krishna Acondy Date: Sun, 12 Dec 2021 21:14:16 +0000 Subject: [PATCH 3/3] chore(deploy): fix code style --- src/commands/deploy/deploy.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/commands/deploy/deploy.ts b/src/commands/deploy/deploy.ts index a76ad7b90..69e22fa6f 100644 --- a/src/commands/deploy/deploy.ts +++ b/src/commands/deploy/deploy.ts @@ -261,10 +261,7 @@ async function deployToSas9( logFilePath || process.cwd(), `${path.basename(deployScript).replace('.sas', '')}.log` ) - await createFile( - errorLogPath, - err.result - ) + await createFile(errorLogPath, err.result) process.logger?.info(`Error log is available at ${errorLogPath}`) throw new Error() } else {