Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Templating and transform:transform: empty output on error #42

Open
ghost opened this issue Jan 13, 2019 · 8 comments
Open

Templating and transform:transform: empty output on error #42

ghost opened this issue Jan 13, 2019 · 8 comments
Labels

Comments

@ghost
Copy link

ghost commented Jan 13, 2019

@dariok commented on Jul 27, 2018, 4:55 PM UTC:

What is the problem

  • The templating system is used to provide the basic HTML for displaying the result of an XSL transformation:
<html data-template="wdb:getEE">
    <head><title>test</title></head>
    <body>
        <div id="wdbContent" data-template="wdb:getContent" />
    </body>
</html>
  • the function to apply the transformation is basically this:
declare function wdb:getContent($node as node(), $model as map(*)) {
  let $re :=
    try { transform:transform(doc($file), doc($xslt), $params, $attr, "expand-xincludes=no") }
    catch * { <h1>Error</h1> }

  return 
    <div id="wdbContent">
        {$re}
    </div>
};
  • this works fine if there are no errors in the XSLT. However, if there is an error, e.g. calling doc() on a file that does not exist, the output is an empty file:
<!DOCTYPE html>
<html></html>

What did you expect

The output of the given HTML in case of an error.

additional observations:

  1. calling wdb:getContent with exactly the same parameters from eXide produces the expected output in case of an error
  2. everything else inside the catch is processed correctly – I tried to console:log before returning output, which worked, and forwarding handling to another function: there, too, console:log worked but no output was produced
  3. using transform:stream-transform returns the expected output in case of an error (but of course won't work correctly with the templating system)

Describe how to reproduce or add a test

The attached .zip contains an example. Store in /db/apps and call $server/exist/apps/catch/view.html.
If the line with doc() is commented out in the XSLT, you get “Testing”; if it is active, you get an empty response. If you use stream-transform instead of transform in app.xql, you get “error“ if the doc() line is active.
catch.zip

Context information

Please always add the following information

  • eXist-db: 4.3.0
  • Java version: 1.8.0_171
  • Operating system: tested on Ubuntu 16.04 and Windows 10
  • 64 bit
  • How is eXist-db installed? JAR installer
  • Any custom changes in e.g. conf.xml: added an additional root to controller-config.xml on the Ubuntu machine; this is not present under Windows.

This issue was moved by duncdrum from eXist-db/exist#2074.

@ghost ghost added the bug label Jan 13, 2019
@ghost
Copy link
Author

ghost commented Jan 13, 2019

@dizzzz commented on Jul 27, 2018, 8:40 PM UTC:

How is $xslt constructed ?

@ghost
Copy link
Author

ghost commented Jan 13, 2019

@joewiz commented on Jul 27, 2018, 9:56 PM UTC:

I have installed your .zip file in 4.3.1 and see what I would expect when I call http://localhost:8080/exist/apps/catch/view.html and view source - the following HTML and not an "empty file," as you described it:

<!DOCTYPE html>
<html>
    <head>
        <title>test</title>
    </head>
    <body>
        <div id="wdbContent">
            <h1>error</h1>
        </div>
    </body>
</html>

@ghost
Copy link
Author

ghost commented Jan 13, 2019

@dariok commented on Jul 28, 2018, 3:40 PM UTC:

joewiz: Indeed, app.xql in the zip contains "stream-transform()" from my testing (line 19). Change that to just "transform()" and you should observe the behaviour I described.

dizzzz: from an XSLT file stored in the DB via doc(). See app.xql in my zip.

@ghost
Copy link
Author

ghost commented Jan 13, 2019

@dizzzz commented on Jul 28, 2018, 4:35 PM UTC:

dariok the reason I ask.... I typically read mail on a phone/tablet, opening attachments is somewhat cumbersome :-)

@ghost
Copy link
Author

ghost commented Jan 13, 2019

@dariok commented on Jul 28, 2018, 6:29 PM UTC:

