[BUG] parse_gomod crashes with AttributeError on comments or blank lines inside require/exclude blocks
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 2.7k
- Forks
- 871
- Ø Merge
- 1 T. 10 Std.
- Gemergte PRs (30 T.)
- 3
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus aboutcode-org/scancode-toolkit
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no errorEvtl. vergeben @Shubham-dev-stack hat das vor 6 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
aboutcode-org/scancode-toolkit#5466 ·
Maintainer antworten meist innerhalb von 1 Tag
-
package-lock.json dependencies report file_references as a list inside a listEvtl. vergeben @Anbarasu2410 hat das vor 10 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
aboutcode-org/scancode-toolkit#5449 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
scancode aborts when encountering a broken RPM archiveEvtl. vergeben @Ashutosh-Panda2004 hat das vor 14 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
aboutcode-org/scancode-toolkit#5407 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappingsEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenbug
Schwierigkeit 2/5 Ein halber Tag Anfängerfreundlichkeit 65/100
aboutcode-org/scancode-toolkit#5405 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle bracketsEvtl. vergeben @RohitSutar1823 hat das vor 15 Tagen übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
aboutcode-org/scancode-toolkit#5402 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in aboutcode-org/scancode-toolkit
Ähnliche Issues
-
author-page correction move-papers
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 78/100
acl-org/acl-anthology#10978 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
PostgreSQL results table stores labels with single quotes, and a double quote in a label fails the writeEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
HKUDS/CLI-Anything#652 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Project-N-E-K-O/N.E.K.O#3813 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Dao-AILab/flash-attention#3191 ·
Maintainer antworten meist innerhalb von 4 Tagen