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/pkg/js/transformer/modules/modules-to-model.ts b/pkg/js/transformer/modules/modules-to-model.ts index 8923aa3f..436d4494 100644 --- a/pkg/js/transformer/modules/modules-to-model.ts +++ b/pkg/js/transformer/modules/modules-to-model.ts @@ -49,7 +49,17 @@ export const transformModuleFilesToModel = ( extendedTypeDefs[name].push(typeDef); continue; } - + if (!typeDef.metadata) { + errors.push( + new ModuleTransformationSingleError({ + msg: "file is not a module", + line: { start: 0, end: 0 }, + column: { start: 0, end: 0 }, + file: "nomodule.fga", + }), + ); + continue; + } typeDef.metadata!.source_info = { file: name, }; 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..33cb4a5a 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,16 @@ [ + { + "msg": "file is not a module", + "file":"nomodule.fga", + "line": { + "start": 0, + "end": 0 + }, + "column": { + "start": 0, + "end": 0 + } + }, { "msg": "duplicate condition a_check", "file": "org.fga", diff --git a/tests/data/transformer-module/01-module-with-errors/module/nomodule.fga b/tests/data/transformer-module/01-module-with-errors/module/nomodule.fga new file mode 100644 index 00000000..6a5936f1 --- /dev/null +++ b/tests/data/transformer-module/01-module-with-errors/module/nomodule.fga @@ -0,0 +1,4 @@ +model + schema 1.1 + +type usernomodule