Skip to content

Commit

Permalink
fix: can deploy error, as json output could not be parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed May 11, 2024
1 parent 880ac14 commit 9cdf34a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/can-deploy/can-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class CanDeploy {
],
this.__argMapping
);
const output: Array<string | Buffer> = [];
let output: Array<string | Buffer> = [];
if (instance.stdout && instance.stderr) {
instance.stdout.on('data', (l) => output.push(l));
instance.stderr.on('data', (l) => output.push(l));
Expand All @@ -110,9 +110,15 @@ export class CanDeploy {

if (this.options.output === 'json') {
try {
const startIndex = output.findIndex((l: string | Buffer) =>
l.toString().startsWith('{')
);
const findJsonIndex = (data: (string | Buffer)[]) =>
data.findIndex((l: string | Buffer) =>
l.toString().startsWith('{')
);
let startIndex = findJsonIndex(output);
if (startIndex === -1) {
output = output.toString().split('\n');
startIndex = findJsonIndex(output);
}
if (startIndex === -1) {
logger.error(
`can-i-deploy produced no json output:\n${result}`
Expand Down

0 comments on commit 9cdf34a

Please sign in to comment.