Giter Club home page Giter Club logo

Comments (4)

l3pp4rd avatar l3pp4rd commented on May 23, 2024

Hi, thanks. That is something what needs to be improved. Currently caught panics does not print stack trace, which needs to be changed. probably an error should have a different type similar to https://github.com/pkg/errors so it could print stack trace in verbose mode on %+v

Currently what I suggest you to do, is catch panic in your step in order to debug the reason. Later when I have some more time, I will revisit this. The issue is important but not critical to behavior. Thanks for reminding.

from godog.

upayavira avatar upayavira commented on May 23, 2024

Thx @l3pp4rd , how do I print a stack trace if all print statements are swallowed?

from godog.

l3pp4rd avatar l3pp4rd commented on May 23, 2024

to replicate it, lets simply create a small feature:

Feature: panic

  Scenario: panics
    Then fail with panic

Now implement the panic step in _test.go file.

package main

import (
    "fmt"

    "github.com/DATA-DOG/godog"
)

func myStepCallsFunc() {
    arr := make([]int, 0)
    fmt.Println(arr[6])
}

func failWithPanic() error {
    myStepCallsFunc()
    return nil
}

func FeatureContext(s *godog.Suite) {
    s.Step(`^fail with panic$`, failWithPanic)
}

Run it:

2016-10-06-071846

Then lets print stack trace of panic instead.

package main

import (
    "fmt"
    "runtime/debug"

    "github.com/DATA-DOG/godog"
)

func myStepCallsFunc() {
    arr := make([]int, 0)
    fmt.Println(arr[6])
}

func failWithPanic() (err error) {
    defer func() {
        if r := recover(); r != nil {
            err = fmt.Errorf("runtime error: %s", r)
            debug.PrintStack()
        }
    }()
    myStepCallsFunc()
    return
}

func FeatureContext(s *godog.Suite) {
    s.Step(`^fail with panic$`, failWithPanic)
}

And you see the output now:

2016-10-06-073310

from godog.

upayavira avatar upayavira commented on May 23, 2024

The simple answer is to use "log" which still outputs. Apologies for the noise.

from godog.

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.