FAQ
Hi.

In a project I'm using the same error message (created using errors.New) to
report errors in a function; this is similar to what it is done in the
strconv.UnquoteChar function, using ErrSyntax.
The problem is that during testing the information of where the error
occurred is lost.
I searched for more advanced error support, but all the packaged I found
were too big.

So I decided to implement my own version, available at:
https://gist.github.com/perillo/f0eeb79a938e82c981d5

The package provides two support functions, Clone and Equal, that can be
used, as an example, for:

import "https://gist.github.com/perillo/f0eeb79a938e82c981d5"

var ErrSyntax = errors.New("invalid syntax")

func foo() error {
     ...
     return errors.Clone(ErrSyntax)
}

func main() {
     err := foo()
     if errors.Equal(err, ErrSyntax) { ... }
}


Feedback is appreciated.
I'm not sure I'm using the program counter correctly.
I'm also not sure about the Errorf name, since errors.Errorf sounds bad.


Thanks Manlio



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Tamás Gulácsi at Nov 23, 2015 at 12:08 pm
    I'd suggest gopkg.in/errgo.v1

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Manlio Perillo at Nov 23, 2015 at 1:58 pm
    Il giorno lunedì 23 novembre 2015 13:08:26 UTC+1, Tamás Gulácsi ha scritto:

    The API seems too complex for me.
    Moreover I have read the code a pair of time and I have yet to understand
    what the Causer means [1].

    The API also have the problem that the Error method returns the "plain"
    information, and I need to call an additional function to get debug details
    (but at least it implements the GoStringer interface).
    It is my impression that the error handling suggested by gopkg.in/errgo.v1
    is to wrap each error handled on the call stack, so that the Details
    function is equivalent to printing the stack trace.
    gopkg.in/errgo.v1 just prints a less verbose stack trace, compared to
    another implementation that prints the entire stack trace as it is done by
    the go runtime during a panic.

    [1] This may be a my problem since it took me several days to understand
    GOPATH and friends.
           But Donald A. Norman says that the problem is always caused by the
    designer, not the user.


    Regards Manlio

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Dan Kortschak at Nov 23, 2015 at 10:29 pm

    On Mon, 2015-11-23 at 05:58 -0800, Manlio Perillo wrote:
    Moreover I have read the code a pair of time and I have yet to
    understand
    what the Causer means [1].
    Please file an issue on this.

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Chris Hines at Nov 23, 2015 at 7:28 pm
    Shameless plug: You might find my gopkg.in/stack.v1 package useful as a
    building block.

    Chris
    On Monday, November 23, 2015 at 6:40:48 AM UTC-5, Manlio Perillo wrote:

    Hi.

    In a project I'm using the same error message (created using errors.New)
    to report errors in a function; this is similar to what it is done in the
    strconv.UnquoteChar function, using ErrSyntax.
    The problem is that during testing the information of where the error
    occurred is lost.
    I searched for more advanced error support, but all the packaged I found
    were too big.

    So I decided to implement my own version, available at:
    https://gist.github.com/perillo/f0eeb79a938e82c981d5

    The package provides two support functions, Clone and Equal, that can be
    used, as an example, for:

    import "https://gist.github.com/perillo/f0eeb79a938e82c981d5"

    var ErrSyntax = errors.New("invalid syntax")

    func foo() error {
    ...
    return errors.Clone(ErrSyntax)
    }

    func main() {
    err := foo()
    if errors.Equal(err, ErrSyntax) { ... }
    }


    Feedback is appreciated.
    I'm not sure I'm using the program counter correctly.
    I'm also not sure about the Errorf name, since errors.Errorf sounds bad.


    Thanks Manlio


    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Manlio Perillo at Nov 23, 2015 at 7:39 pm
    Il giorno lunedì 23 novembre 2015 20:28:33 UTC+1, Chris Hines ha scritto:
    Shameless plug: You might find my gopkg.in/stack.v1
    <http://www.google.com/url?q=http%3A%2F%2Fgopkg.in%2Fstack.v1&sa=D&sntz=1&usg=AFQjCNEwWDKybTP4qRr3zBxjlrKP-Bx2CQ>
    package useful as a building block.
    Thanks.
    I too was planning to implement the support for printing the package import
    path, instead of the absolute source file, but decided to give up for the
    sake of simplicity.
    gopkg.in/stack.v1 is interesting but simply "too much" for handling errors
    (IMHO, of course).


    Manlio

    --
    You received this message because you are subscribed to the Google Groups "golang-nuts" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 23, '15 at 11:40a
activeNov 23, '15 at 10:29p
posts6
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase