[RFC] errors.Newf(format string, a ...interface{}) error

277 views
Skip to first unread message

Carlos Cobo

unread,
Aug 29, 2013, 9:02:48 PM8/29/13
to golan...@googlegroups.com
Hello dear gophers,

I would like to propose an addition to the lonely errors package as stated by the subject of this thread.

What should it do? Equivalent to errors.New(fmt.Sprintf(...)).

As of Go 1.1.2 there are 91 potential uses for this new function according to:
grep --color=auto -iRnH 'Error() string' * | wc -l

What do you think?


-Carlos

jimmy frasche

unread,
Aug 29, 2013, 9:04:35 PM8/29/13
to Carlos Cobo, golang-nuts
you want fmt.Errorf

Carlos Cobo

unread,
Aug 29, 2013, 9:07:45 PM8/29/13
to golan...@googlegroups.com, Carlos Cobo
GOD
DAMN
IT.

That was crazy fast, I'm ashamed of this but I have to admit I wouldn't look for it on fmt, maybe it's just me.

On Friday, August 30, 2013 3:04:35 AM UTC+2, soapboxcicero wrote:
you want fmt.Errorf

Jesse McNelis

unread,
Aug 29, 2013, 9:07:35 PM8/29/13
to Carlos Cobo, golang-nuts

Kevin Gillette

unread,
Aug 29, 2013, 9:12:35 PM8/29/13
to golan...@googlegroups.com, Carlos Cobo
I knew about errors.New for months before I found out about fmt.Errorf.

jimmy frasche

unread,
Aug 29, 2013, 9:12:24 PM8/29/13
to Carlos Cobo, golang-nuts
It's somewhat surprising. The errors package is used a lot and
including Errorf in errors would mean pulling fmt and its dependencies
into pretty much everything.

In the documentation of the errors package the second example is for
Errorf, but then again the example in the package overview uses
fmt.Sprintf with errors.New. The documentation could be clearer, maybe
mentioning fmt.Errorf in the package overview. You could file an issue
to clarify the documentation.

Jesse McNelis

unread,
Aug 29, 2013, 9:12:41 PM8/29/13
to Carlos Cobo, golang-nuts
On Fri, Aug 30, 2013 at 11:07 AM, Carlos Cobo <toqu...@gmail.com> wrote:
GOD
DAMN
IT.

That was crazy fast, I'm ashamed of this but I have to admit I wouldn't look for it on fmt, maybe it's just me.

That's why there is an example in the errors package.
 
--
=====================
http://jessta.id.au

Carlos Cobo

unread,
Aug 29, 2013, 9:28:31 PM8/29/13
to golan...@googlegroups.com, Carlos Cobo
Woops, I sent message only to you cause I replied over the phone.

Copy-pasting here:
That's a nice explanation of why it's how it is now.
The clarification as Jeese said is there it was my fault not seeing it (not checking docs, instead let gocode pop out suggestions for me).
Again, ashamed.
I love how well they did think about the language, they should make an even lower level cousin and conquer the world.

Rodrigo Moraes

unread,
Aug 29, 2013, 10:46:07 PM8/29/13
to Carlos Cobo, golang-nuts

I would like to see a MultiError type in the errors package, which is some boilerplate people write over and over: 

type MultiError []Error

func (e MultiError) Error() string {
    // ...
}

See: https://code.google.com/p/appengine-go/source/browse/appengine/errors.go#33

-- rodrigo

Kyle Lemons

unread,
Aug 30, 2013, 1:08:18 AM8/30/13
to jimmy frasche, Carlos Cobo, golang-nuts
On Thu, Aug 29, 2013 at 6:12 PM, jimmy frasche <soapbo...@gmail.com> wrote:
It's somewhat surprising. The errors package is used a lot and
including Errorf in errors would mean pulling fmt and its dependencies
into pretty much everything.

It's the opposite, actually; if you pull in errors, you don't need to pull in fmt; if errors had Errorf, then errors would always pull in fmt.  As it stands, now you only pull in formatted i/o if you use it :).
 
In the documentation of the errors package the second example is for
Errorf, but then again the example in the package overview uses
fmt.Sprintf with errors.New. The documentation could be clearer, maybe
mentioning fmt.Errorf in the package overview. You could file an issue
to clarify the documentation.

--
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...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

aro...@gmail.com

unread,
Aug 30, 2013, 3:36:32 AM8/30/13
to golan...@googlegroups.com, Carlos Cobo
Reply all
Reply to author
Forward
0 new messages