colorjson icon indicating copy to clipboard operation
colorjson copied to clipboard

marshalValue silently fails for unsupported values

Open dolmen opened this issue 5 years ago • 4 comments

marshalValue doesn't handle the wide range of values supported by encoding/json (such as any value implementing json.Marshaler) but silently fails (no output) instead of reporting an error indicating an unsupported data type.

Example: https://play.golang.org/p/dmF0aGDl0J5

package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/TylerBrock/colorjson"
)

func main() {
	raw := json.RawMessage(`{
  "str": "foo",
  "num": 100,
  "bool": false,
  "null": null,
  "array": ["foo", "bar", "baz"],
  "obj": { "a": 1, "b": 2 }
}`)

	f := colorjson.NewFormatter()
	f.Indent = 2

	b, err := f.Marshal(raw)
	if err != nil {
		log.Fatal(err)
	}
	if len(b) == 0 {
		log.Fatal("no output")
	}
	fmt.Println(string(b))
}

dolmen avatar Jun 04 '19 08:06 dolmen

Came across the same issue. When calling colorjson.Marshal no error and no output is returned back.

diogogmt avatar Dec 13 '20 22:12 diogogmt

bump

pablodz avatar Oct 15 '21 16:10 pablodz

same

DaveGardner-Alfi avatar May 03 '22 18:05 DaveGardner-Alfi

same

Freccia avatar Oct 12 '22 10:10 Freccia