Git Product home page Git Product logo

Comments (9)

cosmos72 avatar cosmos72 commented on May 23, 2024

Can you please provide a (possibly small) package that exhibits this problem?

I could not find readsig.go or SigElemType anywhere, and for me :env works with all packages that I tried until now...

Thanks

from gomacro.

glycerine avatar glycerine commented on May 23, 2024

yeah, sorry about that. It's difficult to minimize the reproducer.
type SigElemType int is just a type in the code.

from gomacro.

cosmos72 avatar cosmos72 commented on May 23, 2024

I have an idea - it comes from the observation that :env only calls the String() method (if available) of the constants, variables, functions and types declared in the package.

Maybe the package contains some SigElemType constants, and SigElemType has a method String() that panics if the receiver is not one of the "known good" constants, and the SigElemType constant '9' is declared but is not among the "known good" ones?

Checking line 66 of readsig.go, where the panic happens, could help verifying if this is the case...

from gomacro.

glycerine avatar glycerine commented on May 23, 2024

Yes, you were right, @cosmos72. I was missing some constants in a big switch doing String() string output. When I filled in the missing cases, then :env is happy.

Partial repro here:

https://github.com/glycerine/repro

from gomacro.

glycerine avatar glycerine commented on May 23, 2024

obviously this is user error on my part. My code should have had those constants. I'm sure rob pike published a tool at one point to generate those String() methods for us automagically, but I can't remember what it is called to find it again.

Anyway.

I'll leave this open--for you to close when you wish-- just in case something occurs to you that would make such confusion over cause less likely in the future. I'm not sure what to suggest other than to point out to me that the crash was in my code and not in gomacro; gomacro was invoking my code during :env -- that's the part I didn't realize.

from gomacro.

cosmos72 avatar cosmos72 commented on May 23, 2024

Thanks :) it makes sense that a big switch could miss some cases.

I will harden :env against panics in String() and GoString() methods of the constants, variables, types and functions present in the package

from gomacro.

cosmos72 avatar cosmos72 commented on May 23, 2024

About autogenerating the String() method:

if you do not find anything already implemented for the purpose, gomacro has extensive (although poorly documented) code generation features - it could be a nice and simple example, if I have time I will implement it and reply here

from gomacro.

cosmos72 avatar cosmos72 commented on May 23, 2024

Commit 6eee083 should fix this problem.

Anyway, as you wrote in https://github.com/glycerine/repro, a panic in the String() method usually has a different and non-fatal effect: :env simply shows the panic message instead of the constant or variable, as for example:

ArrayFSMTy      = %!v(PANIC=unknown SigElemType: '9')	// repro.SigElemType

so, lacking a clear analysis, I am still not 100% convinced that commit 6eee083 is enough.

Can you try updating gomacro and re-running :env on your private package?

from gomacro.

glycerine avatar glycerine commented on May 23, 2024

Confirmed: the panics no longer crash gomacro. Looks good. Thanks again!

from gomacro.

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.