[pulseaudio-discuss] [PATCH] pasuspender: Check pa_context_connect() return value.

Tanu Kaskinen tanu.kaskinen at digia.com
Thu Mar 29 23:19:33 PDT 2012


On Thu, 2012-03-29 at 23:14 +0200, David Henningsson wrote:
> On 03/29/2012 11:18 AM, Tanu Kaskinen wrote:
> > ---
> >   src/utils/pasuspender.c |    6 +++++-
> >   1 files changed, 5 insertions(+), 1 deletions(-)
> >
> > diff --git a/src/utils/pasuspender.c b/src/utils/pasuspender.c
> > index 0a60923..ac764d2 100644
> > --- a/src/utils/pasuspender.c
> > +++ b/src/utils/pasuspender.c
> > @@ -292,7 +292,11 @@ int main(int argc, char *argv[]) {
> >       }
> >
> >       pa_context_set_state_callback(context, context_state_callback, NULL);
> > -    pa_context_connect(context, server, PA_CONTEXT_NOAUTOSPAWN, NULL);
> > +
> > +    if (pa_context_connect(context, server, PA_CONTEXT_NOAUTOSPAWN, NULL)<  0) {
> > +        fprintf(stderr, _("pa_context_connect() failed: %s\n"), pa_strerror(pa_context_errno(context)));
> 
> You probably do the i18n for consistency with what's three lines below, 
> but I'd like strings like these to remain untranslated (they are 
> unlikely to be helpful for non-English speaking users).
> 
> Or if you insist on translating them, we should at least create a 
> generic "%s failed: %s\n" string and use everywhere.

Yes, I chose this form for consistency, so I made the string
translatable, but I also made the decision to use the developer-friendly
message. If pa_context_connect() fails, that's actually something that
could justify a more user-friendly message, like "Connecting to
PulseAudio server failed. Is the server running?", but since pacat also
seemed to use the "function() failed" format, I just copied that.

So what to do? If I choose the user-friendly message option, I then have
to think whether I should check for specific error codes and give
different error messages based on that. All I want to do here is to fix
the unchecked return value, so I think I prefer to simply fall back to
the "pa_context_connect() failed" message, without translation as you
suggested.

If there are no further opinions, I'll push a non-translated version of
this patch soon.

-- 
Tanu



More information about the pulseaudio-discuss mailing list