dizzzz it is, indeed. I didn't mean to sound rude.

@ghost
Copy link
Author

ghost commented Jan 13, 2019

@joewiz commented on Jul 30, 2018, 3:39 PM UTC:

dariok Thanks for the pointer. I've confirmed your results, and I've tried to reduce the files you've provided into a single, self-contained query that demonstrates the problem. Basically, I took modules/view.xql and brought all of the other aspects of the test into the file. Unfortunately, the query pegs my processor and runs out of memory for me with eXist 4.3.1. My hunch is that the core issue has to do with the way the templating module handles the call out to the transform functions. This is not good, but I'm not really sure how to attack the problem from here.

Does anyone have ideas for how best to proceed?

xquery version "3.1";

declare namespace config = "http://exist-db.org/xquery/apps/config";
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace wdb = "https://github.com/dariok/wdbplus/wdb";

declare option output:method "html5";
declare option output:media-type "text/html";

import module namespace console = "http://exist-db.org/xquery/console";
import module namespace templates = "http://exist-db.org/xquery/templates";

declare variable $doc := 
    <TEI xmlns="http://www.tei-c.org/ns/1.0" xml:id="test">
        <teiHeader/>
        <text>
            <body>
                <div>
                    <p>asdfa</p>
                </div>
            </body>
        </text>
    </TEI>;

declare variable $xslt := 
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="3.0">
        <xsl:template match="/">
            <h1>Testing</h1>
            <xsl:sequence select="doc('bogus')"/>
        </xsl:template>
    </xsl:stylesheet>;

declare function wdb:test($node as node(), $model as map(*), $transform-function as xs:string) {
    let $params :=
        <parameters>
            <param name="exist:stop-on-warn" value="no" />
            <param name="exist:stop-on-error" value="no" />
        </parameters>
    let $attrs := 
        <attributes>
            <attr name="http://saxon.sf.net/feature/recoveryPolicyName" value="recoverSilently" />
        </attributes>
    let $serialization-options := "expand-xincludes=no"
    let $transform-params := 
        [$doc, $xslt, $params, $attrs, $serialization-options]
(:        [$doc, $xslt]:)
    let $transform-arity := array:size($transform-params)
    let $transform := function-lookup(xs:QName("transform:" || $transform-function), $transform-arity)
    let $re :=
        try { 
            apply($transform, $transform-params) 
        }
        catch * { 
            let $t := console:log(
                <report>
                    {$params}
                    {$attrs}
                    <error>{$err:code || ': ' || $err:description}</error>
                    <error>{$err:module || '@' || $err:line-number ||':'||$err:column-number}</error>
                    <additional>{$err:additional}</additional>
                </report>
            )
            return
                <h1>error</h1>
        }
    return 
        <div id="wdbContent">
            {$re}
        </div>
};

let $lookup := 
    function($functionName as xs:string, $arity as xs:int) {
        try {
            function-lookup(xs:QName($functionName), $arity)
        } catch * {
            ()
        }
    }
let $config := map { $templates:CONFIG_STOP_ON_ERROR : true() }
for $transform-function in ("transform", "stream-transform")
let $content := 
    <html>
        <head>
            <title>test</title>
        </head>
        <body>
            <div id="wdbContent" data-template="wdb:getContent" data-template-transform-function="{$transform-function}"/>
        </body>
    </html>
return
    templates:apply($content, $lookup, (), $config)

@ghost
Copy link
Author

ghost commented Jan 13, 2019

@adamretter commented on Jul 30, 2018, 4:24 PM UTC:

joewiz do you think this could be another manifestation of this still open issue with templating: eXist-db/public-xar-repo#21?

@ghost
Copy link
Author

ghost commented Jan 13, 2019

@duncdrum commented on Jan 13, 2019, 10:43 AM UTC:

as this is a problem with the templating module moving this to its code repo.
/move eXist-db/shared-resources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

0 participants