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

"Error: an error occured while trying to parse imports: path is missing starting quotes" on valid Go file #48

Closed
charleskorn opened this issue Mar 1, 2022 · 3 comments · Fixed by #49
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@charleskorn
Copy link
Contributor

If I have a file that contains this content:

package main

import (
	/*
		#include "types.h"
	*/
	"C"
)

...and invoke gci with gci diff --debug file.go, I get this error:

2022/03/01 11:42:07 Loaded File: file.go
Error: an error occured while trying to parse imports: path is missing starting quotes

Is this expected? I can't see what the issue is.

Removing the /* ... */ causes gci to not fail with an error, but I can't remove that comment as cgo relies on it.

@daixiang0 daixiang0 added bug Something isn't working help wanted Extra attention is needed labels Mar 1, 2022
@daixiang0
Copy link
Owner

Yes, it is truly a bug with CGO, someone interested in fixing it need to add a check for CGO part and skip them.

@charleskorn
Copy link
Contributor Author

Do you have any pointers on where to start to fix this @daixiang0?

@daixiang0
Copy link
Owner

parseToImportDefinitions in pkg/gci/parse.go.

charleskorn added a commit to charleskorn/gci that referenced this issue Mar 2, 2022
…issing starting quotes" when parsing a file with block comments.

Fixes daixiang0#48.

Note that this only handles simple cases for block comments, and does
not cover more complex cases (see FIXME in parse.go).
charleskorn added a commit to charleskorn/gci that referenced this issue Mar 2, 2022
…issing starting quotes" when parsing a file with block comments.

Fixes daixiang0#48.

Note that this only handles simple cases for block comments, and does
not cover more complex cases (see FIXME in parse.go).

Signed-off-by: Charles Korn <me@charleskorn.com>
daixiang0 pushed a commit that referenced this issue Mar 3, 2022
…or cgo imports. (#49)

* Fix "Error: an error occured while trying to parse imports: path is missing starting quotes" when parsing a file with block comments.

Fixes #48.

Note that this only handles simple cases for block comments, and does
not cover more complex cases (see FIXME in parse.go).

Signed-off-by: Charles Korn <me@charleskorn.com>

* Make block comment parsing more robust to different formatting.

Signed-off-by: Charles Korn <me@charleskorn.com>

* Add test case for multiple comments before a "C" import.

Signed-off-by: Charles Korn <me@charleskorn.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants