jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Why are errors being supressed?

Open blobaugh opened this issue 12 years ago • 8 comments

In Jetpack_Client_Server we have a line suppressing error messages: @list( $role, $hmac ) = explode( ':', $json->scope );

Any idea why we are doing this?

https://github.com/Automattic/jetpack/blob/master/class.jetpack-client-server.php#L202

blobaugh avatar Jun 11 '14 03:06 blobaugh

Also https://github.com/Automattic/jetpack/blob/master/class.jetpack-client.php#L41

@list( $token_key, $secret ) = explode( '.', $token->secret );

blobaugh avatar Jun 11 '14 03:06 blobaugh

with the second one, I'd wager that it's to make sure we're not inadvertently exposing secrets

samhotchkiss avatar Dec 11 '14 18:12 samhotchkiss

@samhotchkiss is spot on, both cases are what looks like best practice when dealing with sensitive data.

zinigor avatar Dec 01 '15 13:12 zinigor

Would it be better to verify the data before attempting to use it?

I.E:

if( $token->is_valid_secret() ) {
    $parts = explode(  '.', $token->secret );
    if( count( $parts ) == 2 ) {
        list( $token_key, $secret ) = $parts;
    }
    else {
        // handle error here
    }
}

It should never really be a best practice to suppress error messages. If you are doing so that probably means the data being used is not properly verified.

blobaugh avatar Dec 01 '15 14:12 blobaugh

A discussion http://programmers.stackexchange.com/questions/219788/is-error-suppressing-bad-practice

blobaugh avatar Dec 01 '15 14:12 blobaugh

On second thought I admit that you're right. It looks like the only thing that the operator suppresses in this case is a possible Undefined offset notice. I fail to see any possible way that the sensitive data could get echoed if the stfu operator was omitted. On the other hand, this seems like a fairly legitimate use case for the @ because it wouldn't possibly hide any problem. It just makes the code look less bulky, wouldn't you agree?

zinigor avatar Dec 01 '15 15:12 zinigor

I have spent hours chasing around bugs in WP core only to narrow it down to a line with an @ in it (There are a few in the media stuff). Removed that and I could see the issue and resolve it. Errors really never should be hidden, they should be dealt with.

blobaugh avatar Dec 02 '15 14:12 blobaugh

Yes, I agree with you, but in this case it can only hide a notice which we check against immediately after the statement. Do you see a possibility that it will hide something else?

zinigor avatar Dec 03 '15 17:12 zinigor