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

Javascript friendly error messages #2

Open
gotama opened this issue Sep 17, 2020 · 2 comments
Open

Javascript friendly error messages #2

gotama opened this issue Sep 17, 2020 · 2 comments

Comments

@gotama
Copy link

gotama commented Sep 17, 2020

Here is my execution :

var schema = xsd.parseFile(xsdPath);
var validationErrors = schema.validate(manifestItem.output);
validationErrors.forEach(element => {
     console.log('element: ', Object.entries(element));
});

which outputs

element:  [ [ 'domain', 17 ],
  [ 'code', 1871 ],
  [ 'level', 2 ],
  [ 'column', 0 ],
  [ 'line', 65535 ] ]

However when I run the below code I then get my XSD documented error messages.

var schema = xsd.parseFile(xsdPath);
var validationErrors = schema.validate(manifestItem.output);
validationErrors.forEach(element => {
     console.log('element: ',element);
});

which outputs

element:  { Error: Element 'Reporting': This element is not expected. Expected is one of ( DirectReporting, IndirectReporting ).

    at Schema.validate (/obfuscated/node_modules/libxmljs2-xsd/index.js:68:33)
    at /obfuscated/dist/utils/xml.js:37:51
    at new Promise (<anonymous>)
    at Object.orchestrateXML (/obfuscated/dist/utils/xml.js:12:12)
    at Object.<anonymous> (/obfuscated/dist/utils/orchestrate.js:62:52)
    at step (/obfuscated/dist/utils/orchestrate.js:33:23)
    at Object.next (/obfuscated/dist/utils/orchestrate.js:14:53)
    at /obfuscated/dist/utils/orchestrate.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/obfuscated/dist/utils/orchestrate.js:4:12) domain: 17, code: 1871, level: 2, column: 0, line: 65535 }

Is there any workaround to capturing the error message from the validationErrors array?

I have been looking into your source and src/xml_errors.cc builds these error messages, So I was thinking of injecting quotes and commas so that I can work with those messages in javascript.

Let me know, willing to assist but will need some guidance on the C side of things.

UPDATE:

I am using my fork with this output :

element:  { domain: 17,
  code: 1871,
  message: 'Element \'Reporting\': This element is not expected. Expected is one of ( DirectReporting, IndirectReporting ).\n',
  level: 2,
  column: 0,
  line: 65535 }
@gotama
Copy link
Author

gotama commented Sep 17, 2020

@cdegalitt

@cdegalitt
Copy link
Owner

Hi gotama,
First of all, thanks for your interest and contribution.
Sorry for the late answer, I had some off-time.
The way you report errors seems indeed much more appropriate.
I'll be lloking at your PR today.

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