serverless / compose

Orchestrate Serverless Framework in monorepos
https://serverless.com/framework/docs/guides/compose
MIT License
110 stars 15 forks source link

Fixes stack output parsing by stripping ANSI #166

Closed Christop406 closed 1 year ago

Christop406 commented 1 year ago

This PR fixes an issue I have been running into when calling deploy using serverless/compose, in which, after deploy, I would get this error message:

project › Error: Impossible to parse the output of "serverless info":

An example of the full error:

project › Stack Outputs:
project ›   BucketName: ...
project ›   ServerlessDeploymentBucketName: ....
project › Need a better logging experience than CloudWatch? Try our Dev Mode in console: run "serverless --console"
project › error
project › Impossible to parse the output of "serverless info":
project › service: ...
project › stage: dev
project › region: us-east-1
project › stack: ...
project › 
project › Stack Outputs:
project ›   BucketName: ...
project ›   ServerlessDeploymentBucketName: ...
project › 
project › Error: Impossible to parse the output of "serverless info":
project › service: ...
project › stage: dev
project › region: us-east-1
project › stack: ...
project › 
project › Stack Outputs:
project ›   BucketName: ...
project ›   ServerlessDeploymentBucketName: ...
project › 
project ›    <stack trace>
Verbose logs are available in ".serverless/compose.log"
 >  NX   ERROR: Something went wrong in run-commands - Command failed: serverless project:deploy
   Pass --verbose to see the stacktrace.

Which causes the process to exit with a non-zero exit code, causing things like CI pipeline failures.

I played around with the code a bit and figured out it was the ANSI characters (for colors, I assume) that seemed to be messing up the YAML.parse call. The text looked similar to this:

'\x1B[90mservice:\x1B[39m service-name\n' +
    '\x1B[90mstage:\x1B[39m dev\n' +
    '\x1B[90mregion:\x1B[39m us-east-1\n' +
    '\x1B[90mstack:\x1B[39m service-name-dev\n' +
    '\x1B[90m\x1B[39m\n' +
    '\x1B[90mStack Outputs:\x1B[39m\n' +
    '\x1B[90m\x1B[39m  BucketName: bucket-name\n' +
    '  ServerlessDeploymentBucketName: bucket-name\n'

By adding a stripAnsi call around the text before it is parsed by the YAML parser, we get something that looks much better:

'service: service-name\n' +
    'stage: dev\n' +
    'region: us-east-1\n' +
    'stack: service-name-dev\n' +
    '\n' +
    'Stack Outputs:\n' +
    '  BucketName: bucket-name\n' +
    '  ServerlessDeploymentBucketName: bucket-name\n'

All tests still pass, and I was able to verify this fix on my end. Let me know if more is needed.

My system specs:

MacOS Ventura 13.0 ARM (M1 Pro) NPM 8.19.2 Node v16.15.1 Serverless 3.24.0 Compose 1.3.0

Christop406 commented 1 year ago

Hey, just bumping this for visibility, anything else I need to do here?

lucasvieirasilva commented 1 year ago

could we have this change released?