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

transform function return undefined (5318992) #80

Closed
AviramCloudbeat opened this issue Sep 9, 2019 · 7 comments
Closed

transform function return undefined (5318992) #80

AviramCloudbeat opened this issue Sep 9, 2019 · 7 comments

Comments

@AviramCloudbeat
Copy link

Hello,
I'm trying to use camaro in my project and I encounter a problem that I'm not sure where it is coming from.
this is my code:

    const {transform} = require('camaro');
    const fs = require('fs');
     ....
module.myModule= function () {
       try {
           var xml= fs.readFileSync('c:\myPath\file.xml', 'utf-8');
       } catch (err) {
           console.error(err);
       };

       const sampleTemplet = {
         first: "first element",
         second: "second element"
       };
       (async function() {
          try {
              var result = await transform(xml, sampleTemplet);
          } catch (err) {
              console.error(err);
          };
          console.log(result);
        })();

     };

the result is that transform return undefined error (with number 5318992)
and I can't figure out why because there is no err.message or err.stack - both return undefined as well.

  • camaro version: 4.0.7
  • Node version: 8.14.0
  • Operating system: WIN10
@tuananh
Copy link
Owner

tuananh commented Sep 9, 2019

can you provide the xml input that cause the error?

@AviramCloudbeat
Copy link
Author

Ok, so the issue was this:
In my original 'sampleTemplet' there are a few fields some of them are getting their values from functions, one of them returned 'undefined' and so 'transform()' just sent the message to the console.
It was hard for me to detect since the error message was the most generic as it could be.

@tuananh
Copy link
Owner

tuananh commented Sep 10, 2019

@AviramCloudbeat if you could send the xml and template, maybe i can debug it and have better error handling implemented

@AviramCloudbeat
Copy link
Author

AviramCloudbeat commented Sep 10, 2019

Here is an example file (notice the suffix is txt since github doesn't allow xml files here, so just change the suffix).
Example.txt
It failed in a place I tried to concat two xpath in to one field.
var example = string(//HTTPSamplerProxy[@testname='test1']/stringProp[@name='HTTPSampler.protocol']); const sampleTemplet = { first: example, second: example + example };
so, in this example 'second' will be undefined and so the whole process will fail.

@tuananh
Copy link
Owner

tuananh commented Sep 10, 2019

@AviramCloudbeat second is not a valid xpath expression.

if you want to concat, you can do this

const { transform } = require('camaro')

const xml = require('fs').readFileSync('input.xml', 'utf-8')

;(async function() {
    var example =
        "string(//HTTPSamplerProxy[@testname='test1']/stringProp[@name='HTTPSampler.protocol'])"
    const sampleTemplate = { first: example, second: `concat(${example}, ${example})` }

    const result = await transform(xml, sampleTemplate)

    console.log(JSON.stringify(result, null, 2))
})()

@AviramCloudbeat
Copy link
Author

Yes, I understand it now :(
My problem was to locate where the bug is.

@tuananh
Copy link
Owner

tuananh commented Sep 10, 2019

Yes, I understand it now :(
My problem was to locate where the bug is.

true. i can def. do a better error reporting here.

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

No branches or pull requests

2 participants