nodejs plugin: build fails if there are missing peer dependencies.

Bug #1819804 reported by TheBITLINK aka BIT
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Snapcraft
New
Undecided
Unassigned

Bug Description

This happens when trying to run `npm ls --json` at the build stage.

If there are any missing peer dependencies, the command exits with a non-zero exit code.

However, most of the time those errors can be safely ignored.

An attempt to mitigate this is already in place:

```
def _get_installed_node_packages(self, cwd):
    # There is no yarn ls
    cmd = [os.path.join(self._npm_dir, "bin", "npm"), "ls", "--json"]
    try:
        output = self.run_output(cmd, cwd)
    except subprocess.CalledProcessError as error:
        # XXX When dependencies have missing dependencies, an error like
        # this is printed to stderr:
        # npm ERR! peer dep missing: glob@*, required by glob-promise@3.1.0
        # retcode is not 0, which raises an exception.
        output = error.output.decode(sys.getfilesystemencoding()).strip()
```

However, `run_output()` itself captures the `CalledProcessError`, rasing a different type of exception (SnapcraftPluginCommandError):

```
def run_output(self, cmd, cwd=None, **kwargs):
    if not cwd:
        cwd = self.builddir
    os.makedirs(cwd, exist_ok=True)
    try:
        return common.run_output(cmd, cwd=cwd, **kwargs)
    except CalledProcessError as process_error:
        raise errors.SnapcraftPluginCommandError(
            command=cmd, part_name=self.name, exit_code=process_error.returncode
        ) from process_error
```

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.