Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: silent does not always work (fixes #851) #861

Closed
wants to merge 1 commit into from

Conversation

uttpal
Copy link
Contributor

@uttpal uttpal commented Jun 23, 2018

No description provided.

@uttpal uttpal changed the title fix: silent does not always work #851 fix: silent does not always work (fixes #851) Jun 23, 2018
@codecov-io
Copy link

Codecov Report

Merging #861 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master    #861   +/-   ##
======================================
  Coverage    95.8%   95.8%           
======================================
  Files          34      34           
  Lines        1262    1262           
======================================
  Hits         1209    1209           
  Misses         53      53
Impacted Files Coverage Δ
src/exec.js 97.1% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aa9d443...5190896. Read the comment docs.

Copy link
Member

@nfischer nfischer left a comment

Choose a reason for hiding this comment

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

Thanks for this quick fix! Left a couple comments, otherwise this is a great help.

@@ -96,7 +96,7 @@ function execSync(cmd, opts, pipe) {
try { common.unlinkSync(stdoutFile); } catch (e) {}

if (code !== 0) {
common.error(stderr, code, { continue: true });
common.error(stderr, code, { continue: true, silent: opts.silent });
Copy link
Member

Choose a reason for hiding this comment

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

Actually, I believe correct behavior (comparing against v0.7.8) is to never print this. So, this should be silent: true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just to clarify, here silent: true will always be there?

Copy link
Member

Choose a reason for hiding this comment

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

In my previous comment, I intended for you to change this line to:

common.error(stderr, code, { continue: true, silent: true });

@@ -85,6 +91,14 @@ test('check if stdout + stderr go to output', t => {
t.is(result.stderr, '1234\n');
});

test('check if stdout + stderr should not be printed to console if silent', t => {
Copy link
Member

Choose a reason for hiding this comment

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

This test is great. Can you also add a second test to handle the case for silent: false?


Optional suggestion: you can replace the command with shell.exec('shx ls resources/file1.txt filethatdoesnotexist'). shx ls is cross-platform, guaranteed to produce both stdout & stderr, and guaranteed to have a non-zero exit code.

Copy link
Contributor Author

@uttpal uttpal Jun 25, 2018

Choose a reason for hiding this comment

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

Above you suggested that silent will always be true, then there will be no silent: falsecase?

Copy link
Member

Choose a reason for hiding this comment

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

Above you suggested that silent will always be true

For this PR, correct behavior is to always pass { silent: true } to common.error(), regardless of config.silent or exec's { silent: true } option.

then there will be no silent: false case?

I think two cases are interesting:

  1. when the user passes silent: true, there should be no stdio
  2. when the user passes silent: false (or, equivalently, the default), the command's stdio should go to stdio, but exec should not also print exec: <something here> to stderr

Does this make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it

Copy link
Member

Choose a reason for hiding this comment

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

@uttpal any update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will fix and add test asap


const CWD = process.cwd();
const ORIG_EXEC_PATH = shell.config.execPath;
shell.config.silent = true;

test.beforeEach(() => {
mocks.init();
Copy link
Member

Choose a reason for hiding this comment

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

This line is OK as written. This actually exposes a bug (#862), which I will handle.

Copy link
Member

Choose a reason for hiding this comment

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

FYI fix is uploaded (#863). It's OK if this PR lands first.

@nfischer nfischer added this to the v0.8.x milestone Jul 12, 2018
@3rd-Eden
Copy link

Any update on this? The current work around is to globally silent the module using sh.config.silent = true so the build-in log function doesn't output anything. It would be nice if this PR could be merged and released.

@nfischer
Copy link
Member

I believe I still need a change from @uttpal (if that's not the case, please let me know I should re-review this).

@nfischer
Copy link
Member

FYI I cherry-picked this to #892

nfischer added a commit that referenced this pull request Oct 27, 2018
Unconditionally apply `silent: true` when calling `common.error()` from
`exec()`. This is because errors are already printed to stderr, or are
intentionally silenced by `shell.config.silent`.

Based on #861 

Fixes #851
@nfischer
Copy link
Member

Close in favor of #892

@nfischer nfischer closed this Oct 27, 2018
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.

None yet

4 participants