nextflow icon indicating copy to clipboard operation
nextflow copied to clipboard

Provide a special class for pipeline-defined error messages

Open jfy133 opened this issue 4 months ago • 4 comments

New feature

It would be nice to have a special error class or function for pipeline-level errors or warnings, that help distinguish pipeline-defined (conditional) errors versus Nextflow level errors

Usage scenario

Pipelines will often have their own checks or validations, for example mutually exclusive parameters, that they will want to report to a user. Currently it is expected that a pipeline uses error("error message") to report this.

Often these are 'simple' errors, compared to Nextflow errors that have a more technical reason for the problem.

It might nice to be able to distinguish such pipeline-level errors from Nextflow errors. One benefit would be that it makes it much faster to identify where the error is coming from for developers, so they can quickly guide a user to a solution (i.e., whether it's a simple fix, or something the developer needs to investigate deeper.

Currently I do this manually by adding a prefix to warnings or logs, but it could be nice to have this happen automatically. Furthermore the way to report an error vs warning is slightly different (to my understanding anyway).

e.g. to report an error I do the following with the pipeline name as a prefix:

if (params.shortread_qc_includeunmerged && !params.shortread_qc_mergepairs) error("ERROR: [nf-core/taxprofiler] cannot include unmerged reads when merging is not turned on. Please specify --shortread_qc_mergepairs")

https://github.com/nf-core/taxprofiler/blob/45ce748534872c5105a5d3a94b83f47cd44f8826/workflows/taxprofiler.nf#L36

vs a warning

if (params.diamond_save_reads              ) log.warn "[nf-core/taxprofiler] DIAMOND only allows output of a single format. As --diamond_save_reads supplied, only aligned reads in SAM format will be produced, no taxonomic profiles will be available."

https://github.com/nf-core/taxprofiler/blob/45ce748534872c5105a5d3a94b83f47cd44f8826/workflows/taxprofiler.nf#L48

Where I have to manually specify ERROR: in when using error(), but the log.warn() autmatically puts WARN at the beginning. I guess there is a log.error but my understanding this doesn't cause the pipeline run to exit 'nicely'.

Suggest implementation

Could be nice to have something a native pipelineError("") - thing the prefixes the workflow name at the beginning etc.

It could also have a distinct colour from a Nextflow level error.

More info

I initially brought this up for discussion with nf-core (in particular @ewels and @maxulysse) here: https://nfcore.slack.com/archives/C04QR0T3G3H/p1713533132261319 based on the suggestion from @Midnighter here: https://github.com/nf-core/taxprofiler/pull/60#discussion_r852845213.

All three may be able to provide better (technical) suggestions and/or benefits.

jfy133 avatar Apr 20 '24 12:04 jfy133