Git Product home page Git Product logo

Comments (5)

fasterthanlime avatar fasterthanlime commented on June 12, 2024

Alternative idea:

type causer interface {
  Cause() error
}

func ErrCode(err error) ErrorCode { 
  if ce, ok := err.(causer); ok {
    return ErrCode(ce.Cause())
  }

  // ... current ErrCode code
}

This would support github.com/pkg/errors without creating a dependency.

Just two data points:

from sqlite.

crawshaw avatar crawshaw commented on June 12, 2024

Your second alternative is not so bad, but I wonder if this belongs in the sqlite package. I think a user can write their own ErrCode wrapper function and use that instead of sqlite.ErrCode, which can do any kind of handling they want. Is that not the case?

from sqlite.

fasterthanlime avatar fasterthanlime commented on June 12, 2024

Your second alternative is not so bad, but I wonder if this belongs in the sqlite package. I think a user can write their own ErrCode wrapper function and use that instead of sqlite.ErrCode, which can do any kind of handling they want. Is that not the case?

Well, ErrCode() is used in sqliteutil to determine whether to RELEASE or ROLLBACK at the end of a savepoint so.. yes and no.

(The err that Save()'s releaseFn analyzes would definitely be wrapped)

I suppose I could reimplement Save myself, but as we've seen today, it is tricky to get right :)

from sqlite.

crawshaw avatar crawshaw commented on June 12, 2024

sqliteutil.Save is a good argument. If you want to send a PR that looks for a causer interface I'll take it.

from sqlite.

crawshaw avatar crawshaw commented on June 12, 2024

Oh you did already. :-)

from sqlite.

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.