From 1d6d62298c316c939bb0260ea0302bfade4082ea Mon Sep 17 00:00:00 2001 From: Pandurang Patil <5101898+pandurangpatil@users.noreply.github.com> Date: Fri, 19 Apr 2024 20:02:44 +0530 Subject: [PATCH] Graceful handling for go.mod file (#35) Graceful handling for go.mod file if the module name is not present. --- goastgen/modfileparser.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/goastgen/modfileparser.go b/goastgen/modfileparser.go index 5f8d2c7..3bc98cc 100644 --- a/goastgen/modfileparser.go +++ b/goastgen/modfileparser.go @@ -38,12 +38,21 @@ func (mod *ModFile) Parse() (string, error) { } objMap["node_filename"] = mod.File module := make(map[string]interface{}) - module["Name"] = modFile.Module.Mod.Path - module["node_line_no"] = modFile.Module.Syntax.Start.Line - module["node_col_no"] = modFile.Module.Syntax.Start.LineRune - module["node_line_no_end"] = modFile.Module.Syntax.End.Line - module["node_col_no_end"] = modFile.Module.Syntax.End.LineRune - module["node_type"] = "mod.Module" + if modFile.Module != nil { + module["Name"] = modFile.Module.Mod.Path + module["node_line_no"] = modFile.Module.Syntax.Start.Line + module["node_col_no"] = modFile.Module.Syntax.Start.LineRune + module["node_line_no_end"] = modFile.Module.Syntax.End.Line + module["node_col_no_end"] = modFile.Module.Syntax.End.LineRune + module["node_type"] = "mod.Module" + } else { + module["Name"] = mod.File + module["node_line_no"] = 0 + module["node_col_no"] = 0 + module["node_line_no_end"] = 0 + module["node_col_no_end"] = 0 + module["node_type"] = "mod.Module" + } objMap["Module"] = module dependencies := []interface{}{} for _, req := range modFile.Require {