[BUG] parse_gomod crashes with AttributeError on comments or blank lines inside require/exclude blocks
メンテナーはふだん 2 日以内に返信
評価
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 2.7k
- フォーク
- 871
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 3
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aboutcode-org/scancode-toolkit のほかの issue
-
yarn.lock v1 with a scoped alias of an unscoped package yields no packages and no error対応中かも @Shubham-dev-stack が 6 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
aboutcode-org/scancode-toolkit#5466 ·
メンテナーはふだん 2 日以内に返信
-
package-lock.json dependencies report file_references as a list inside a list対応中かも @Anbarasu2410 が 9 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
aboutcode-org/scancode-toolkit#5449 · コメント 4 件 ·
メンテナーはふだん 2 日以内に返信
-
scancode aborts when encountering a broken RPM archive対応中かも @Ashutosh-Panda2004 が 14 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
aboutcode-org/scancode-toolkit#5407 · コメント 3 件 ·
メンテナーはふだん 2 日以内に返信
-
Four silent bugs: IsRequiredPhrase.license_expression returns None, find_in_path ignores later PATH changes, duplicate dict keys override license mappings対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンbug
難易度 2/5 半日 初心者へのやさしさ 65/100
aboutcode-org/scancode-toolkit#5405 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
parse_maintainer_name_email returns empty name and wrong email when string has "@" but no angle brackets対応中かも @RohitSutar1823 が 15 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
aboutcode-org/scancode-toolkit#5402 ·
メンテナーはふだん 2 日以内に返信
aboutcode-org/scancode-toolkit の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
GoogleCloudPlatform/professional-services-data-validator#1899 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
mohanraj00/entelos#200 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
-
sweep
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
bketelsen/truenas-mcp#77 ·
メンテナーはふだん 1 日以内に返信
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskオープン
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
sandbox-quantum/switch#2163 ·
メンテナーはふだん 1 日以内に返信