| 118 | // nil interface but neither a nil slice nor an interface holding a nil pointer, so an |
| 119 | // empty listing would otherwise marshal as `"data": null` and the documented |
| 120 | // `--jq '.data[]'` recipe would fail on it, and a mutation the API answered with |
| 121 | // nothing would report `"data": null` rather than leaving the key out. |
| 122 | func normalizeData(data any) any { |
| 123 | value := reflect.ValueOf(data) |
| 124 | switch { |
| 125 | case value.Kind() == reflect.Slice && value.IsNil(): |
| 126 | return reflect.MakeSlice(value.Type(), 0, 0).Interface() |
| 127 | case value.Kind() == reflect.Pointer && value.IsNil(): |
| 128 | return nil |
| 129 | default: |
| 130 | return data |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | func (w *Writer) Err(err error) { |
| 135 | e := apierr.AsError(err) |
| 136 | format := w.EffectiveFormat() |
| 137 | |
| 138 | // An --html run is a person redirecting to a file: the error reads as text on |
| 139 | // stderr, as it does on a terminal, rather than as a JSON envelope. Either way the |