Skip to content

Fix AttributeError in parse_gomod on comments or blank lines (fixes #5489) - #5490

Open
muskan-creates352 wants to merge 1 commit into
aboutcode-org:developfrom
muskan-creates352:fix-gomod-comments-crash-5489
Open

muskan-creates352 wants to merge 1 commit into
aboutcode-org:developfrom
muskan-creates352:fix-gomod-comments-crash-5489

Conversation

@muskan-creates352

Copy link
Copy Markdown

Fixes #5489

Problem

In src/packagedcode/go_mod.py, when a go.mod file contains comments (e.g. // indirect) or blank lines inside a multiline require (...) or exclude (...) block, preprocess(line) returns an empty string "" and parse_dep_link(line) returns None.

Because ns_name = parsed_dep_link.group('ns_name') was called before checking if parsed_dep_link is None, an AttributeError: 'NoneType' object has no attribute 'group' was raised. This caused ScanCode to silently fail on go.mod files with comments, resulting in 0 detected packages.

Solution

  1. In src/packagedcode/go_mod.py:
    • Added a guard to skip empty lines (if not req: continue and if not exc: continue).
    • Moved .group('ns_name') and dependency creation inside the if parsed_dep_link: conditional block for both require and exclude.
  2. Added unit test test_parse_gomod_with_comments_and_blank_lines in tests/packagedcode/test_golang.py.

Checklist

  • Signed-off-by included in commit message
  • Unit test added and all 15 golang tests pass
  • Tested on Python 3.11

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] parse_gomod crashes with AttributeError on comments or blank lines inside require/exclude blocks

1 participant