MCPcopy
hub / github.com/marimo-team/marimo / strip_explain_from_error_message

Function strip_explain_from_error_message

marimo/_sql/utils.py:425–462  ·  view source on GitHub ↗

Strip EXPLAIN from an error message. Also adjusts the caret position Example: ``` LINE 1: EXPLAIN SELECT * FROM t ^ ``` becomes ``` LINE 1: SELECT * FROM t ^ ```

(error_message: str)

Source from the content-addressed store, hash-verified

423
424
425def strip_explain_from_error_message(error_message: str) -> str:
426 """Strip EXPLAIN from an error message. Also adjusts the caret position
427
428 Example:
429 ```
430 LINE 1: EXPLAIN SELECT * FROM t
431 ^
432 ```
433 becomes
434 ```
435 LINE 1: SELECT * FROM t
436 ^
437 ```
438 """
439 # Find the first occurrence of "EXPLAIN " and replace it
440 explain_pos = error_message.find("EXPLAIN ")
441 if explain_pos == -1:
442 return error_message
443
444 explain_length = len("EXPLAIN ")
445
446 # Replace the first "EXPLAIN " with empty string
447 result = (
448 error_message[:explain_pos]
449 + error_message[explain_pos + explain_length :]
450 )
451
452 # Find the next newline and strip the same amount from the next line
453 next_newline = result.find("\n", explain_pos)
454 if next_newline != -1 and next_newline + explain_length < len(result):
455 # Remove the same length from the beginning of the next line
456 # This is the caret position
457 result = (
458 result[: next_newline + 1]
459 + result[next_newline + 1 + explain_length :]
460 )
461
462 return result

Calls 1

findMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…