• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Problematy / goodmap / 20583796061

29 Dec 2025 10:11PM UTC coverage: 96.449% (-2.3%) from 98.783%
20583796061

Pull #278

github

web-flow
Merge dacfe649f into 783f855e7
Pull Request #278: chore: better errors handling

559 of 590 branches covered (94.75%)

Branch coverage included in aggregate %.

139 of 167 new or added lines in 4 files covered. (83.23%)

1 existing line in 1 file now uncovered.

1261 of 1297 relevant lines covered (97.22%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/goodmap/data_models/location.py
1
from typing import Any, Type
1✔
2

3
from pydantic import (
1✔
4
    BaseModel,
5
    Field,
6
    ValidationError,
7
    create_model,
8
    field_validator,
9
    model_validator,
10
)
11

12
from goodmap.exceptions import LocationValidationError
1✔
13

14

15
class LocationBase(BaseModel, extra="allow"):
1✔
16
    position: tuple[float, float]
1✔
17
    uuid: str
1✔
18

19
    @field_validator("position")
1✔
20
    @classmethod
1✔
21
    def position_must_be_valid(cls, v):
1✔
22
        if v[0] < -90 or v[0] > 90:
1✔
23
            raise ValueError("latitude must be in range -90 to 90")
1✔
24
        if v[1] < -180 or v[1] > 180:
1✔
25
            raise ValueError("longitude must be in range -180 to 180")
1✔
26
        return v
1✔
27

28
    @model_validator(mode="before")
1✔
29
    @classmethod
1✔
30
    def validate_uuid_exists(cls, data: Any) -> Any:
1✔
31
        """Ensure UUID is present before validation for better error messages."""
32
        if isinstance(data, dict) and "uuid" not in data:
1✔
NEW
33
            raise ValueError("Location data must include 'uuid' field")
×
34
        return data
1✔
35

36
    @model_validator(mode="wrap")
1✔
37
    @classmethod
1✔
38
    def enrich_validation_errors(cls, data, handler):
1✔
39
        """Wrap validation errors with UUID context for better debugging."""
40
        try:
1✔
41
            return handler(data)
1✔
42
        except ValidationError as e:
1✔
43
            uuid = data.get("uuid") if isinstance(data, dict) else None
1✔
44
            raise LocationValidationError(e, uuid=uuid) from e
1✔
45

46
    def basic_info(self):
1✔
47
        return {
1✔
48
            "uuid": self.uuid,
49
            "position": self.position,
50
            "remark": bool(getattr(self, "remark", False)),
51
        }
52

53

54
def create_location_model(obligatory_fields: list[tuple[str, Type[Any]]]) -> Type[BaseModel]:
1✔
55
    fields = {
1✔
56
        field_name: (field_type, Field(...)) for (field_name, field_type) in obligatory_fields
57
    }
58

59
    return create_model(
1✔
60
        "Location",
61
        __config__=None,
62
        __doc__=None,
63
        __module__="Location",
64
        __validators__=None,
65
        __base__=LocationBase,
66
        __cls_kwargs__=None,
67
        **fields,
68
    )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc