Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions src/commands/deploy/deploy.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -252,16 +252,24 @@ 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) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Branch ordering blocks the new feature. The adapter's parseError produces a JobExecutionError with errorCode: 404 for both "stored process not found" and "Stored Process Error / This request completed with errors" (the latter carries the SAS log in result). Since this errorCode === 404 check comes first, every JobExecutionError from the SAS9 path falls into this branch and calls displaySasjsRunnerError — the else if (err instanceof JobExecutionError) branch below is never reached for SAS9. Recommend checking err instanceof JobExecutionError first, then distinguishing runner-missing (result empty) from stored-process-error (result has the log).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Regression: the previous code logged formatErrorString(err) for all errors before the 404 check. Now the 404 branch logs nothing about the underlying error (only displaySasjsRunnerError). If this 404 is a JobExecutionError with a real message (not the runner-missing case), the diagnostic detail is lost.

displaySasjsRunnerError(username)
} else if (err instanceof JobExecutionError) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 This branch is only reachable for a JobExecutionError whose errorCode is not 404. Per the adapter's parseError, all SAS9 JobExecutionErrors use errorCode: 404, so this log-saving code is effectively dead on the SAS9 path today. A unit test that mocks executeScriptSAS9 to reject with new JobExecutionError(404, 'This request completed with errors.', '<log>') and asserts the .log file is created would catch this.

process.logger?.error('Deployment completed with errors.')
const errorLogPath = path.join(
logFilePath || process.cwd(),
`${path.basename(deployScript).replace('.sas', '')}.log`
)
await createFile(errorLogPath, err.result)
process.logger?.info(`Error log is available at ${errorLogPath}`)
throw new Error()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 throw new Error() with no message makes the propagated failure opaque to callers and to logs. Consider throw new Error('Deployment completed with errors. See log for details.').

} 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,
Expand Down