Skip to content

Commit

Permalink
fix: resolve crash in TransformModuleFilesToModel if regular schema…
Browse files Browse the repository at this point in the history
… file passed instead (#386)
  • Loading branch information
rhamzeh authored Nov 23, 2024
2 parents ff7db03 + 9a914c1 commit 1ed66e7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
11 changes: 9 additions & 2 deletions pkg/go/transformer/module-to-model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/js/transformer/modules/modules-to-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
model
schema 1.1

type usernomodule

0 comments on commit 1ed66e7

Please sign in to comment.