Git Product home page Git Product logo

Comments (8)

christophcemper avatar christophcemper commented on September 2, 2024

Yes,

also getting a panic for time pointers

%!v(PANIC=Format method: value method time.Time.GoString called using nil *Time pointer)

with a *time.Time in a struct that = nil

Go 1.17.6
Prettty v0.3.0

from pretty.

kr avatar kr commented on September 2, 2024

Some relevant info in https://go.dev/issue/20995.

from pretty.

drinktee avatar drinktee commented on September 2, 2024

Same issue. How to fix ?

from pretty.

barrettj12 avatar barrettj12 commented on September 2, 2024

Still observing this on Go 1.18.5.

from pretty.

jameinel avatar jameinel commented on September 2, 2024

So the go dev issue 20995 says that the workaround (while a bit ugly) is to essentially check to see if you have a pointer, and whether the Elem of the pointer has the method:

if fieldType.Kind() == reflect.Ptr && field.IsNil() {
	// Method defined on a value receiver.
	if _, ok := fieldType.Elem().MethodByName("Check"); ok {
		continue // Ignore since value can't be retrieved from nil pointer
	}
}

Essentially you are saying "oh, I have a nil pointer, let me check if the method is defined on the Value (non-pointer) of this type".
I'm not sure if that means all of the kr/pretty code that says "you have a custom formatter" then needs to do this check (but the custom formatter is defined on a value type but I have a nil pointer)
It doesn't seem bad to just say "ignore custom formatters if you have a nil pointer"

from pretty.

benhoyt avatar benhoyt commented on September 2, 2024

We fixed this in our canonical fork at canonical@771f4dc (see discussion at canonical#1). It's fixed in a similar way to how fmt does when calling GoString and other user-defined methods. I've also created a pull request here with the same fix: #87

from pretty.

PrMinisterGR avatar PrMinisterGR commented on September 2, 2024

Shouldn't there be a new proper release with this fix integrated?

from pretty.

kr avatar kr commented on September 2, 2024

Shouldn't there be a new proper release with this fix integrated?

Yes indeed. Just tagged v0.3.1. Thank you.

from pretty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.