Add --panicOnWarning flag

Fixes #9357
Fixes #9359
This commit is contained in:
Bjørn Erik Pedersen 2022-01-06 10:22:19 +01:00
parent 85c5b89593
commit c8b5ab75b7
4 changed files with 22 additions and 6 deletions

View file

@ -331,12 +331,14 @@ func (l *DistinctLogger) Warnf(format string, v ...interface{}) {
l.Logger.Warnf(format, v...)
})
}
func (l *DistinctLogger) Warnln(v ...interface{}) {
logStatement := fmt.Sprint(v...)
l.printIfNotPrinted("warnln", logStatement, func() {
l.Logger.Warnln(v...)
})
}
func (l *DistinctLogger) Errorf(format string, v ...interface{}) {
logStatement := fmt.Sprint(v...)
l.printIfNotPrinted("errorf", logStatement, func() {
@ -396,7 +398,6 @@ var (
func InitLoggers() {
DistinctErrorLog.Reset()
DistinctWarnLog.Reset()
}
// Deprecated informs about a deprecation, but only once for a given set of arguments' values.
@ -408,7 +409,11 @@ func Deprecated(item, alternative string, err bool) {
if err {
DistinctErrorLog.Errorf("%s is deprecated and will be removed in Hugo %s. %s", item, hugo.CurrentVersion.Next().ReleaseVersion(), alternative)
} else {
DistinctWarnLog.Warnf("%s is deprecated and will be removed in a future release. %s", item, alternative)
var warnPanicMessage string
if !loggers.PanicOnWarning {
warnPanicMessage = "\n\nRe-run Hugo with the flag --panicOnWarning to get a better error message."
}
DistinctWarnLog.Warnf("%s is deprecated and will be removed in a future release. %s%s", item, alternative, warnPanicMessage)
}
}