Skip to content

[bug] Gazelle fails to parse go.mod if godebug is set #2137

@albertocavalcante

Description

@albertocavalcante

go.mod accepts godebug as per https://go.dev/doc/modules/gomod-ref#godebug, but gazelle fails when this field is set.

repro: https://github.com/albertocavalcante/repros/tree/main/2025-07-08-bazel-gazelle

stacktrace:

ERROR: /private/var/tmp/_bazel_user/b657a3728cd030fff5d5deff34f01ea1/external/gazelle+/internal/bzlmod/go_mod.bzl:215:21: Traceback (most recent call last):
        File "/private/var/tmp/_bazel_user/b657a3728cd030fff5d5deff34f01ea1/external/gazelle+/internal/bzlmod/go_deps.bzl", line 428, column 95, in *go*deps_impl
                module_path, module_tags_from_go_mod, go_mod_replace_map, tools = deps_from_go_mod(module_ctx, from_file_tag.go_mod)
        File "/private/var/tmp/_bazel_user/b657a3728cd030fff5d5deff34f01ea1/external/gazelle+/internal/bzlmod/go_mod.bzl", line 171, column 26, in deps_from_go_mod
                go_mod = parse_go_mod(go_mod_content, go_mod_path)
        File "/private/var/tmp/_bazel_user/b657a3728cd030fff5d5deff34f01ea1/external/gazelle+/internal/bzlmod/go_mod.bzl", line 215, column 21, in parse_go_mod
                fail("{}:{}: unexpected token '{}' at start of line".format(path, line_no, tokens[0]))
Error in fail: /Users/user/dev/workspace/repros/2025-07-08-bazel-gazelle/go.mod:5: unexpected token 'godebug' at start of line

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions