Skip to content

Commit 10e2b8b

Browse files
committed
deepcopy: Put some colons in error messages to make them more readable
The error message invalid field type: invalid type isn't great, but it's a heck of a lot better than invalid field type invalid type
1 parent 04609bd commit 10e2b8b

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pkg/deepcopy/traverse.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (n *namingInfo) Syntax(basePkg *loader.Package, imports *importsList) strin
197197
(&namingInfo{typeInfo: typeInfo.Key()}).Syntax(basePkg, imports),
198198
(&namingInfo{typeInfo: typeInfo.Elem()}).Syntax(basePkg, imports))
199199
default:
200-
basePkg.AddError(fmt.Errorf("name requested for invalid type %s", typeInfo))
200+
basePkg.AddError(fmt.Errorf("name requested for invalid type: %s", typeInfo))
201201
return typeInfo.String()
202202
}
203203
}
@@ -215,7 +215,7 @@ type copyMethodMaker struct {
215215
func (c *copyMethodMaker) GenerateMethodsFor(root *loader.Package, info *markers.TypeInfo) {
216216
typeInfo := root.TypesInfo.TypeOf(info.RawSpec.Name)
217217
if typeInfo == types.Typ[types.Invalid] {
218-
root.AddError(loader.ErrFromNode(fmt.Errorf("unknown type %s", info.Name), info.RawSpec))
218+
root.AddError(loader.ErrFromNode(fmt.Errorf("unknown type: %s", info.Name), info.RawSpec))
219219
}
220220

221221
// figure out if we need to use a pointer receiver -- most types get a pointer receiver,
@@ -312,7 +312,7 @@ func (c *copyMethodMaker) genDeepCopyIntoBlock(actualName *namingInfo, typeInfo
312312
// handled via the above loop, should never happen
313313
c.pkg.AddError(fmt.Errorf("interface type %s encountered directly, invalid condition", last))
314314
default:
315-
c.pkg.AddError(fmt.Errorf("invalid type %s", last))
315+
c.pkg.AddError(fmt.Errorf("invalid type: %s", last))
316316
}
317317
}
318318

@@ -322,7 +322,7 @@ func (c *copyMethodMaker) genMapDeepCopy(actualName *namingInfo, mapType *types.
322322
// maps *must* have shallow-copiable types, since we just iterate
323323
// through the keys, only trying to deepcopy the values.
324324
if !fineToShallowCopy(mapType.Key()) {
325-
c.pkg.AddError(fmt.Errorf("invalid map key type %s", mapType.Key()))
325+
c.pkg.AddError(fmt.Errorf("invalid map key type: %s", mapType.Key()))
326326
return
327327
}
328328

@@ -383,7 +383,7 @@ func (c *copyMethodMaker) genMapDeepCopy(actualName *namingInfo, mapType *types.
383383
// structs will have deepcopy generated for them, so use that
384384
c.Line("(*out)[key] = *val.DeepCopy()")
385385
default:
386-
c.pkg.AddError(fmt.Errorf("invalid map value type %s", underlyingElem))
386+
c.pkg.AddError(fmt.Errorf("invalid map value type: %s", underlyingElem))
387387
return
388388
}
389389
}
@@ -425,7 +425,7 @@ func (c *copyMethodMaker) genSliceDeepCopy(actualName *namingInfo, sliceType *ty
425425
// structs will always have deepcopy
426426
c.Linef("(*in)[i].DeepCopyInto(&(*out)[i])")
427427
default:
428-
c.pkg.AddError(fmt.Errorf("invalid slice element type %s", underlyingElem))
428+
c.pkg.AddError(fmt.Errorf("invalid slice element type: %s", underlyingElem))
429429
}
430430
})
431431
}
@@ -491,7 +491,7 @@ func (c *copyMethodMaker) genStructDeepCopy(_ *namingInfo, structType *types.Str
491491
c.Linef("in.%[1]s.DeepCopyInto(&out.%[1]s)", field.Name())
492492
}
493493
default:
494-
c.pkg.AddError(fmt.Errorf("invalid field type %s", underlyingField))
494+
c.pkg.AddError(fmt.Errorf("invalid field type: %s", underlyingField))
495495
return
496496
}
497497
}
@@ -542,7 +542,7 @@ func (c *copyMethodMaker) genPointerDeepCopy(_ *namingInfo, pointerType *types.P
542542
c.Linef("*out = new(%[1]s)", (&namingInfo{typeInfo: pointerType.Elem()}).Syntax(c.pkg, c.importsList))
543543
c.Line("(*in).DeepCopyInto(*out)")
544544
default:
545-
c.pkg.AddError(fmt.Errorf("invalid pointer element type %s", underlyingElem))
545+
c.pkg.AddError(fmt.Errorf("invalid pointer element type: %s", underlyingElem))
546546
return
547547
}
548548
}
@@ -602,7 +602,7 @@ func shouldBeCopied(pkg *loader.Package, info *markers.TypeInfo) bool {
602602

603603
typeInfo := pkg.TypesInfo.TypeOf(info.RawSpec.Name)
604604
if typeInfo == types.Typ[types.Invalid] {
605-
pkg.AddError(loader.ErrFromNode(fmt.Errorf("unknown type %s", info.Name), info.RawSpec))
605+
pkg.AddError(loader.ErrFromNode(fmt.Errorf("unknown type: %s", info.Name), info.RawSpec))
606606
return false
607607
}
608608

0 commit comments

Comments
 (0)