Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b3f2aa

Browse filesBrowse files
committed
propogate error
Signed-off-by: Omer Aplatony <omerap12@gmail.com>
1 parent aeb43eb commit 2b3f2aa
Copy full SHA for 2b3f2aa

File tree

Expand file treeCollapse file tree

1 file changed

+26
-9
lines changed
Filter options
  • staging/src/k8s.io/code-generator/cmd/conversion-gen/generators
Expand file treeCollapse file tree

1 file changed

+26
-9
lines changed

‎staging/src/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go

Copy file name to clipboardExpand all lines: staging/src/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go
+26-9Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,20 @@ func extractExternalTypesTag(comments []string) ([]string, error) {
7676
return extractTagValues(externalTypesTagName, comments)
7777
}
7878

79-
func isCopyOnly(comments []string) bool {
80-
values, _ := extractTagValues("k8s:conversion-fn", comments)
81-
return len(values) == 1 && values[0] == "copy-only"
79+
func isCopyOnly(comments []string) (bool, error) {
80+
values, err := extractTagValues("k8s:conversion-fn", comments)
81+
if err != nil {
82+
return false, err
83+
}
84+
return len(values) == 1 && values[0] == "copy-only", nil
8285
}
8386

84-
func isDrop(comments []string) bool {
85-
values, _ := extractTagValues("k8s:conversion-fn", comments)
86-
return len(values) == 1 && values[0] == "drop"
87+
func isDrop(comments []string) (bool, error) {
88+
values, err := extractTagValues("k8s:conversion-fn", comments)
89+
if err != nil {
90+
return false, err
91+
}
92+
return len(values) == 1 && values[0] == "drop", nil
8793
}
8894

8995
// TODO: This is created only to reduce number of changes in a single PR.
@@ -360,7 +366,10 @@ func GetTargets(context *generator.Context, args *args.Args) []generator.Target
360366
// If there is a manual conversion defined between two types, exclude it
361367
// from being a candidate for unsafe conversion
362368
for k, v := range manualConversions {
363-
if isCopyOnly(v.CommentLines) {
369+
copyOnly, err := isCopyOnly(v.CommentLines)
370+
if err != nil {
371+
klog.Errorf("error extracting tags: %v", err)
372+
} else if copyOnly {
364373
klog.V(4).Infof("Conversion function %s will not block memory copy because it is copy-only", v.Name)
365374
continue
366375
}
@@ -954,15 +963,23 @@ func (g *genConversion) doStruct(inType, outType *types.Type, sw *generator.Snip
954963

955964
// check based on the top level name, not the underlying names
956965
if function, ok := g.preexists(inMember.Type, outMember.Type); ok {
957-
if isDrop(function.CommentLines) {
966+
dropFn, err := isDrop(function.CommentLines)
967+
if err != nil {
968+
klog.Errorf("Error extracting drop tag for function %s: %v", function.Name, err)
969+
} else if dropFn {
958970
continue
959971
}
960972
// copy-only functions that are directly assignable can be inlined instead of invoked.
961973
// As an example, conversion functions exist that allow types with private fields to be
962974
// correctly copied between types. These functions are equivalent to a memory assignment,
963975
// and are necessary for the reflection path, but should not block memory conversion.
964976
// Convert_unversioned_Time_to_unversioned_Time is an example of this logic.
965-
if !isCopyOnly(function.CommentLines) || !g.isFastConversion(inMemberType, outMemberType) {
977+
copyOnly, copyErr := isCopyOnly(function.CommentLines)
978+
if copyErr != nil {
979+
klog.Errorf("Error extracting copy-only tag for function %s: %v", function.Name, copyErr)
980+
copyOnly = false
981+
}
982+
if !copyOnly || !g.isFastConversion(inMemberType, outMemberType) {
966983
args["function"] = function
967984
sw.Do("if err := $.function|raw$(&in.$.name$, &out.$.name$, s); err != nil {\n", args)
968985
sw.Do("return err\n", nil)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.