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

[core-xml] Create @azure/core-xml #10307

Merged
merged 5 commits into from
Jul 30, 2020
Merged

[core-xml] Create @azure/core-xml #10307

merged 5 commits into from
Jul 30, 2020

Conversation

xirzec
Copy link
Member

@xirzec xirzec commented Jul 28, 2020

Per the core 2.0 work, this change creates a new package called @azure/core-xml that handles all XML parsing and serialization. This allows generated clients to conditionally pull in the xml2js dependency.

Fixes #8616

xirzec added 2 commits July 27, 2020 17:15
Also fix some tests that weren't ported correctly.
@xirzec xirzec added Client This issue points to a problem in the data-plane of the library. Azure.Core labels Jul 28, 2020
@xirzec xirzec self-assigned this Jul 28, 2020
Copy link
Member

@joheredi joheredi left a comment

Choose a reason for hiding this comment

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

Looks good!


let errorNS = "";
try {
errorNS = parser.parseFromString("INVALID", "text/xml").getElementsByTagName("parsererror")[0]
Copy link
Member

Choose a reason for hiding this comment

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

What's the goal of this block? as I understand, this is trying to figure the error structure, which may vary depending on the browser. Once that is figured out errorNS can be used to check if there are any errors.

Is the reason this is on a block by itself and not inside throwIfError, that we just want to run this (expensive?) figuring out once?

Copy link
Member Author

Choose a reason for hiding this comment

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

Found the PR that introduced this line of code, but seems like it was grabbing the error NS before: https://github.com/Azure/ms-rest-js/pull/211/files

Setting the variable once has been in there since this support was originally added: Azure/ms-rest-js#187

Perhaps @RikkiGibson could enlighten us?

Copy link
Member

Choose a reason for hiding this comment

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

This was the best way I found at the time to discover the namespace used to report XML parsing errors, and therefore find out whether the return value of parseFromString represents a parse failure. I wrote it to discover the errorNS eagerly at startup because it's simple, and you need it every time you try to parse XML anyway. I can't speak to whether e.g. computing it from scratch each time or lazy initializing it is better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the context, I think it's probably fine to do this eagerly, especially now that this code isn't even loaded as part of the main http pipeline and will only show up in services that need XML support.

Copy link
Member

@jeremymeng jeremymeng left a comment

Choose a reason for hiding this comment

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

Looks good!

const response = await getDeserializedResponse({
headers: { "content-type": "application/xml" },
bodyAsText: `<fruit><apples>3</apples></fruit>`
});
assert.exists(response);
assert.isUndefined(response.readableStreamBody);
assert.isUndefined(response.blobBody);
assert.isUndefined(response.parsedBody);
Copy link
Member

Choose a reason for hiding this comment

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

I am curious what leads to this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

When I converted the tests I rewrote some of the assertions... and because many test assertions are similar I was copy pasting a lot. Since the tests were disabled though I didn't notice my copypaste errors. 😅

@xirzec xirzec merged commit 1645bf7 into Azure:master Jul 30, 2020
@xirzec xirzec deleted the createCoreXml branch July 30, 2020 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Core Client This issue points to a problem in the data-plane of the library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core-http] Make XML parse/deserialization a separate optional package
5 participants