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

Panic on already generated godoc #70

Closed
krzwiatrzyk opened this issue Oct 12, 2023 · 2 comments
Closed

Panic on already generated godoc #70

krzwiatrzyk opened this issue Oct 12, 2023 · 2 comments

Comments

@krzwiatrzyk
Copy link

krzwiatrzyk commented Oct 12, 2023

My code:

package handler

import (
	"gmod/pkg/version"
	"net/http"

	"github.com/autometrics-dev/autometrics-go/prometheus/autometrics"
	"github.com/gin-gonic/gin"
)

//go:generate autometrics
//autometrics:inst
func (h *Handler) VersionHandler(ctx *gin.Context) {
	defer autometrics.Instrument(autometrics.PreInstrument(autometrics.NewContext(
		nil,
		autometrics.WithConcurrentCalls(true),
		autometrics.WithCallerName(true),
	)), nil) //autometrics:defer

	ctx.JSON(http.StatusOK, gin.H{
		"version": version.Version,
	})
}

First run of go generate ./... runs smooth, properly generates docs and instruments code. Executing it second time causes panic:

❯ go generate ./...
panic: runtime error: slice bounds out of range [:-1]

goroutine 1 [running]:
github.com/autometrics-dev/autometrics-go/internal/generate.cleanUpAutometricsComments({{{0x911459, 0x3}, {0x0, 0x0}, {0x0, 0x0}, 0x1, 0x1, 0x0}, {0x0, ...}, ...}, ...)
        /home/krzwiatrzyk/go/pkg/mod/github.com/autometrics-dev/[email protected]/internal/generate/documentation.go:43 +0x691
github.com/autometrics-dev/autometrics-go/internal/generate.walkFuncDeclaration(0xc000166000, 0xc000188000, {0xc0000322da?, 0x8cd560?})
        /home/krzwiatrzyk/go/pkg/mod/github.com/autometrics-dev/[email protected]/internal/generate/generate.go:145 +0x29b
github.com/autometrics-dev/autometrics-go/internal/generate.GenerateDocumentationAndInstrumentation.func1({0x9c6da0?, 0xc000188000?})
        /home/krzwiatrzyk/go/pkg/mod/github.com/autometrics-dev/[email protected]/internal/generate/generate.go:100 +0x4b
github.com/dave/dst.inspector.Visit(0xc000182240, {0x9c6da0?, 0xc000188000?})
        /home/krzwiatrzyk/go/pkg/mod/github.com/dave/[email protected]/walk.go:341 +0x31
github.com/dave/dst.Walk({0x9c82c0?, 0xc000182240?}, {0x9c6da0?, 0xc000188000?})
        /home/krzwiatrzyk/go/pkg/mod/github.com/dave/[email protected]/walk.go:52 +0x68
github.com/dave/dst.walkDeclList({0x9c82c0, 0xc000182240}, {0xc000132e60?, 0x2, 0x50?})
        /home/krzwiatrzyk/go/pkg/mod/github.com/dave/[email protected]/walk.go:38 +0x69
github.com/dave/dst.Walk({0x9c82c0?, 0xc000182240?}, {0x9c6d60?, 0xc00011ef70?})
        /home/krzwiatrzyk/go/pkg/mod/github.com/dave/[email protected]/walk.go:321 +0x173e
github.com/dave/dst.Inspect(...)
        /home/krzwiatrzyk/go/pkg/mod/github.com/dave/[email protected]/walk.go:353
github.com/autometrics-dev/autometrics-go/internal/generate.GenerateDocumentationAndInstrumentation({{{0x911459, 0x3}, {0x0, 0x0}, {0x0, 0x0}, 0x1, 0x1, 0x0}, {0x0, ...}, ...}, ...)
        /home/krzwiatrzyk/go/pkg/mod/github.com/autometrics-dev/[email protected]/internal/generate/generate.go:110 +0x2c5
github.com/autometrics-dev/autometrics-go/internal/generate.TransformFile({{{0x911459, 0x3}, {0x0, 0x0}, {0x0, 0x0}, 0x1, 0x1, 0x0}, {0x0, ...}, ...}, ...)
        /home/krzwiatrzyk/go/pkg/mod/github.com/autometrics-dev/[email protected]/internal/generate/generate.go:54 +0x2e8
main.main()
        /home/krzwiatrzyk/go/pkg/mod/github.com/autometrics-dev/[email protected]/cmd/autometrics/main.go:77 +0x1c5
pkg/handler/version.go:36: running "autometrics": exit status 2
@krzwiatrzyk
Copy link
Author

Also:

  • doc examples on autometrics website references bad pkg url (autometrics "github.com/autometrics-dev/autometrics-go/pkg/autometrics/otel <- not exist)

@gagbo
Copy link
Member

gagbo commented Oct 13, 2023

Hello, and thanks for the report.

I think I hit this issue once but since I have a test for this I thought I only got unlucky when I instrumented things. Apparently not, I'll look into this today.

And thanks for the doc example, we changed the name of the import to be more telling and I missed a few places!

gagbo added a commit that referenced this issue Oct 13, 2023
@gagbo gagbo closed this as completed in 6fb3c8d Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants