GithubHelp home page GithubHelp logo

safeString() not so safe about logfmt HOT 7 CLOSED

go-logfmt avatar go-logfmt commented on July 30, 2024
safeString() not so safe

from logfmt.

Comments (7)

ChrisHines avatar ChrisHines commented on July 30, 2024

Good observation.

The basic structure of safeString was modeled on how the standard library fmt package handles panics. It's been a while since I implemented it here, and I haven't tracked if the fmt package's handling of panics has improved or changed since I looked at it back then, but here is the pertinent code in fmt today: https://golang.org/src/fmt/print.go#L530. At first glance it looks like fmt tries harder to avoid propagating the panic.

I tend to agree with your suggestion that we can and probably should do more here. Would you like to work on a PR to improve this?

from logfmt.

bboreham avatar bboreham commented on July 30, 2024

I took a look at fmt/print.go; it will take first the %v format string; if that panics and it was a null pointer then <nil>; otherwise try to print the panic value; if that panics then it re-throws the panic.

I can get similar behaviour by writing s, ok = fmt.Sprintf("PANIC:%v", panicVal), false in the else clause of safeString. Will try to do a PR with this today.

To what extent do you want the decode side to work with panic values? Perhaps they should obviously fail to decode?

from logfmt.

ChrisHines avatar ChrisHines commented on July 30, 2024

That sounds like a reasonable approach to me. If you do submit a PR please make the same improvements to safeError and safeMarshal as well.

I don't think the decode side needs to do anything special. The decoder only returns []byte data for the keys and values it parses. It doesn't interpret the keys or values in any way and I don't think it should start now.

from logfmt.

bboreham avatar bboreham commented on July 30, 2024

I submitted a PR.

from logfmt.

ChrisHines avatar ChrisHines commented on July 30, 2024

Yes, you did, and I totally lost track of that. My apologies.

I'll try to review that soon. I've also been thinking about another change to improve the way this package handles invalid keys. So I'd like to work on that and probably release it together with your improvements in v0.4.0.

from logfmt.

AlekSi avatar AlekSi commented on July 30, 2024

Was it done? Can this issue be closed?

from logfmt.

ChrisHines avatar ChrisHines commented on July 30, 2024

Yes, it was done. #7 was merged. Don't know why the issue didn't get closed. Thanks for the reminder.

from logfmt.

Related Issues (7)

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.