From 963343160fd1a52849ff3bae00475728e8586ee2 Mon Sep 17 00:00:00 2001 From: jenkins-x-bot Date: Wed, 20 Nov 2024 14:33:18 +0100 Subject: [PATCH] Fix crash if a non-module is passed to TransformModuleFilesToModel --- pkg/go/transformer/module-to-model.go | 11 +++++++++-- .../01-module-with-errors/expected_errors.json | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/go/transformer/module-to-model.go b/pkg/go/transformer/module-to-model.go index c1d3c742..edf1582c 100644 --- a/pkg/go/transformer/module-to-model.go +++ b/pkg/go/transformer/module-to-model.go @@ -116,8 +116,15 @@ func TransformModuleFilesToModel( //nolint:funlen,gocognit,cyclop } types = append(types, typeDef.GetType()) - typeDef.Metadata.SourceInfo = &openfgav1.SourceInfo{ - File: module.Name, + if typeDef.Metadata != nil { + typeDef.Metadata.SourceInfo = &openfgav1.SourceInfo{ + File: module.Name, + } + } else { + transformErrors = multierror.Append(transformErrors, &ModuleTransformationSingleError{ + Msg: "file is not a module", + }) + continue } rawTypeDefs = append(rawTypeDefs, typeDef) } diff --git a/tests/data/transformer-module/01-module-with-errors/expected_errors.json b/tests/data/transformer-module/01-module-with-errors/expected_errors.json index 2059ccf8..89e43406 100644 --- a/tests/data/transformer-module/01-module-with-errors/expected_errors.json +++ b/tests/data/transformer-module/01-module-with-errors/expected_errors.json @@ -1,4 +1,8 @@ [ + { + "msg": "file is not a module", + "file":"nomodule.fga" + }, { "msg": "duplicate condition a_check", "file": "org.fga",