From cb6196db588ad45d34df6b72863ca2228869ca50 Mon Sep 17 00:00:00 2001 From: xescugc Date: Mon, 8 Jun 2020 21:31:25 +0200 Subject: [PATCH] stringer: Add logic to fail if transformer empties value If the output of the transformer is '' means that something went wrong (if it had a value before) and so it needs to fail to not conntinue with silence errors --- stringer.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/stringer.go b/stringer.go index 21181cd..594e2f3 100644 --- a/stringer.go +++ b/stringer.go @@ -377,8 +377,17 @@ func (g *Generator) transformValueNames(values []Value, transformMethod string) return } - for i := range values { - values[i].name = fn(values[i].name) + for i, v := range values { + after := fn(v.name) + // If the original one was "" or the one before the transformation + // was "" (most commonly if linecomment defines it as empty) we + // do not care if it's empty. + // But if any of them was not empty before then it means that + // the transformed emptied the value + if v.originalName != "" && v.name != "" && after == "" { + log.Fatalf("transformation of %q (%s) got an empty result", v.name, v.originalName) + } + values[i].name = after } }