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

Making xmlError js friendly. #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules/
/build/
.vscode
170 changes: 73 additions & 97 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "libxmljs2-xsd",
"version": "0.26.3",
"version": "1.27.1",
"description": "XSD validator based on libxmljs2",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -39,7 +39,7 @@
"license": "MIT",
"dependencies": {
"bindings": "^1.2.1",
"libxmljs2": "^0.26.0",
"libxmljs2": "^0.26.1",
"nan": "^2.14.1"
},
"devDependencies": {
Expand Down
6 changes: 2 additions & 4 deletions src/xml_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ void set_numeric_field(Local<Object> obj, const char *name, const int value) {
Local<Value> BuildSyntaxError(xmlError *error) {
Nan::EscapableHandleScope scope;

Local<Value> err =
Exception::Error(Nan::New<String>(error->message).ToLocalChecked());
Local<Object> out = Local<Object>::Cast(err);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I removed this, because casting err to the out object is the reason the formatting for JS broke.

A stack trace doesn't fit nicely into a key value JS object. Im trying to think of a more elegant way to append a stack trace. Will update if I come up with anything.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also error->message might not be a stack trace, as im using that as xsd validation error messages.

Local<Object> out = Nan::New<Object>();

set_numeric_field(out, "domain", error->domain);
set_numeric_field(out, "code", error->code);
Expand All @@ -44,5 +42,5 @@ Local<Value> BuildSyntaxError(xmlError *error) {
set_numeric_field(out, "int1", error->int1);
}

return scope.Escape(err);
return scope.Escape(out);
}