• Resolved performancefoundry

    (@performancefoundry)


    Hello,

    There are server errors 5(xx) in Google Search Console for AMP pages. As a workaround, I edited wp-content/plugins/amp/includes/utils/class-amp-dom-utils.php:621, and added try/catch block:

    public static function add_attributes_to_node( $node, $attributes ) {
    foreach ( $attributes as $name => $value ) {
    try {
    $node->setAttribute( $name, $value );
    } catch (Exception $exception) {
    error_log( $exception->getMessage(), E_USER_ERROR );
    }
    }
    }

    it fixed the errors in GSC, there are no related errors in server logs. Can you please advise what I should check on the server or this is something with the plugin?

    Kind regards,
    Dmitriy

    The page I need help with: [log in to see the link]

Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    What were the errors in the server logs?

    Thread Starter performancefoundry

    (@performancefoundry)

    Hi Weston,

    There no errors on server logs. The error is appearing on Google Search Console:
    AMP > Server error (5xx)

    Yours,
    Victor

    Plugin Author Weston Ruter

    (@westonruter)

    A 500 error indicates there should be some error on the server that should be logged. Nothing in a PHP error log?

    Thread Starter performancefoundry

    (@performancefoundry)

    Hi Weston,

    Found this error in logs:

    PHP Fatal error: Uncaught DOMException: Invalid Character Error in /dom25271/wp-content/plugins/amp/includes/utils/class-amp-dom-utils.php:621

    without my code changes.

    Regards,
    Dmitriy

    Plugin Author Weston Ruter

    (@westonruter)

    Interesting! Can you also log out what the $name is that is attempting to be set as the attribute? Apparently this exception is thrown when an attribute begins with an illegal character.

    Thread Starter performancefoundry

    (@performancefoundry)

    Hi Weston,

    I updated the catch block:
    catch (Exception $exception) {
    error_log( $exception->getMessage(), E_USER_ERROR );
    error_log( “LOG name: ” . $name );
    error_log( “LOG value: ” . $value );
    error_log( “LOG EXCEPTION: ” . $exception->getTraceAsString() );
    }

    here are the results:

    [19-Jul-2019 16:05:59 UTC] Invalid Character Error
    [19-Jul-2019 16:05:59 UTC] LOG name: …this
    [19-Jul-2019 16:05:59 UTC] LOG value:

    [19-Jul-2019 16:39:00 UTC] EXCEPTION: #0 /dom25271/wp-content/plugins/amp/includes/utils/class-amp-dom-utils.php(622): DOMElement->setAttribute(‘…this’, ”)
    #1 /dom25271/wp-content/plugins/amp/includes/utils/class-amp-dom-utils.php(583): AMP_DOM_Utils::add_attributes_to_node(Object(DOMElement), Array)
    #2 /dom25271/wp-content/plugins/amp/includes/sanitizers/class-amp-img-sanitizer.php(327): AMP_DOM_Utils::create_node(Object(DOMDocument), ‘amp-img’, Array)
    #3 /dom25271/wp-content/plugins/amp/includes/sanitizers/class-amp-img-sanitizer.php(285): AMP_Img_Sanitizer->adjust_and_replace_node(Object(DOMElement))
    #4 /dom25271/wp-content/plugins/amp/includes/sanitizers/class-amp-img-sanitizer.php(150): AMP_Img_Sanitizer->adjust_and_replace_nodes_in_array_map(Array)
    #5 /dom25271/wp-content/plugins/amp/includes/templates/class-amp-content-sanitizer.php(117): AMP_Img_Sanitizer->sanitize()
    #6 /dom25271/wp-content/plugins/amp/includes/templates/class-amp-content.php(221): AMP_Content_Sanitizer::sanitize_document(Object(DOMDocument), Array, Array)
    #7 /dom25271/wp-content/plugins/amp/includes/templates/class-amp-content.php(140): AMP_Content->sanitize(‘<!– /3508311/_…’)
    #8 /dom25271/wp-content/plugins/amp/includes/templates/class-amp-content.php(87): AMP_Content->transform()
    #9 /dom25271/wp-content/plugins/amp/includes/templates/class-amp-post-template.php(329): AMP_Content->__construct(‘<p>Are you goin…’, Array, Array, Array)
    #10 /dom25271/wp-content/plugins/amp/includes/templates/class-amp-post-template.php(142): AMP_Post_Template->build_post_content()
    #11 /dom25271/wp-content/plugins/amp/amp.php(675): AMP_Post_Template->__construct(Object(WP_Post))
    #12 /dom25271/wp-content/plugins/amp/amp.php(623): amp_render_post(Object(WP_Post))
    #13 /wordpress-4.9.10/wp-includes/class-wp-hook.php(286): amp_render(”)
    #14 /wordpress-4.9.10/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)
    #15 /wordpress-4.9.10/wp-includes/plugin.php(453): WP_Hook->do_action(Array)
    #16 /wordpress-4.9.10/wp-includes/template-loader.php(12): do_action(‘template_redire…’)
    #17 /wordpress-4.9.10/wp-blog-header.php(19): require_once(‘/wordpress-4.9….’)
    #18 /wordpress-4.9.10/index.php(17): require(‘/wordpress-4.9….’)
    #19 {main}

    Regards,
    Dmitriy

    Plugin Author Weston Ruter

    (@westonruter)

    OK, thank you. So for some reason $new_attributes here includes an attribute like ...this:

    https://github.com/ampproject/amp-wp/blob/8f2a1cd69f37bb645d9876b8185cc712d8fe440c/includes/sanitizers/class-amp-img-sanitizer.php#L328

    Can you also please error_log( json_encode( $attributes ) );?

    Also, is the issue still happening on https://www.ourawesomeplanet.com/awesome/2019/06/build-megawatt.html/amp ?

    Can you share the post_content of that post? I’m not seeing ...this in the content anywhere in the non-AMP version.

    Thread Starter performancefoundry

    (@performancefoundry)

    Hi Weston,

    Sure, added
    error_log( json_encode( $new_attributes ) ); to #329 in amp-wp/includes/sanitizers/class-amp-img-sanitizer.php, didn’t find $attributes in that function, here are logs for the post containing “…This” –
    https://www.ourawesomeplanet.com/awesome/2006/12/patapat-viaduct.html/amp

    [22-Jul-2019 07:35:57 UTC] {“width”:500,”height”:354,”src”:”https:\/\/i0.wp.com\/www.ourawesomeplanet.com\/wp-content\/uploads\/2006\/12\/330901026_8584af8bca.jpg?resize=500%2C354&ssl=1″,”class”:”attachment-500×354 size-500×354 amp-wp-enforced-sizes”,”alt”:””,”srcset”:”https:\/\/i0.wp.com\/www.ourawesomeplanet.com\/wp-content\/uploads\/2006\/12\/330901026_8584af8bca.jpg?resize=500%2C354&ssl=1 500w, https:\/\/www.ourawesomeplanet.com\/wp-content\/uploads\/2006\/12\/330901026_8584af8bca-300×212.jpg 300w”,”data-jpibfi-post-excerpt”:”Patapat Viaduct is an elevated concrete highway constructed along winding mountainside in the northernmost section of Ilocos Norte. This viaduct was constructed to solve the problem of landslides in the area which have caused so many vehicular accidents in the past.\n…This will take you through winding mountain roads that have lush vegetation on both sides and occasional views of the sea until you reach the patapat viaduct.\n”,”data-jpibfi-post-url”:”https:\/\/www.ourawesomeplanet.com\/awesome\/2006\/12\/patapat-viaduct.html”,”data-jpibfi-post-title”:”Patapat Viaduct”,”data-jpibfi-src”:”https:\/\/i0.wp.com\/www.ourawesomeplanet.com\/wp-content\/uploads\/2006\/12\/330901026_8584af8bca.jpg?resize=500%2C354&ssl=1″,”data-recalc-dims”:”1″,”layout”:”intrinsic”}
    [22-Jul-2019 07:35:57 UTC] Invalid Character Error
    [22-Jul-2019 07:35:57 UTC] {“alt”:”Infographic: Your Awesome Journey to Pagudpud”,”src”:”https:\/\/i2.wp.com\/www.ourawesomeplanet.com\/wp-content\/uploads\/2006\/12\/pagudpudinfographicbannerad-7.jpg?w=640&ssl=1″,”title”:” data-jpibfi-post-excerpt=”,”patapat”:””,”viaduct”:””,”is”:””,”an”:””,”elevated”:””,”concrete”:””,”highway”:””,”constructed”:””,”along”:””,”winding”:””,”mountainside”:””,”in”:””,”the”:””,”northernmost”:””,”section”:””,”of”:””,”ilocos”:””,”norte.”:””,”this”:””,”was”:””,”to”:””,”solve”:””,”problem”:””,”landslides”:””,”area”:””,”which”:””,”have”:””,”caused”:””,”so”:””,”many”:””,”vehicular”:””,”accidents”:””,”past.”:””,”…this”:””,”will”:””,”take”:””,”you”:””,”through”:””,”mountain”:””,”roads”:””,”that”:””,”lush”:””,”vegetation”:””,”on”:””,”both”:””,”sides”:””,”and”:””,”occasional”:””,”views”:””,”sea”:””,”until”:””,”reach”:””,”viaduct.”:””,”data-jpibfi-post-url”:”https:\/\/www.ourawesomeplanet.com\/awesome\/2006\/12\/patapat-viaduct.html”,”data-jpibfi-post-title”:”Patapat Viaduct”,”data-jpibfi-src”:”https:\/\/i2.wp.com\/www.ourawesomeplanet.com\/wp-content\/uploads\/2006\/12\/pagudpudinfographicbannerad-7.jpg?w=640&ssl=1″,”data-recalc-dims”:”1″,”width”:640,”height”:126,”class”:”amp-wp-enforced-sizes”,”layout”:”intrinsic”}

    Here is the post content:

    <p>Are you going on a road trip to Pagudpud? Download this Infographic Guide before you go…<br>Infographic: Your Awesome Journey to Pagudpud <p></p>
    <p></p>
    <p>Patapat Viaduct is an elevated concrete highway constructed along winding mountainside in the northernmost section of Ilocos Norte. This viaduct was constructed to solve the problem of landslides in the area which have caused so many vehicular accidents in the past. Footed on the rocky seashore just several meters from the mountain side it gives motorists a spectacular view of Pasaleng Bay.</p>
    <p>It is practically deserted except for occasional photo taking from Tourist (like me from years ago). You should take this leisure drive along Patapat and be mesmerized by its awesome beauty…</p>
    <p></p>
    <p><span style=”text-decoration: underline”>How to Get there:</span><br> The Patapat viaduct is about 16+ kilometers from Pagudpud, Ilocos Norte (about an hour away). This is farther north from Blue Lagoon. From Pagudpud, simply head northeast towards Cagayan. This will take you through winding mountain roads that have lush vegetation on both sides and occasional views of the sea until you reach the patapat viaduct.</p>
    <p>Anton</p>

    Regards,
    Dmitriy

    Plugin Author Weston Ruter

    (@westonruter)

    Thank you.

    It appears this is caused by a corrupted img tag:

    <img alt="Infographic: Your Awesome Journey to Pagudpud" src="https://i2.wp.com/www.ourawesomeplanet.com/wp-content/uploads/2006/12/pagudpudinfographicbannerad-7.jpg?w=640&ssl=1" ></a> <p><a title=" data-jpibfi-post-excerpt="Patapat Viaduct  is an elevated concrete highway constructed along winding mountainside in the northernmost section of Ilocos Norte.   This viaduct was constructed to solve the problem of landslides in the area which have caused so many vehicular accidents in the past.
    ...This will take you through winding mountain roads that have lush vegetation on both sides and occasional views of the sea until you reach the patapat viaduct.
    " data-jpibfi-post-url="https://www.ourawesomeplanet.com/awesome/2006/12/patapat-viaduct.html" data-jpibfi-post-title="Patapat Viaduct" data-jpibfi-src="https://i2.wp.com/www.ourawesomeplanet.com/wp-content/uploads/2006/12/pagudpudinfographicbannerad-7.jpg?w=640&ssl=1"  data-recalc-dims="1">
    Plugin Author Weston Ruter

    (@westonruter)

    The forum stripped some of the markup. Here is the code in question: https://gist.github.com/westonruter/4381fb399af5d64c17c6ae270960d99f

    Plugin Author Weston Ruter

    (@westonruter)

    I’m able to reproduce the fatal error with this code, so that’s great. I’ll figure out what is going on.

    Plugin Author Weston Ruter

    (@westonruter)

    @performancefoundry Can you please copy/paste the original post_content into a Gist as well? This will prevent the forum from processing any of the characters.

    Plugin Author Weston Ruter

    (@westonruter)

    I’ve opened a PR which adds the try/catch block and which uses your site’s content in a test case: https://github.com/ampproject/amp-wp/pull/2866

    Plugin Author Weston Ruter

    (@westonruter)

    The underling bad markup should probably be reported as a bug to Jetpack.

    Thread Starter performancefoundry

    (@performancefoundry)

    Hi Weston,

    Thank you very much.

    Dmitriy

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘Server error 5(xx) in Google Search Console’ is closed to new replies.