Coverage for lode / exceptions.py: 90%

21 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2026-11-22 15:54 +0000

1"""Domain exceptions of LODE. 

2 

3Every error the user can cause (bad URL, unreachable or malformed artefact, 

4rejected upload) is a LODEError subclass, so the web layer can tell it apart 

5from an unexpected failure and show a clear message instead of a traceback. 

6""" 

7from datetime import datetime, timezone 

8from typing import Optional 

9import uuid 

10 

11class LODEError(Exception): 

12 """Base exception. All LODE errors inherit this exception. 

13 

14 Carries a `context` dict (which file, which URL, which limit), a UTC 

15 `timestamp` and a unique `request_id` so a message shown to the user can be 

16 matched with the server log. 

17 """ 

18 

19 def __init__(self, message: str, context: Optional[dict] = None): 

20 """Store the message together with its context, timestamp and request id.""" 

21 super().__init__(message) 

22 self.context = context or {} 

23 self.timestamp = datetime.now(timezone.utc).isoformat() 

24 self.request_id = str(uuid.uuid4()) 

25 

26class ArtefactLoadError(LODEError): 

27 """The artefact was reached but cannot be parsed in any RDF format.""" 

28 pass 

29 

30class ArtefactNotFoundError(LODEError): 

31 """The artefact answers 404 or the request fails with a network error.""" 

32 pass 

33 

34class ArtefactUnavailableError(LODEError): 

35 """The remote host was reached but answers with a server error (5xx). 

36 

37 The artefact may well exist: it is the service that is temporarily unavailable. 

38 """ 

39 pass 

40 

41class BuildCapacityError(LODEError): 

42 """The service cannot start a static-site build right now (no free slot or no disk quota). 

43 

44 `retry_after` is the number of seconds the client should wait before retrying. 

45 """ 

46 

47 def __init__(self, message: str, retry_after: int, context: Optional[dict] = None): 

48 """Store the message, the suggested wait and the optional context.""" 

49 super().__init__(message, context) 

50 self.retry_after = retry_after 

51 

52class ArtefactValidationError(LODEError): 

53 """The artefact was rejected by a security check (size, extension, URL scheme/SSRF, non-text).""" 

54 pass