Skip to content

Commit f5e464e

Browse files
authored
tools: store C error report context lines (#27325)
1 parent 7bf483e commit f5e464e

3 files changed

Lines changed: 34 additions & 12 deletions

File tree

‎cmd/tools/modules/vbugreport/c_error_storage.v‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ pub:
88
target_os string
99
ccompiler string
1010
error_string string
11+
lines string
1112
}
1213

1314
// new_stored_c_error_report builds the fields stored by the C error report receiver.
14-
pub fn new_stored_c_error_report(c_file string, target_os string, ccompiler string, c_error string) StoredCErrorReport {
15+
pub fn new_stored_c_error_report(c_file string, target_os string, ccompiler string, c_error string, c_lines []string, v_lines []string) StoredCErrorReport {
1516
return StoredCErrorReport{
1617
c_file_name: normalized_file_name(c_file)
1718
target_os: target_os
1819
ccompiler: ccompiler
1920
error_string: c_error_string(c_error)
21+
lines: c_error_report_lines(c_lines, v_lines)
2022
}
2123
}
2224

@@ -38,6 +40,17 @@ fn c_error_string(c_output string) string {
3840
return ''
3941
}
4042

43+
fn c_error_report_lines(c_lines []string, v_lines []string) string {
44+
mut lines := []string{cap: c_lines.len + v_lines.len}
45+
for line in c_lines {
46+
lines << line
47+
}
48+
for line in v_lines {
49+
lines << line
50+
}
51+
return lines.join('\n')
52+
}
53+
4154
fn normalized_error_string(trimmed string, lower string) ?string {
4255
if lower.starts_with('fatal error:') || lower.starts_with('fatal error ') {
4356
return 'error: ${trimmed}'

‎cmd/tools/modules/vbugreport/c_error_storage_test.v‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@ module vbugreport
22

33
fn test_new_stored_c_error_report_extracts_sql_fields() {
44
report := new_stored_c_error_report('/tmp/v/program.tmp.c', 'linux', 'clang',
5-
'/tmp/v/program.tmp.c:12:7: error: unknown type name "Foo"')
5+
'/tmp/v/program.tmp.c:12:7: error: unknown type name "Foo"', [
6+
'void main__main(void) {',
7+
'\tFoo x;',
8+
], [
9+
'foo := Foo{}',
10+
])
611
assert report.c_file_name == 'program.tmp.c'
712
assert report.target_os == 'linux'
813
assert report.ccompiler == 'clang'
914
assert report.error_string == 'error: unknown type name "Foo"'
15+
assert report.lines == 'void main__main(void) {\n\tFoo x;\nfoo := Foo{}'
1016
}
1117

1218
fn test_new_stored_c_error_report_handles_windows_c_file_path() {
1319
report := new_stored_c_error_report('C:\\tmp\\program.tmp.c', 'windows', 'msvc',
14-
'error: syntax error')
20+
'error: syntax error', []string{}, []string{})
1521
assert report.c_file_name == 'program.tmp.c'
1622
}
1723

‎cmd/tools/vbug-report.v‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ fn init_db(db sqlite.DB) ! {
193193
delete_token text not null,
194194
created_at text not null,
195195
remote_ip text not null,
196-
user_agent text not null,
197-
c_file_name text not null,
198-
target_os text not null,
199-
ccompiler text not null,
200-
error_string text not null
201-
)')!
196+
user_agent text not null,
197+
c_file_name text not null,
198+
target_os text not null,
199+
ccompiler text not null,
200+
error_string text not null,
201+
lines text not null
202+
)')!
202203
db.exec('create index if not exists idx_bug_reports_created_at
203204
on bug_reports(created_at)')!
204205
}
@@ -220,13 +221,14 @@ pub fn (mut app App) create(mut ctx Context) veb.Result {
220221
return ctx.request_error('unsupported report kind')
221222
}
222223
stored_report := vbugreport.new_stored_c_error_report(report.c_file, report.target_os,
223-
report.ccompiler, report.c_error)
224+
report.ccompiler, report.c_error, report.c_context.map(it.text),
225+
report.v_context.map(it.text))
224226
id := new_report_id()
225227
delete_token := rand.uuid_v4()
226228
app.db.exec_param_many('insert into bug_reports (
227229
id, delete_token, created_at, remote_ip, user_agent,
228-
c_file_name, target_os, ccompiler, error_string
229-
) values (?, ?, ?, ?, ?, ?, ?, ?, ?)', [
230+
c_file_name, target_os, ccompiler, error_string, lines
231+
) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', [
230232
id,
231233
delete_token,
232234
time.utc().format_rfc3339(),
@@ -236,6 +238,7 @@ pub fn (mut app App) create(mut ctx Context) veb.Result {
236238
stored_report.target_os,
237239
stored_report.ccompiler,
238240
stored_report.error_string,
241+
stored_report.lines,
239242
]) or { return ctx.server_error('could not store report') }
240243
return ctx.json(CreateBugReportResponse{
241244
id: id

0 commit comments

Comments
 (0)