Repository: nf-core/tools

Issue:
[BUG] KeyError when installing modules
## Check Documentation

I have checked the following places for your error:

- [x] [nf-core website: troubleshooting](https://nf-co.re/usage/troubleshooting)
- [x] [nf-core/module documentation](https://github.com/nf-core/modules/blob/master/README.md)

## Description of the bug
Module installation fails.
nf-core/tools version 2.2


## Steps to reproduce

Steps to reproduce the behaviour:

1. Try installing a module, eg`$ nf-core modules install bwa/mem`
2. See error: 

```
                                          ,--./,-.
          ___     __   __   __   ___     /,-._.--~\
    |\ | |__  __ /  ` /  \ |__) |__         }  {
    | \| |       \__, \__/ |  \ |___     \`-._,-`-,
                                          `._,._,'

    nf-core/tools version 2.2



INFO     Creating missing 'module.json' file.                                                                                                                                                                                                             modules_command.py:107
╭───────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/bin/nf-core:10 in <module>                                                                                                                                        │
│                                                                                                                                                                                                      │
│    9 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                                                                                                                            │
│ ❱ 10 │   sys.exit(run_nf_core())                                                                                                                                                                     │
│   11                                                                                                                                                                                                 │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/nf_core/__main__.py:62 in run_nf_core                                                                                                 │
│                                                                                                                                                                                                      │
│    61 │   # Lanch the click cli                                                                                                                                                                      │
│ ❱  62 │   nf_core_cli()                                                                                                                                                                              │
│    63                                                                                                                                                                                                │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/click/core.py:1128 in __call__                                                                                                        │
│                                                                                                                                                                                                      │
│   1127 │   │   """Alias for :meth:`main`."""                                                                                                                                                         │
│ ❱ 1128 │   │   return self.main(*args, **kwargs)                                                                                                                                                     │
│   1129                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/click/core.py:1053 in main                                                                                                            │
│                                                                                                                                                                                                      │
│   1052 │   │   │   │   with self.make_context(prog_name, args, **extra) as ctx:                                                                                                                      │
│ ❱ 1053 │   │   │   │   │   rv = self.invoke(ctx)                                                                                                                                                     │
│   1054 │   │   │   │   │   if not standalone_mode:                                                                                                                                                   │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/click/core.py:1659 in invoke                                                                                                          │
│                                                                                                                                                                                                      │
│   1658 │   │   │   │   with sub_ctx:                                                                                                                                                                 │
│ ❱ 1659 │   │   │   │   │   return _process_result(sub_ctx.command.invoke(sub_ctx))                                                                                                                   │
│   1660                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/click/core.py:1659 in invoke                                                                                                          │
│                                                                                                                                                                                                      │
│   1658 │   │   │   │   with sub_ctx:                                                                                                                                                                 │
│ ❱ 1659 │   │   │   │   │   return _process_result(sub_ctx.command.invoke(sub_ctx))                                                                                                                   │
│   1660                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/click/core.py:1395 in invoke                                                                                                          │
│                                                                                                                                                                                                      │
│   1394 │   │   if self.callback is not None:                                                                                                                                                         │
│ ❱ 1395 │   │   │   return ctx.invoke(self.callback, **ctx.params)                                                                                                                                    │
│   1396                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/click/core.py:754 in invoke                                                                                                           │
│                                                                                                                                                                                                      │
│    753 │   │   │   with ctx:                                                                                                                                                                         │
│ ❱  754 │   │   │   │   return __callback(*args, **kwargs)                                                                                                                                            │
│    755                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/click/decorators.py:26 in new_func                                                                                                    │
│                                                                                                                                                                                                      │
│    25 │   def new_func(*args, **kwargs):  # type: ignore                                                                                                                                             │
│ ❱  26 │   │   return f(get_current_context(), *args, **kwargs)                                                                                                                                       │
│    27                                                                                                                                                                                                │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/nf_core/__main__.py:436 in install                                                                                                    │
│                                                                                                                                                                                                      │
│   435 │   │   module_install.modules_repo = ctx.obj["modules_repo_obj"]                                                                                                                              │
│ ❱ 436 │   │   exit_status = module_install.install(tool)                                                                                                                                             │
│   437 │   │   if not exit_status and all:                                                                                                                                                            │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/nf_core/modules/install.py:28 in install                                                                                              │
│                                                                                                                                                                                                      │
│    27 │   │   # Check whether pipelines is valid                                                                                                                                                     │
│ ❱  28 │   │   if not self.has_valid_directory():                                                                                                                                                     │
│    29 │   │   │   return False                                                                                                                                                                       │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/nf_core/modules/modules_command.py:98 in has_valid_directory                                                                          │
│                                                                                                                                                                                                      │
│    97 │   │   try:                                                                                                                                                                                   │
│ ❱  98 │   │   │   self.has_modules_file()                                                                                                                                                            │
│    99 │   │   │   return True                                                                                                                                                                        │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/nf_core/modules/modules_command.py:109 in has_modules_file                                                                            │
│                                                                                                                                                                                                      │
│   108 │   │   │   try:                                                                                                                                                                               │
│ ❱ 109 │   │   │   │   nf_core.modules.module_utils.create_modules_json(self.dir)                                                                                                                     │
│   110 │   │   │   except UserWarning as e:                                                                                                                                                           │
│                                                                                                                                                                                                      │
│ /home/paul/anaconda3/envs/nf-tools/lib/python3.7/site-packages/nf_core/modules/module_utils.py:129 in create_modules_json                                                                            │
│                                                                                                                                                                                                      │
│   128 │   pipeline_config = nf_core.utils.fetch_wf_config(pipeline_dir)                                                                                                                              │
│ ❱ 129 │   pipeline_name = pipeline_config["manifest.name"]                                                                                                                                           │
│   130 │   pipeline_url = pipeline_config["manifest.homePage"]                                                                                                                                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'manifest.name'
```

## Expected behaviour

Successful installation of desired module
## Log files

Have you provided the following extra information/files:

- [ x ] The command used to run the module

## System

- Hardware: Server
- Executor: local
- OS: Ubuntu 18.04.3

## Nextflow Installation

- Version: 21.10.6.5660

## Container engine

- Engine: Conda
- version: 4.9.0
- Image tag: <!-- [e.g. nfcore/module:2.6] -->

## Additional context

<!-- Add any other context about the problem here. -->



Discussion:
Moved this to tools to get it in front of the right people!

It's a good catch, in the meantime could you try just running `nf-core modules install` and using the interactive selection? 

If that doesn't work, can you copy over a modules.json from another repo and try to install again then?

Resolving patch:
diff --git a/nf_core/modules/module_utils.py b/nf_core/modules/module_utils.py
--- a/nf_core/modules/module_utils.py
+++ b/nf_core/modules/module_utils.py
@@ -126,8 +126,8 @@ def create_modules_json(pipeline_dir):
         pipeline_dir (str): The directory where the `modules.json` should be created
     """
     pipeline_config = nf_core.utils.fetch_wf_config(pipeline_dir)
-    pipeline_name = pipeline_config["manifest.name"]
-    pipeline_url = pipeline_config["manifest.homePage"]
+    pipeline_name = pipeline_config.get("manifest.name", "")
+    pipeline_url = pipeline_config.get("manifest.homePage", "")
     modules_json = {"name": pipeline_name.strip("'"), "homePage": pipeline_url.strip("'"), "repos": dict()}
     modules_dir = f"{pipeline_dir}/modules"
 


Test patch: