Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Being EOL, any alternative recommendation #143

Open
satish-suradkar opened this issue Jan 11, 2023 · 3 comments
Open

Being EOL, any alternative recommendation #143

satish-suradkar opened this issue Jan 11, 2023 · 3 comments

Comments

@satish-suradkar
Copy link

Since this package is EOL, is there any alternative recommendation?

@derekperkins
Copy link

https://github.com/sanity-io/litter

@yassinebenaid
Copy link

there is this one too:

https://github.com/yassinebenaid/godump

@fira42073
Copy link

@yassinebenaid this one is amazing, but it panics on array types C:

I did a small workaround, but tbh don't have time to open a proper PR. if you can fix it in one of the future releases using the idiomatic behavior you deem proper, I'd really appreciate that.

diff --git a/dumper.go b/dumper.go
index 45968c1..a05a16a 100644
--- a/dumper.go
+++ b/dumper.go
@@ -248,7 +248,21 @@ func (d *Dumper) dumpSlice(v reflect.Value) {
 		d.ptrTag = 0
 	}
 
-	if v.IsNil() {
+	defer func() {
+		if r := recover(); r != nil {
+			d.buf.WriteString(__(d.Theme.Types, v.Type().String()))
+			d.writeNil()
+			d.buf.WriteString(tag)
+		}
+	}()
+
+	// this might panic if it's an array instead of slice
+	if v.IsZero() {
+		d.buf.WriteString(__(d.Theme.Types, v.Type().String()))
+		d.writeZeroValue()
+		d.buf.WriteString(tag)
+		return
+	} else if v.IsNil() {
 		d.buf.WriteString(__(d.Theme.Types, v.Type().String()))
 		d.writeNil()
 		d.buf.WriteString(tag)
@@ -422,3 +436,7 @@ func (d *Dumper) wrapType(v reflect.Value, str string) {
 func (d *Dumper) writeNil() {
 	d.buf.WriteString(__(d.Theme.Braces, "(") + __(d.Theme.Nil, "nil") + __(d.Theme.Braces, ")"))
 }
+
+func (d *Dumper) writeZeroValue() {
+	d.buf.WriteString(__(d.Theme.Braces, "(") + __(d.Theme.Nil, "<zero value>") + __(d.Theme.Braces, ")"))
+}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants