Skip to content

Conversation

@jamietanna
Copy link
Member

@jamietanna jamietanna commented Nov 1, 2025

When formatting the resulting output, using goimports, we may
receive an error due to generating invalid code using our templates.

The output returned is fairly unhelpful, noting a line number, but
requiring the users to take the broken output and then paste it into
something that has a line number.

This improves the output by reporting:

  • line numbers for the resulting Go code
  • a ❗ where the (first) formatting error is found

I.e.

    104:             }
    105:             a.AdditionalProperties[fieldName] = fieldVal
    106:         }
    107:     }
    108:        return nil
    109: }
    110: 
    111: // Override default JSON handling for ArrayContainer to handle AdditionalProperties
    112: func (a ArrayContainer) MarshalJSON() ([]byte, error) {
    113:     var err error
    114:     object := make(map[string]json.RawMessage)
    115: 
    116:     /* JVT:
    117:     #v%!(EXTRA codegen.Property={ values {[]string  0xc0000de600 map[] [] false <nil> [] true  [] <nil> true 0xc0000e0c00} false false false false false map[x-go-type-skip-optional-pointer:true] false})
    118:     #{ values {[]string  0xc0000de600 map[] [] false <nil> [] true  [] <nil> true 0xc0000e0c00} false false false false false map[x-go-type-skip-optional-pointer:true] false}
    119:     []string
    120:     []string
    121: 
    122:     */
    123: if a.Values != nil { 
    124:     object["values"], err = json.Marshal(a.Values)
    125:     if err != nil {
    126:         return nil, fmt.Errorf("error marshaling 'values': %w", err)
    127:     }
    128: 
    129: 
    130:     for fieldName, field := range a.AdditionalProperties {
    131:                object[fieldName], err = json.Marshal(field)
    132:                if err != nil {
    133:                        return nil, fmt.Errorf("error marshaling '%s': %w", fieldName, err)
    134:                }
    135:        }
    136:        return json.Marshal(object)
    137: }
    138: 
❗  139: 
    140: 
error was: issue2031.go:139:2: expected '}', found 'EOF'
exit status 1
generate.go:3: running "go": exit status 1

@jamietanna jamietanna requested a review from a team as a code owner November 1, 2025 10:57
@jamietanna jamietanna added the bug Something isn't working label Nov 1, 2025
@jamietanna jamietanna changed the title chore: report formatting errors with line numbers fix: report formatting errors with line numbers Nov 1, 2025
When formatting the resulting output, using `goimports`, we may
receive an error due to generating invalid code using our templates.

The output returned is fairly unhelpful, noting a line number, but
requiring the users to take the broken output and then paste it into
something that has a line number.

This improves the output by reporting:

- line numbers for the resulting Go code
- a ❗ where the (first) formatting error is found
@jamietanna jamietanna merged commit 7a6b40a into main Nov 1, 2025
46 checks passed
@jamietanna jamietanna deleted the chore/line-number branch November 1, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants