Skip to content

Commit

Permalink
error handling with verbose error message
Browse files Browse the repository at this point in the history
  • Loading branch information
stan-dot committed Mar 7, 2024
1 parent 0f20d3b commit 3fa0c6f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/blueapi/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from pydantic import ValidationError, parse_obj_as
import logging
from collections import deque
from functools import wraps
Expand All @@ -16,7 +17,7 @@
from blueapi.messaging import MessageContext
from blueapi.messaging.stomptemplate import StompMessagingTemplate
from blueapi.service.main import start
from blueapi.service.model import WorkerTask
from blueapi.service.model import PlanModel, WorkerTask
from blueapi.service.openapi import (
DOCS_SCHEMA_LOCATION,
generate_schema,
Expand Down Expand Up @@ -182,6 +183,21 @@ def store_finished_event(event: WorkerEvent) -> None:
finished_event.append(event)

parameters = parameters or "{}"
schema: PlanModel = client.get_plan(name)
progress_tracking = f"Trying to run plan: {name} with the expected schema: {schema}"
print(progress_tracking)
try:
text = "Checking supplied parameters against expected parameters..."
print(text)
validated_data = parse_obj_as(type(schema), parameters)
print("Plan params validation successful:", validated_data)
except ValidationError as e:
# Handle the case where the parameters are invalid according to the PlanModel
print(
f"failed to run the {name} plan, supplied params {parameters} do not match the expected params: {schema}"
)
return

task = Task(name=name, params=json.loads(parameters))

resp = client.create_task(task)
Expand Down

0 comments on commit 3fa0c6f

Please sign in to comment.