Skip to content

Commit

Permalink
improve error messages for Nextflow metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rahuldesai1 committed Sep 24, 2024
1 parent fafc1cd commit 58ec6cd
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Types of changes

# Latch SDK Changelog

## 2.52.5 - 2024-09-23

### Changed

* Improve error messaging when registering Nextflow workflows

## 2.52.4 - 2024-09-19

### Changed
Expand Down
18 changes: 14 additions & 4 deletions latch_cli/nextflow/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from pathlib import Path
from textwrap import dedent
from typing import Any, Optional, Type
from typing import Optional, Type, Union

import click

Expand All @@ -11,10 +11,15 @@
from latch_cli.snakemake.utils import reindent


def get_param_type(details: dict) -> Type:
def get_param_type(
details: dict,
) -> Union[
Type[str], Type[bool], Type[int], Type[float], Type["LatchFile"], Type["LatchDir"]
]:
t = details.get("type")
if t is None:
return Any
# rahul: assume string if type is not specified
return str

if t == "string":
format = details.get("format")
Expand All @@ -31,7 +36,7 @@ def get_param_type(details: dict) -> Type:
elif t == "number":
return float

return Any
return str


def generate_metadata(
Expand Down Expand Up @@ -108,6 +113,11 @@ def generate_metadata(
default = None
if generate_defaults and t not in {LatchFile, LatchDir, LatchOutputDir}:
default = details.get("default")
if default is not None:
try:
default = t(default)
except ValueError:
pass

if param not in required_params:
t = Optional[t]
Expand Down
16 changes: 14 additions & 2 deletions latch_cli/nextflow/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,20 @@ def get_results_code_block(parameters: Dict[str, NextflowParameter]) -> str:


def get_nextflow_major_version(pkg_root: Path) -> int:
with (pkg_root / latch_constants.pkg_config).open("r") as f:
config = LatchWorkflowConfig(**json.load(f))
try:
with (pkg_root / latch_constants.pkg_config).open("r") as f:
config = LatchWorkflowConfig(**json.load(f))
except FileNotFoundError:
click.secho(
dedent(f"""
Could not find the latch config file at {pkg_root / latch_constants.pkg_config}
Please check if you package root contains a Dockerfile that was NOT generated
by the Latch CLI. If it does, please move it to a subdirectory and try again.
"""),
fg="red",
)
raise click.exceptions.Exit(1)

if "latch-base-nextflow" not in config.base_image:
return 1
Expand Down
24 changes: 24 additions & 0 deletions latch_cli/services/register/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import time
import webbrowser
from pathlib import Path
from textwrap import dedent
from typing import Iterable, List, Optional

import click
Expand Down Expand Up @@ -228,6 +229,29 @@ def _build_and_serialize(
exit_status = ctx.dkr_client.wait(container_id)
if exit_status["StatusCode"] != 0:
click.secho("\nWorkflow failed to serialize", fg="red", bold=True)
if "TypeTransformerFailedError" in "".join(serialize_logs):
file_to_update = (
"latch_metadata/parameters.py"
if ctx.workflow_type
in (WorkflowType.nextflow, WorkflowType.snakemake)
else "workflow function"
)
click.secho(
dedent(f"""
This is likely caused by a type mismatch between the type of one of
your input parameters and the type of the default value for that
parameter.
To fix this, ensure that the default value for each parameter matches
the type of the parameter itself in your {file_to_update}.
For example, if you have a parameter `x: float` and the default value
`x = 200000`, you will need to update the default value of x to
`200000.0`.
"""),
fg="red",
)

sys.exit(1)

ctx.dkr_client.remove_container(container_id)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

setup(
name="latch",
version="v2.52.4",
version="v2.52.5",
author_email="[email protected]",
description="The Latch SDK",
packages=find_packages(),
Expand Down

0 comments on commit 58ec6cd

Please sign in to comment.