Skip to content

buf curl: malformed-header errors report 0-based, drifting line numbers #8

Description

@fchimpan

Summary

Malformed-header errors from buf curl header files report 0-based line numbers that additionally do not count blank or comment lines, so the reported location drifts away from the real file line.

Reproduction

printf '# comment\nno-colon-here\n' > hdrs.txt
buf curl --http2-prior-knowledge -H @hdrs.txt http://127.0.0.1:9/foo.v1.FooService/Bar
# Failure: hdrs.txt:0: malformed header: "no-colon-here"     <- actual file line: 2

(Verified against a local build — the output above is real.)

Root cause

private/buf/bufcurl/headers.go:131-157var lineNo int starts at 0 and is incremented only after a successful addHeader; the continue for blank/comment lines never increments it:

var lineNo int
for {
	line, err := in.ReadLine()
	...
	if strings.TrimSpace(line) == "" || strings.HasPrefix(line, "#") {
		continue                       // lineNo not incremented
	}
	if !addHeader(line, headers) {
		return nil, fmt.Errorf("%s:%d: malformed header: %q", headerFile, lineNo, line)
	}
	lineNo++                           // incremented only on success
}

Expected

Increment a 1-based counter on every line read, so file:N matches the editor's line number.


Found via a full mutest (mutation-testing) run over this repo; verified manually.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions