Skip to content

Commit f6970ec

Browse files
committed
fix: tailing spaces on project names raises informative error
1 parent 2b66742 commit f6970ec

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

cli/kleinkram/api/routes.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from kleinkram.errors import MissionValidationError
4444
from kleinkram.errors import ProjectExists
4545
from kleinkram.errors import ProjectNotFound
46+
from kleinkram.errors import ProjectValidationError
4647
from kleinkram.models import File
4748
from kleinkram.models import Mission
4849
from kleinkram.models import Project
@@ -350,17 +351,30 @@ def _create_mission(
350351
def _create_project(
351352
client: AuthenticatedClient, project_name: str, description: str
352353
) -> UUID:
353-
if not _project_name_is_available(client, project_name):
354-
raise ProjectExists(f"Project with name: `{project_name}` already exists")
355354

356-
# TODO: check name and description are valid
355+
_validate_project_name(client, project_name, description)
357356
payload = {"name": project_name, "description": description}
358357
resp = client.post(CREATE_PROJECT, json=payload)
359358
resp.raise_for_status()
360359

361360
return UUID(resp.json()["uuid"], version=4)
362361

363362

363+
def _validate_project_name(
364+
client: AuthenticatedClient, project_name: str, description: str
365+
) -> None:
366+
if not _project_name_is_available(client, project_name):
367+
raise ProjectExists(f"Project with name: `{project_name}` already exists")
368+
369+
if project_name.endswith(" "):
370+
raise ProjectValidationError(
371+
f"Project name must not end with a tailing whitespace: `{project_name}`"
372+
)
373+
374+
if not description:
375+
raise ProjectValidationError("Project description is required")
376+
377+
364378
def _validate_tag_value(tag_value, tag_datatype) -> None:
365379
if tag_datatype == "NUMBER":
366380
try:

cli/kleinkram/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ class InvalidMissionMetadata(Exception): ...
5252
class MissionValidationError(Exception): ...
5353

5454

55+
class ProjectValidationError(Exception): ...
56+
57+
5558
class NotAuthenticated(Exception):
5659
def __init__(self) -> None:
5760
super().__init__(LOGIN_MESSAGE)

0 commit comments

Comments
 (0)