[BUG] parse_gomod crashes with AttributeError on comments or blank lines inside require/exclude blocks
Maintainers usually reply within 2 days
@muskan-creates352 is already working on this.
Since Nov 15, 2026.
- #5490 by @muskan-creates352 — open
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 35/100
Research direction
Start with src/packagedcode/go_mod.py, where the issue identifies the failing require and exclude parsing paths, and inspect related Go module parser tests. Reproduce with comments or blank lines in both block types, then confirm parsing completes and dependencies are extracted without an AttributeError. Pull request #5490 is already open against this issue.
Written by the indexing model from the issue text.
Description
Problem Description
parse_gomod in src/packagedcode/go_mod.py raises AttributeError: 'NoneType' object has no attribute 'group' whenever a go.mod file contains comments (e.g., // indirect) or blank lines inside a multiline require (...) or exclude (...) block.
When running a scan via the CLI (scancode --package), this unhandled exception causes ScanCode to fail silently on the go.mod file, resulting in 0 detected packages and missing all Go dependencies.
Steps to Reproduce
- Create a minimal
go.modfile containing comments or an empty line in arequireblock (typical output fromgo mod tidy):
module example.com/hello
go 1.21
require (
// Direct dependencies
github.com/stretchr/testify v1.8.4
// Indirect dependencies
github.com/davecgh/go-spew v1.1.1
)
- Run package scan:
scancode --package --json-pp scan.json go.mod
-
Notice that
scan.jsonreportspackages: [](empty list, no dependencies extracted). -
Calling
parse_gomodorGoModHandler.parsedirectly reveals the traceback:
Traceback (most recent call last):
File "src/packagedcode/golang.py", line 53, in parse
gomods = go_mod.parse_gomod(location)
File "src/packagedcode/go_mod.py", line 133, in parse_gomod
ns_name = parsed_dep_link.group('ns_name')
AttributeError: 'NoneType' object has no attribute 'group'
Root Cause
In src/packagedcode/go_mod.py, lines 132-135:
parsed_dep_link = parse_dep_link(req)
ns_name = parsed_dep_link.group('ns_name')
namespace, _, name = ns_name.rpartition('/')
if parsed_dep_link:
When req is a blank line or comment line, preprocess(req) strips it down to an empty string "". Consequently, parse_dep_link(req) returns None.
However, parsed_dep_link.group('ns_name') is called on line 133 before the if parsed_dep_link: check on line 135.
The exact same bug also exists on line 150 in the exclude (...) block:
parsed_dep_link = parse_dep_link(exc)
ns_name = parsed_dep_link.group('ns_name')
namespace, _, name = ns_name.rpartition('/')
if parsed_dep_link:
Proposed Solution
Move the attribute access inside the if parsed_dep_link: conditional block for both require and exclude:
parsed_dep_link = parse_dep_link(req)
if parsed_dep_link:
ns_name = parsed_dep_link.group('ns_name')
namespace, _, name = ns_name.rpartition('/')
require.append(
GoModule(
namespace=namespace,
name=name,
version=parsed_dep_link.group('version'),
)
)
And similarly for exclude:
parsed_dep_link = parse_dep_link(exc)
if parsed_dep_link:
ns_name = parsed_dep_link.group('ns_name')
namespace, _, name = ns_name.rpartition('/')
exclude.append(
GoModule(
namespace=namespace,
name=name,
version=parsed_dep_link.group('version'),
)
)
Environment
- ScanCode version: 33.0.0rc1 / develop branch
- OS: All
- Dominant language
- Python
- Stars
- 2.7k
- Forks
- 871
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 3
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from aboutcode-org/scancode-toolkit
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no errorPossibly taken @Shubham-dev-stack claimed this 6 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
aboutcode-org/scancode-toolkit#5466 ·
Maintainers usually reply within 2 days
-
package-lock.json dependencies report file_references as a list inside a listPossibly taken @Anbarasu2410 claimed this 9 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
aboutcode-org/scancode-toolkit#5449 · 4 comments ·
Maintainers usually reply within 2 days
-
scancode aborts when encountering a broken RPM archivePossibly taken @Ashutosh-Panda2004 claimed this 14 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
aboutcode-org/scancode-toolkit#5407 · 3 comments ·
Maintainers usually reply within 2 days
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappingsPossibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 2/5 Half a day Newbie friendliness 65/100
aboutcode-org/scancode-toolkit#5405 · 1 comment ·
Maintainers usually reply within 2 days
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle bracketsPossibly taken @RohitSutar1823 claimed this 14 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
aboutcode-org/scancode-toolkit#5402 ·
Maintainers usually reply within 2 days
All issues in aboutcode-org/scancode-toolkit
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mohanraj00/entelos#200 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
sweep
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bketelsen/truenas-mcp#77 ·
Maintainers usually reply within 1 day
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskOpen
Difficulty 1/5 Under an hour Newbie friendliness 86/100
sandbox-quantum/switch#2163 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
openedx/xblock-lti-consumer#765 ·
Maintainers usually reply within 1 day