MCPcopy Create free account
hub / github.com/Lap-Platform/LAP / _parse_errors

Function _parse_errors

lap/core/parser.py:318–341  ·  view source on GitHub ↗

Parse @errors {400: desc, 401: desc} or @errors {400, 401}.

(line: str)

Source from the content-addressed store, hash-verified

316
317
318def _parse_errors(line: str) -> list[ErrorSchema]:
319 """Parse @errors {400: desc, 401: desc} or @errors {400, 401}."""
320 m = re.match(r'^@errors\s*\{(.*)\}\s*$', line, re.DOTALL)
321 if not m:
322 return []
323 content = m.group(1).strip()
324 parts = _split_error_entries(content)
325 errors = []
326 for part in parts:
327 part = part.strip()
328 if ':' in part:
329 # Could be "400: desc" or "400:type: desc"
330 first_colon = part.index(':')
331 code_part = part[:first_colon].strip()
332 rest = part[first_colon + 1:].strip()
333 # Check if rest starts with a type (no spaces before next colon)
334 type_m = re.match(r'^(\S+?):\s*(.*)$', rest)
335 if type_m and ' ' not in type_m.group(1):
336 errors.append(ErrorSchema(code=code_part, type=type_m.group(1), description=type_m.group(2)))
337 else:
338 errors.append(ErrorSchema(code=code_part, description=rest))
339 else:
340 errors.append(ErrorSchema(code=part))
341 return errors
342
343
344def _parse_params_block(line: str) -> list[Param]:

Callers 4

test_codes_onlyMethod · 0.90
parse_lapFunction · 0.85

Calls 2

ErrorSchemaClass · 0.90
_split_error_entriesFunction · 0.85

Tested by 3

test_codes_onlyMethod · 0.72