Giter Site home page Giter Site logo

Proposal: show var names in output about is HOT 8 CLOSED

v-braun avatar v-braun commented on September 16, 2024 1
Proposal: show var names in output

from is.

Comments (8)

matryer avatar matryer commented on September 16, 2024 1

I had this same thought. I quite like it. We should see how well the AST stuff works (see #24) as this might make it easy.

from is.

v-braun avatar v-braun commented on September 16, 2024 1

see the new PR #25
included are the var names and also your proposal with the variable src (for NoErr)

That is how it looks like:
image

see is_test.go:170 or this testcase with the error source example.

I am currentley not happy with the print output. There are a lot of information (file, line, var name, var value, var type, comment, err src) in just one line. Maybe there is a better way to format the otput.

Anyhow the AST stuff makes fun and is simpliar than I thout.

from is.

v-braun avatar v-braun commented on September 16, 2024

Will check that out in a new experimental branch.

from is.

matryer avatar matryer commented on September 16, 2024

Thanks @v-braun.

While you're there, I wonder how easy it might be to detect where a variable came from, or more specifically where it was last assigned to.

How cool would it be if you would write this:

err := something()
is.NoErr(err)

And get a failure that said:

err: some error  // from: something()

from is.

v-braun avatar v-braun commented on September 16, 2024

i have built something simmiliar! will push it later.
not exactley your example but is also nice:

is.NoErr(errors.New("BANG!"))

will end in:

err: errors.New("BANG!")

That is for sure not exactley your example but also very helpfull.

I think the other case is also solvable through AST but is much more complex.
So in theory I have the error ast.Node and have only to search the entire AST again for a declaration/assignment to this ast.Node.

from is.

matryer avatar matryer commented on September 16, 2024

@v-braun This is very cool but I'm not sure the complexity is worth it just yet. I'll review the code more. But I had a thought. Maybe it shouldn't show the code if there is a comment? In theory, if you put a comment, that's what you care about isn't it?

from is.

j0holo avatar j0holo commented on September 16, 2024

I agree with @matryer, while it is a neat idea this problem can already be solved with a debugger. You know where the test went wrong, put a breakpoint on the function under test and you can inspect each step.

from is.

matryer avatar matryer commented on September 16, 2024

Closing for now, thanks all.

from is.

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.