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

Escaped test run output before logging it, to avoid a rich MarkupError #1506

Merged
merged 1 commit into from
Apr 1, 2022

Conversation

ewels
Copy link
Member

@ewels ewels commented Apr 1, 2022

Reported by @sateeshperi and @henningonsbring via nf-core/modules#1460

Errors in the test data gave this unhelpful Python traceback error:

MarkupError: closing tag '[/nf-core/test-datasets/modules/data/genomics/sarscov2/genome/db/metamaps.tar.gz]' at position 589 doesn't match any open tag

This was due to the underlying nf-core/tools code logging the output from the test command to the terminal. This happened to include square brackets, which the Rich library was interpreting as formatting markup.

Properly escaping that text before logging it should fix the issue and properly log the error to the terminal.

Untested, as I can't easily replicate the testing error.

Full original log output
nextflow run tests/modules/metamaps/mapdirectly -entry test_metamaps_mapdirectly -c tests/config/nextflow.config --outdir /tmp/tmpxbjzlp64 -work-dir /tmp/tmpenszt8k7                                            
Picked up JAVA_TOOL_OPTIONS:  -Xmx3435m

╭───────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                      │
│ /opt/conda/bin/nf-core:8 in <module>                                                                                                                                                                 │
│                                                                                                                                                                                                      │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                                                                                                                             │
│ ❱ 8 │   sys.exit(run_nf_core())                                                                                                                                                                      │
│   9                                                                                                                                                                                                  │
│ /opt/conda/lib/python3.9/site-packages/nf_core/__main__.py:90 in run_nf_core                                                                                                                         │
│                                                                                                                                                                                                      │
│    89 │   # Lanch the click cli                                                                                                                                                                      │
│ ❱  90 │   nf_core_cli()                                                                                                                                                                              │
│    91                                                                                                                                                                                                │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/click/core.py:1128 in __call__                                                                                                                                │
│                                                                                                                                                                                                      │
│   1127 │   │   """Alias for :meth:`main`."""                                                                                                                                                         │
│ ❱ 1128 │   │   return self.main(*args, **kwargs)                                                                                                                                                     │
│   1129                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/rich_click/rich_click.py:594 in main                                                                                                                          │
│                                                                                                                                                                                                      │
│   593 │   │   try:                                                                                                                                                                                   │
│ ❱ 594 │   │   │   return super().main(*args, standalone_mode=False, **kwargs)                                                                                                                        │
│   595 │   │   except click.ClickException as e:                                                                                                                                                      │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/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:                                                                                                                                                   │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/click/core.py:1659 in invoke                                                                                                                                  │
│                                                                                                                                                                                                      │
│   1658 │   │   │   │   with sub_ctx:                                                                                                                                                                 │
│ ❱ 1659 │   │   │   │   │   return _process_result(sub_ctx.command.invoke(sub_ctx))                                                                                                                   │
│   1660                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/click/core.py:1659 in invoke                                                                                                                                  │
│                                                                                                                                                                                                      │
│   1658 │   │   │   │   with sub_ctx:                                                                                                                                                                 │
│ ❱ 1659 │   │   │   │   │   return _process_result(sub_ctx.command.invoke(sub_ctx))                                                                                                                   │
│   1660                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/click/core.py:1395 in invoke                                                                                                                                  │
│                                                                                                                                                                                                      │
│   1394 │   │   if self.callback is not None:                                                                                                                                                         │
│ ❱ 1395 │   │   │   return ctx.invoke(self.callback, **ctx.params)                                                                                                                                    │
│   1396                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/click/core.py:754 in invoke                                                                                                                                   │
│                                                                                                                                                                                                      │
│    753 │   │   │   with ctx:                                                                                                                                                                         │
│ ❱  754 │   │   │   │   return __callback(*args, **kwargs)                                                                                                                                            │
│    755                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/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                                                                                                                                                                                                │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/nf_core/__main__.py:585 in create_test_yml                                                                                                                    │
│                                                                                                                                                                                                      │
│   584 │   except UserWarning as e:                                                                                                                                                                   │
│ ❱ 585 │   │   log.critical(e)                                                                                                                                                                        │
│   586 │   │   sys.exit(1)                                                                                                                                                                            │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/logging/__init__.py:1493 in critical                                                                                                                                        │
│                                                                                                                                                                                                      │
│   1492 │   │   if self.isEnabledFor(CRITICAL):                                                                                                                                                       │
│ ❱ 1493 │   │   │   self._log(CRITICAL, msg, args, **kwargs)                                                                                                                                          │
│   1494                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/logging/__init__.py:1589 in _log                                                                                                                                            │
│                                                                                                                                                                                                      │
│   1588 │   │   │   │   │   │   │   │    exc_info, func, extra, sinfo)                                                                                                                                │
│ ❱ 1589 │   │   self.handle(record)                                                                                                                                                                   │
│   1590                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/logging/__init__.py:1599 in handle                                                                                                                                          │
│                                                                                                                                                                                                      │
│   1598 │   │   if (not self.disabled) and self.filter(record):                                                                                                                                       │
│ �� 1599 │   │   │   self.callHandlers(record)                                                                                                                                                         │
│   1600                                                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/logging/__init__.py:1661 in callHandlers                                                                                                                                    │
│                                                                                                                                                                                                      │
│   1660 │   │   │   │   if record.levelno >= hdlr.level:                                                                                                                                              │
│ ❱ 1661 │   │   │   │   │   hdlr.handle(record)                                                                                                                                                       │
│   1662 │   │   │   if not c.propagate:                                                                                                                                                               │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/logging/__init__.py:952 in handle                                                                                                                                           │
│                                                                                                                                                                                                      │
│    951 │   │   │   try:                                                                                                                                                                              │
│ ❱  952 │   │   │   │   self.emit(record)                                                                                                                                                             │
│    953 │   │   │   finally:                                                                                                                                                                          │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/rich/logging.py:157 in emit                                                                                                                                   │
│                                                                                                                                                                                                      │
│   156 │   │                                                                                                                                                                                          │
│ ❱ 157 │   │   message_renderable = self.render_message(record, message)                                                                                                                              │
│   158 │   │   log_renderable = self.render(                                                                                                                                                          │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/rich/logging.py:176 in render_message                                                                                                                         │
│                                                                                                                                                                                                      │
│   175 │   │   use_markup = getattr(record, "markup", self.markup)                                                                                                                                    │
│ ❱ 176 │   │   message_text = Text.from_markup(message) if use_markup else Text(message)                                                                                                              │
│   177                                                                                                                                                                                                │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/rich/text.py:270 in from_markup                                                                                                                               │
│                                                                                                                                                                                                      │
│    269 │   │                                                                                                                                                                                         │
│ ❱  270 │   │   rendered_text = render(text, style, emoji=emoji, emoji_variant=emoji_variant)                                                                                                         │
│    271 │   │   rendered_text.justify = justify                                                                                                                                                       │
│                                                                                                                                                                                                      │
│ /opt/conda/lib/python3.9/site-packages/rich/markup.py:160 in render                                                                                                                                  │
│                                                                                                                                                                                                      │
│   159 │   │   │   │   │   except KeyError:                                                                                                                                                           │
│ ❱ 160 │   │   │   │   │   │   raise MarkupError(                                                                                                                                                     │
│   161 │   │   │   │   │   │   │   f"closing tag '{tag.markup}' at position {position} doesn't                                                                                                        │
│       match any open tag"                                                                                                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
MarkupError: closing tag '[/nf-core/test-datasets/modules/data/genomics/sarscov2/genome/db/metamaps.tar.gz]' at position 589 doesn't match any open tag

PR checklist

  • This comment contains a description of changes (with reason)
  • CHANGELOG.md is updated
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

@henningonsbring
Copy link

Ran nf-core modules create-test-yml metamaps/mapdirectly

Got output:

                                          ,--./,-.
          ___     __   __   __   ___     /,-._.--~\
    |\ | |__  __ /  ` /  \ |__) |__         }  {
    | \| |       \__, \__/ |  \ |___     \`-._,-`-,
                                          `._,._,'

    nf-core/tools version 2.3.2 - https://nf-co.re


INFO     Press enter to use default values (shown in brackets) or type your own responses                                                                                                                                                                              test_yml_builder.py:55
Test YAML output path (- for stdout) (tests/modules/metamaps/mapdirectly/test.yml): 
File exists! 'tests/modules/metamaps/mapdirectly/test.yml' Overwrite? [y/n]: y
INFO     Looking for test workflow entry points: 'tests/modules/metamaps/mapdirectly/main.nf'                                                                                                                                                                         test_yml_builder.py:123
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
INFO     Building test meta for entry point 'test_metamaps_mapdirectly'                                                                                                                                                                                               test_yml_builder.py:157
Test name (metamaps mapdirectly test_metamaps_mapdirectly): 
Test command (nextflow run tests/modules/metamaps/mapdirectly -entry test_metamaps_mapdirectly -c tests/config/nextflow.config): 
Test tags (comma separated) (metamaps,metamaps/mapdirectly): 
Test output folder with results (leave blank to run test): 
? Choose software profile Docker
INFO     Running 'metamaps/mapdirectly' test with command:                                                                                                                                                                                                            test_yml_builder.py:321
         nextflow run tests/modules/metamaps/mapdirectly -entry test_metamaps_mapdirectly -c tests/config/nextflow.config --outdir /var/folders/s6/m7vtlhl147bfm538q4cb_z694thzg_/T/tmp5pjokg12 -work-dir                                                                                    
         /var/folders/s6/m7vtlhl147bfm538q4cb_z694thzg_/T/tmp9_vgm1le                                                                                                                                                                                                                        
CRITICAL Error running test workflow (exit code 1)                                                                                                                                                                                                                            __main__.py:585
         N E X T F L O W  ~  version 21.10.6                                                                                                                                                                                                                                                 
         Launching `tests/modules/metamaps/mapdirectly/main.nf`  - revision: 388518e749                                                                                                                                                                                                      
         [-        ] process > test_metamaps_mapdirectly:UNTAR                -                                                                                                                                                                                                              
         [-        ] process > test_metamaps_mapdirectly:METAMAPS_MAPDIRECTLY -                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                             
         executor >  local (1)                                                                                                                                                                                                                                                               
         [1a/057a89] process > test_metamaps_mapdirectly:UNTAR (metamaps.tar.gz) [  0%] 0 of 1                                                                                                                                                                                               
         [-        ] process > test_metamaps_mapdirectly:METAMAPS_MAPDIRECTLY    -                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                             
         executor >  local (1)                                                                                                                                                                                                                                                               
         [1a/057a89] process > test_metamaps_mapdirectly:UNTAR (metamaps.tar.gz) [100%] 1 of 1 ✔                                                                                                                                                                                             
         [-        ] process > test_metamaps_mapdirectly:METAMAPS_MAPDIRECTLY    -                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                             
         executor >  local (1)                                                                                                                                                                                                                                                               
         [1a/057a89] process > test_metamaps_mapdirectly:UNTAR (metamaps.tar.gz) [100%] 1 of 1 ✔                                                                                                                                                                                             
         [-        ] process > test_metamaps_mapdirectly:METAMAPS_MAPDIRECTLY    -                                                                                                                                                                                                           
         Execution aborted due to an unexpected error                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                             
          -- Check script 'tests/modules/metamaps/mapdirectly/../../../../modules/metamaps/mapdirectly/main.nf' at line: 2 or see '.nextflow.log' file for more details                                                                                                                      
                                                                                                                                                                                                                                                                                             
         executor >  local (1)                                                                                                                                                                                                                                                               
         [1a/057a89] process > test_metamaps_mapdirectly:UNTAR (metamaps.tar.gz) [100%] 1 of 1 ✔                                                                                                                                                                                             
         [-        ] process > test_metamaps_mapdirectly:METAMAPS_MAPDIRECTLY    -                                                                                                                                                                                                           
         Execution aborted due to an unexpected error                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                             
          -- Check script 'tests/modules/metamaps/mapdirectly/../../../../modules/metamaps/mapdirectly/main.nf' at line: 2 or see '.nextflow.log' file for more details

Copy link

@henningonsbring henningonsbring left a comment

Choose a reason for hiding this comment

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

Great work

@ewels ewels merged commit 872caee into nf-core:dev Apr 1, 2022
@ewels ewels deleted the rich-escape-module-test-exceptions branch April 1, 2022 15:01
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