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

Updating yarn.list to not fail when when warnings are emitted #6129

Merged
merged 6 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions changelogs/fragments/6127-yarn-ignore-warnings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- yarn - fixes bug where yarn module tasks would fail when warnings were emitted from Yarn. The ``yarn.list`` method was not filtering out warnings (https://github.com/ansible-collections/community.general/issues/6127).
16 changes: 11 additions & 5 deletions plugins/modules/yarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ def _exec(self, args, run_in_check_mode=False, check_rc=True, unsupported_with_g

return None, None

def _process_yarn_error(self, err):
try:
# We need to filter for errors, since Yarn warnings are included in stderr
for line in err.splitlines():
if json.loads(line)['type'] == 'error':
self.module.fail_json(msg=err)
except Exception:
self.module.fail_json(msg="Unexpected stderr output from Yarn: %s" % err, stderr=err)

def list(self):
cmd = ['list', '--depth=0', '--json']

Expand All @@ -244,8 +253,7 @@ def list(self):
# because it only only lists binaries, but `yarn global add` can install libraries too.
result, error = self._exec(cmd, run_in_check_mode=True, check_rc=False, unsupported_with_global=True)

if error:
self.module.fail_json(msg=error)
self._process_yarn_error(error)

for json_line in result.strip().split('\n'):
data = json.loads(json_line)
Expand Down Expand Up @@ -283,9 +291,7 @@ def list_outdated(self):
cmd_result, err = self._exec(['outdated', '--json'], True, False, unsupported_with_global=True)

# the package.json in the global dir is missing a license field, so warnings are expected on stderr
for line in err.splitlines():
if json.loads(line)['type'] == 'error':
self.module.fail_json(msg=err)
self._process_yarn_error(err)

if not cmd_result:
return outdated
Expand Down