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

Dump(cuecontext.New()): Litter does not, spew does #52

Open
rudifa opened this issue Dec 4, 2023 · 1 comment
Open

Dump(cuecontext.New()): Litter does not, spew does #52

rudifa opened this issue Dec 4, 2023 · 1 comment

Comments

@rudifa
Copy link

rudifa commented Dec 4, 2023

Describe the bug

sanity-io litter.Dump(ctx) fails to dump a moderately complex struct cuecontext.New() where spew.Dump(ctx) dumps over 100 lines.

Both dumpers print a reasonable representation of a simple demo struct

To Reproduce

Run the main.go shown in the next comment and observe results (also reproduced below)

Expected behavior

A detailed dump of ctx by litter, equivalent to that from spew

Observed behavior

From litter.Dump(ctx) I get just a single line:

&cue.Context{}

Which versions of Sanity are you using?

v1.5.5
@atombender atombender tagged this Apr 28, 2022

What operating system are you using?

try-litter % sw_vers
ProductName: macOS
ProductVersion: 13.6.1
BuildVersion: 22G313

Which versions of Node.js / npm are you running?

try-litter % npm -v && node -v
9.8.0
v20.5.1

Additional context

Security issue?

No

@rudifa
Copy link
Author

rudifa commented Dec 4, 2023

Here is the test module

module example.com/try-litter

go 1.21.0

require (
	cuelang.org/go v0.6.0
	github.com/davecgh/go-spew v1.1.1
	github.com/sanity-io/litter v1.5.5
)

require (
	github.com/cockroachdb/apd/v3 v3.2.0 // indirect
	github.com/google/uuid v1.2.0 // indirect
	github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de // indirect
	golang.org/x/net v0.8.0 // indirect
	golang.org/x/text v0.8.0 // indirect
	gopkg.in/yaml.v3 v3.0.1 // indirect
)
package main

import (
	"fmt"

	"cuelang.org/go/cue/cuecontext"

	"github.com/davecgh/go-spew/spew"
	"github.com/sanity-io/litter"
)

func main() {
	SpewVsLitter_Person()

	SpewVsLitter_CueCtx()
}

func SpewVsLitter_Person() {

	type Person struct {
		Name   string
		Age    int
		Parent *Person
	}

	p := Person{
		Name: "Bob",
		Age:  20,
		Parent: &Person{
			Name: "Jane",
			Age:  50,
		},
	}

	fmt.Println("=== SpewVsLitter_Person()")

	fmt.Println("--- spew.Dump(p):")
	spew.Dump(p)

	fmt.Println("--- litter.Dump(p):")
	litter.Dump(p)
}

func SpewVsLitter_CueCtx() {
	ctx := cuecontext.New()

	fmt.Println("=== SpewVsLitter_CueCtx()")

	fmt.Println("--- spew.Dump(ctx):")
	spew.Dump(ctx)

	fmt.Println("--- litter.Dump(ctx):")
	litter.Dump(ctx)

}

This is the output

=== SpewVsLitter_Person()
--- spew.Dump(p):
(main.Person) {
 Name: (string) (len=3) "Bob",
 Age: (int) 20,
 Parent: (*main.Person)(0xc000250ac0)({
  Name: (string) (len=4) "Jane",
  Age: (int) 50,
  Parent: (*main.Person)(<nil>)
 })
}
--- litter.Dump(p):
main.Person{
  Name: "Bob",
  Age: 20,
  Parent: &main.Person{
    Name: "Jane",
    Age: 50,
    Parent: nil,
  },
}
=== SpewVsLitter_CueCtx()
--- spew.Dump(ctx):
(*cue.Context)(0xc00012e798)({
 index: (*runtime.index)(0xc0002627e0)({
  lock: (sync.RWMutex) {
   w: (sync.Mutex) {
    state: (int32) 0,
    sema: (uint32) 0
   },
   writerSem: (uint32) 0,
   readerSem: (uint32) 0,
   readerCount: (atomic.Int32) {
    _: (atomic.noCopy) {
    },
    v: (int32) 0
   },
   readerWait: (atomic.Int32) {
    _: (atomic.noCopy) {
    },
    v: (int32) 0
   }
  },
  imports: (map[*adt.Vertex]*build.Instance) {
  },
  importsByPath: (map[string]*adt.Vertex) {
  },
  importsByBuild: (map[*build.Instance]*adt.Vertex) {
  },
  nextUniqueID: (uint64) 0,
  builtinPaths: (map[string]runtime.PackageFunc) (len=30) {
   (string) (len=11) "crypto/sha1": (runtime.PackageFunc) 0x12e4c00,
...
... about 100 lines elided
...
   (string) (len=7) "strings": (string) (len=7) "strings"
  },
  typeCache: (sync.Map) {
   mu: (sync.Mutex) {
    state: (int32) 0,
    sema: (uint32) 0
   },
   read: (atomic.Pointer[sync.readOnly]) {
    _: ([0]*sync.readOnly) {
    },
    _: (atomic.noCopy) {
    },
    v: (unsafe.Pointer) <nil>
   },
   dirty: (map[interface {}]*sync.entry) <nil>,
   misses: (int) 0
  }
 }),
 loaded: (map[*build.Instance]interface {}) {
 },
 interpreters: (map[string]runtime.Interpreter) <nil>
})
--- litter.Dump(ctx):
&cue.Context{}

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

1 participant