respect output file path on gofmt failure#2356
Conversation
When `imports.Process` rejected the generated source, `Generate()` discarded the code and stuffed a line-numbered dump of it into the returned error. The CLI then printed that error to stderr and never wrote the requested `-o` (or config `output:`) file, so users saw a huge stderr spew with no output file produced. Return the raw pre-format code from `Generate()` alongside the error, and have the CLI write it to the configured destination before exiting. The error message itself is now a single line referencing the failing source line; users can open the written file to inspect the broken code directly. `addLineNumbers` is dropped — it was only used by the removed in-error code dump. Closes: oapi-codegen#2340
Greptile SummaryThis PR fixes the UX regression from #2340 where a formatter error caused Confidence Score: 4/5Safe to merge; the fix is narrow and well-reasoned, with only minor documentation and test-coverage gaps. Both findings are P2-only — missing regression test and undocumented contract change on Generate(). The logic change is correct and the CLI behaviour is clearly improved. P2s cap the score at 4/5. pkg/codegen/codegen.go — the changed Generate() return-value contract should be documented in godoc, and a regression test for the error path would be valuable.
|
| Filename | Overview |
|---|---|
| pkg/codegen/codegen.go | Generate() now returns raw unformatted code on imports.Process failure instead of ""; addLineNumbers helper removed; error message simplified to single-line with optional line number |
| cmd/oapi-codegen/oapi-codegen.go | CLI now writes/prints any non-empty code returned by Generate() before checking genErr, ensuring broken output reaches the configured destination for inspection |
Reviews (1): Last reviewed commit: "respect output file path on gofmt failur..." | Re-trigger Greptile
When
imports.Processrejected the generated source,Generate()discarded the code and stuffed a line-numbered dump of it into the returned error. The CLI then printed that error to stderr and never wrote the requested-o(or configoutput:) file, so users saw a huge stderr spew with no output file produced.Return the raw pre-format code from
Generate()alongside the error, and have the CLI write it to the configured destination before exiting. The error message itself is now a single line referencing the failing source line; users can open the written file to inspect the broken code directly.addLineNumbersis dropped — it was only used by the removed in-error code dump.Closes: #2340