Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/mod/modfile: document what the path is used for in Parse #45149

Closed
dsnet opened this issue Mar 21, 2021 · 3 comments
Closed

x/mod/modfile: document what the path is used for in Parse #45149

dsnet opened this issue Mar 21, 2021 · 3 comments
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dsnet
Copy link
Member

dsnet commented Mar 21, 2021

The Parse function takes in a file name as the first argument. It does not seem obvious to me why a parse function should care about the file name at all in order to parse the contents of the the go.mod file. We should document better what this is used for and whether it is required.

Without studying the code too deeply, it seems that the filename is primarily used in error reporting and also to populate modfile.File.Syntax.Name but otherwise has not semantic impact on how the file is parsed.

In my situation, I don't have the original go.mod path on hand and it's not clear to me whether I should spend the effort to produce the exact right one or just put some arbitrary path.

@gopherbot gopherbot added this to the Unreleased milestone Mar 21, 2021
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 22, 2021
@cagedmantis
Copy link
Contributor

/cc @bcmills @jayconrod @matloob

@bcmills
Copy link
Contributor

bcmills commented Mar 23, 2021

In is indeed just there for error output — there are plenty of places in cmd/go itself where we just pass the string "go.mod" instead of a full path, when the full path is not available or not meaningful:

f, err = modfile.ParseLax("go.mod", data, nil)

f, err := modfile.Parse("go.mod", data, nil)

f, err := modfile.ParseLax("go.mod", data, nil)

Want to send a CL to clarify the documentation?

@gopherbot
Copy link

Change https://golang.org/cl/308452 mentions this issue: modfile: clarify documentation for Parse

@golang golang locked and limited conversation to collaborators Apr 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants