Skip to content

mdox-exec: Also add newline when non-zero exit code - #103

Merged
saswatamcode merged 1 commit into
bwplotka:mainfrom
olivierlemasle:fix-eol
Jan 25, 2023
Merged

saswatamcode merged 1 commit into
bwplotka:mainfrom
olivierlemasle:fix-eol

Conversation

@olivierlemasle

Copy link
Copy Markdown
Contributor

A new line (\n) is added at the end of mdox-exec output, but only when the exit code is 0 (not when using a non-zero mdox-expect-exit-code):

// Add newline to output if not present.
if !bytes.HasSuffix(output, newLineChar) {
output = append(output, newLineChar...)
}

The new line should always be added (if not present).

Tests are updated to use echo -n (prints no \n).

@saswatamcode saswatamcode left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for fixing!

One small suggestion. 🙂

Comment thread pkg/mdformatter/mdgen/mdgen.go Outdated
expectedCode, _ := strconv.Atoi(infoStringAttr[infoStringKeyExitCode])
if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == expectedCode {
return b.Bytes(), nil
if exitErr, ok := err.(*exec.ExitError); !ok || exitErr.ExitCode() != expectedCode {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe we should return a separate error if !ok and exitErr.ExitCode() != expectedCode?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've updated the PR to differentiate these errors.

@saswatamcode saswatamcode left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks!

@saswatamcode
saswatamcode merged commit a3c7a83 into bwplotka:main Jan 25, 2023
@olivierlemasle
olivierlemasle deleted the fix-eol branch January 25, 2023 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址