-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtool_errors.hpp
More file actions
152 lines (126 loc) · 5.53 KB
/
Copy pathtool_errors.hpp
File metadata and controls
152 lines (126 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once
#include <string>
namespace acecode {
// Standardized error messages for tools
class ToolErrors {
public:
static std::string parse_failed() {
return "[Error] Failed to parse tool arguments.";
}
static std::string missing_parameter(const std::string& param_name) {
return "[Error] Required parameter missing: " + param_name;
}
static std::string invalid_parameter(
const std::string& param_name,
const std::string& expectation
) {
return "[Error] Invalid parameter " + param_name + ": " + expectation;
}
static std::string incompatible_parameters(
const std::string& first,
const std::string& second
) {
return "[Error] " + first + " cannot be combined with " + second + ".";
}
static std::string file_not_found(const std::string& path, const std::string& cwd = "") {
std::string msg = "[Error] File not found: " + path;
if (!cwd.empty()) {
msg += "\nCurrent directory: " + cwd;
}
return msg;
}
static std::string cannot_open_file(const std::string& path) {
return "[Error] Cannot open file: " + path;
}
static std::string cannot_write_file(const std::string& path) {
return "[Error] Cannot write to file: " + path;
}
static std::string path_not_regular_file(const std::string& path) {
return "[Error] Path is not a regular file: " + path;
}
static std::string byte_offset_outside_file(
size_t offset,
size_t file_size
) {
return "[Error] byte_offset " + std::to_string(offset) +
" is outside the file (size " + std::to_string(file_size) +
" bytes).";
}
static std::string too_many_lines_for_line_read() {
return "[Error] File has too many lines to address with 32-bit line "
"numbers. Use byte_offset/max_bytes.";
}
static std::string large_text_requires_streaming_encoding(
const std::string& encoding,
size_t size_mb,
size_t limit_mb
) {
return "[Error] Large " + encoding +
" text file requires whole-file decoding (" +
std::to_string(size_mb) + "MiB; read materialization limit " +
std::to_string(limit_mb) +
"MiB). Convert it to UTF-8 for streaming inspection, or use "
"byte_offset/max_bytes windows.";
}
static std::string file_too_large_for_edit(
size_t size_mb,
size_t limit_mb,
const std::string& suggestion = ""
) {
std::string msg =
"[Error] File is too large to edit safely as one in-memory operation (" +
std::to_string(size_mb) + "MiB; edit limit " +
std::to_string(limit_mb) + "MiB).";
if (!suggestion.empty()) {
msg += " " + suggestion;
}
return msg;
}
static std::string external_modification(const std::string& path) {
return "[Error] File was modified externally since it was last read. "
"Re-read the file before writing to avoid data loss: " + path;
}
static std::string file_not_read_for_edit(const std::string& path) {
return "[Error] File has not been read yet. Read the target file with file_read "
"before editing it: " + path;
}
static std::string file_read_not_safe_for_edit(const std::string& path) {
return "[Error] File read is not safe enough to edit. Re-read the target file "
"with non-lossy text decoding before editing it: " + path;
}
static std::string no_changes_to_make() {
return "[Error] No changes to make: old_string and new_string are exactly the same.";
}
static std::string cannot_create_file_exists(const std::string& path) {
return "[Error] Cannot create new file - file already exists: " + path;
}
static std::string notebook_edit_required(const std::string& path) {
return "[Error] File is a Jupyter Notebook. Use a notebook-specific editor instead of file_edit: " + path;
}
static std::string string_not_found(const std::string& file_path) {
return "[Error] old_string not found in " + file_path +
". Re-read the current file content with file_read and retry with "
"an exact old_string including enough surrounding whitespace and "
"indentation to identify the target.";
}
static std::string legacy_range_edit_arguments(const std::string& file_path) {
return "[Error] file_edit no longer supports start_line, end_line, "
"expected_hash, or read_id arguments. Read the current file content "
"with file_read and retry with an exact old_string replacement: " +
file_path;
}
static std::string string_not_unique(size_t count, const std::string& file_path) {
return "[Error] old_string found " + std::to_string(count) +
" times in " + file_path + ". Include more surrounding lines "
"to uniquely identify the target location, or set replace_all to true "
"to replace every occurrence.";
}
static std::string empty_parameter(const std::string& param_name) {
return "[Error] " + param_name + " cannot be empty.";
}
static std::string no_lines_in_range(int start, int end, int total_lines) {
return "[Error] No lines in range " + std::to_string(start) +
"-" + std::to_string(end) + " (file has " + std::to_string(total_lines) + " lines).";
}
};
} // namespace acecode