Skip to content

Commit 6f445f9

Browse files
committed
More improvements to error messages to better guide the LLM
1 parent 2688f1a commit 6f445f9

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/cedarscript_editor/cedarscript_editor.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ def _apply_action(
220220

221221
case MoveClause(insert_position=insert_position, to_other_file=other_file, relative_indentation=relindent):
222222
# TODO Move from 'lines' to the same file or to 'other_file'
223-
if range_spec <= range_spec_to_delete:
223+
224+
if range_spec < range_spec_to_delete:
224225
range_spec_to_delete.delete(lines)
225226
range_spec.write(content, lines)
226-
else:
227+
elif range_spec > range_spec_to_delete:
227228
range_spec.write(content, lines)
228229
range_spec_to_delete.delete(lines)
229230

src/text_manipulation/range_spec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def from_line_marker(
156156
if search_term.offset is None and match_type_count > 1:
157157
raise ValueError(
158158
f"There are {match_type_count} lines matching `{search_term.value}`. "
159-
f"Suggestion: Try using a different line as marker (a couple lines before or after the current one)."
159+
f"Suggestions: 1) Try using a *different line* as marker (a couple lines before or after the one you tried); "
160+
f"2) If you wanted to *REPLACE* line, try instead to replace a *SEGMENT* of a couple of lines."
160161
# f"Add an `OFFSET` (after the line marker) and a number between 0 and {match_type_count - 1} to determine how many to skip. "
161162
# f"Example to reference the *last* one of those: `LINE '{search_term.value.strip()}' OFFSET {match_type_count - 1}`"
162163
# ' (See `offset_clause` in `<grammar.js>` for details on OFFSET)'

src/text_manipulation/text_editor_kit.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def marker_or_segment_to_search_range_impl(
5858
case Marker(type=MarkerType.LINE):
5959
result = RangeSpec.from_line_marker(lines, self, search_range)
6060
assert result is not None, (
61-
f"Unable to find `{self}`; Try: 1) Double-checking the marker "
61+
f"Unable to find {self}; Try: 1) Double-checking the marker "
6262
f"(maybe you specified the the wrong one); or 2) using *exactly* the same characters from source; "
6363
f"or 3) using another marker"
6464
)
@@ -83,9 +83,9 @@ def segment_to_search_range(
8383

8484
start_match_result = RangeSpec.from_line_marker(lines, start_relpos, search_range)
8585
assert start_match_result, (
86-
f"Unable to find segment start `{start_relpos}`; Try: "
86+
f"Unable to find segment start: {start_relpos}; Try: "
8787
f"1) Double-checking the marker (maybe you specified the the wrong one); or "
88-
f"2) using *exactly* the same characters from source; or 3) using a marker from above"
88+
f"2) Using *exactly* the same characters from source; or 3) using a marker from above"
8989
)
9090

9191
start_index_for_end_marker = start_match_result.as_index
@@ -96,8 +96,9 @@ def segment_to_search_range(
9696
start_index_for_end_marker, search_range.end, start_match_result.indent
9797
))
9898
assert end_match_result, (
99-
f"Unable to find segment end `{end_relpos}` - Try: "
100-
f"1) using *exactly* the same characters from source; or 2) using a marker from below"
99+
f"Unable to find segment end: {end_relpos}; Try: "
100+
f"1) Using *exactly* the same characters from source; or "
101+
f"2) using a marker from below"
101102
)
102103
if end_match_result.as_index > -1:
103104
one_after_end = end_match_result.as_index + 1

0 commit comments

Comments
 (0)