all: add limit to accumulated errors / warnings (#11183)

pull/11184/head
Leo Developer 2021-08-14 18:49:21 +02:00 committed by GitHub
parent deb26b92b9
commit 8a8a0932f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 26 deletions

View File

@ -131,6 +131,7 @@ const (
'-w', '-w',
'-print-v-files', '-print-v-files',
'-error-limit', '-error-limit',
'-warn-error-limit',
'-os', '-os',
'-printfn', '-printfn',
'-cflags', '-cflags',

View File

@ -82,6 +82,10 @@ NB: the build flags are shared with the run command too:
d) the function name d) the function name
NB: if you want to output the profile info to stdout, use `-profile -`. NB: if you want to output the profile info to stdout, use `-profile -`.
-warn-error-limit <limit>
Limit of warnings / errors that will be accumulated (defaults to 100).
Settings this to a negative value will disable the limit.
-profile-no-inline -profile-no-inline
Skip [inline] functions when profiling. Skip [inline] functions when profiling.

View File

@ -7622,6 +7622,9 @@ fn (mut c Checker) warn_or_error(message string, pos token.Position, warn bool)
} }
if warn && !c.pref.skip_warnings { if warn && !c.pref.skip_warnings {
c.nr_warnings++ c.nr_warnings++
if c.nr_warnings >= c.pref.warn_error_limit && c.pref.warn_error_limit >= 0 {
return
}
wrn := errors.Warning{ wrn := errors.Warning{
reporter: errors.Reporter.checker reporter: errors.Reporter.checker
pos: pos pos: pos
@ -7638,17 +7641,19 @@ fn (mut c Checker) warn_or_error(message string, pos token.Position, warn bool)
exit(1) exit(1)
} }
c.nr_errors++ c.nr_errors++
if pos.line_nr !in c.error_lines { if c.nr_errors < c.pref.warn_error_limit || c.pref.warn_error_limit < 0 {
err := errors.Error{ if pos.line_nr !in c.error_lines {
reporter: errors.Reporter.checker err := errors.Error{
pos: pos reporter: errors.Reporter.checker
file_path: c.file.path pos: pos
message: message file_path: c.file.path
details: details message: message
details: details
}
c.file.errors << err
c.errors << err
c.error_lines << pos.line_nr
} }
c.file.errors << err
c.errors << err
c.error_lines << pos.line_nr
} }
} }
} }

View File

@ -1649,7 +1649,9 @@ pub fn (mut p Parser) error_with_error(error errors.Error) {
eprintln(ferror) eprintln(ferror)
exit(1) exit(1)
} else { } else {
p.errors << error if p.errors.len < p.pref.warn_error_limit || p.pref.warn_error_limit < 0 {
p.errors << error
}
} }
if p.pref.output_mode == .silent { if p.pref.output_mode == .silent {
// Normally, parser errors mean that the parser exits immediately, so there can be only 1 parser error. // Normally, parser errors mean that the parser exits immediately, so there can be only 1 parser error.
@ -1672,11 +1674,13 @@ pub fn (mut p Parser) warn_with_pos(s string, pos token.Position) {
ferror := util.formatted_error('warning:', s, p.file_name, pos) ferror := util.formatted_error('warning:', s, p.file_name, pos)
eprintln(ferror) eprintln(ferror)
} else { } else {
p.warnings << errors.Warning{ if p.warnings.len < p.pref.warn_error_limit || p.pref.warn_error_limit < 0 {
file_path: p.file_name p.warnings << errors.Warning{
pos: pos file_path: p.file_name
reporter: .parser pos: pos
message: s reporter: .parser
message: s
}
} }
} }
} }

View File

@ -189,6 +189,7 @@ pub mut:
gc_mode GarbageCollectionMode = .no_gc // .no_gc, .boehm, .boehm_leak, ... gc_mode GarbageCollectionMode = .no_gc // .no_gc, .boehm, .boehm_leak, ...
is_cstrict bool // turn on more C warnings; slightly slower is_cstrict bool // turn on more C warnings; slightly slower
assert_failure_mode AssertFailureMode // whether to call abort() or print_backtrace() after an assertion failure assert_failure_mode AssertFailureMode // whether to call abort() or print_backtrace() after an assertion failure
warn_error_limit int = 100 // limit of warnings/errors to be accumulated
// checker settings: // checker settings:
checker_match_exhaustive_cutoff_limit int = 12 checker_match_exhaustive_cutoff_limit int = 12
} }
@ -519,6 +520,10 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
} }
i++ i++
} }
'-warn-error-limit' {
res.warn_error_limit = cmdline.option(current_args, arg, '10').int()
i++
}
'-cc' { '-cc' {
res.ccompiler = cmdline.option(current_args, '-cc', 'cc') res.ccompiler = cmdline.option(current_args, '-cc', 'cc')
res.build_options << '$arg "$res.ccompiler"' res.build_options << '$arg "$res.ccompiler"'

View File

@ -1354,11 +1354,13 @@ pub fn (mut s Scanner) warn(msg string) {
if s.pref.output_mode == .stdout { if s.pref.output_mode == .stdout {
eprintln(util.formatted_error('warning:', msg, s.file_path, pos)) eprintln(util.formatted_error('warning:', msg, s.file_path, pos))
} else { } else {
s.warnings << errors.Warning{ if s.warnings.len < s.pref.warn_error_limit || s.pref.warn_error_limit < 0 {
file_path: s.file_path s.warnings << errors.Warning{
pos: pos file_path: s.file_path
reporter: .scanner pos: pos
message: msg reporter: .scanner
message: msg
}
} }
} }
} }
@ -1376,11 +1378,13 @@ pub fn (mut s Scanner) error(msg string) {
if s.pref.fatal_errors { if s.pref.fatal_errors {
exit(1) exit(1)
} }
s.errors << errors.Error{ if s.errors.len < s.pref.warn_error_limit || s.pref.warn_error_limit < 0 {
file_path: s.file_path s.errors << errors.Error{
pos: pos file_path: s.file_path
reporter: .scanner pos: pos
message: msg reporter: .scanner
message: msg
}
} }
} }
} }