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

Encode XML path and line number in Element and add XML path setter Error. #548

Merged
merged 32 commits into from
May 19, 2021

Conversation

aaronchongth
Copy link
Collaborator

@aaronchongth aaronchongth commented Apr 27, 2021

🎉 New feature

Closes #226 and #510

Summary

This encodes the XML path and line number information into each Element during parsing, and further adds the XML path information into the errors that occur, specifically when readXml is called.

Changes to sdf::Error:

  • Added XmlPath setter and getter to the API
  • Operator << now handles printouts depending on availability of XmlPath, FilePath and LineNumber
    • Error Code #: [XML_PATH]: Msg: ...
    • Error Code #: [XML_PATH:FILE_PATH]: Msg: ...
    • Error Code #: [XML_PATH:FILE_PATH:L#]: Msg: ...
  • Added tests

Changes to sdf::Element:

  • Added API for XmlPath and LineNumber
  • Added unit tests
  • Added integration tests, see test/integration/element_tracing.cc

Changes to Utils:

  • Added XML path support to sdfwarn and sdfdbg
  • Added tests

Changes to parser:

  • Keeps track XML path as it parses the SDF
  • Attributes the XML path to each corresponding SDF Element

Test it

source ws/install/setup.bash
./ws/build/sdformat11/src/UNIT_Error_TEST
./ws/build/sdformat11/src/UNIT_Element_TEST
./ws/build/sdformat11/src/UNIT_Utils_TEST
./ws/build/sdformat11/src/UNIT_parser_TEST
./ws/build/sdformat11/test/integration/INTEGRATION_element_tracing

Testing with ign sdf -k

source ws/install/setup.bash
cd ws/src/sdformat/test/sdf
ign sdf -k bad_syntax_double.sdf

We would expect the top of the error message stack to be,

Error Code 9: [/sdf/world[@name="default"]/model[@name="robot1"]/link[@name="link"]/velocity_decay/linear:/ws/src/sdformat/test/sdf/bad_syntax_double.sdf:L7]: Msg: Error reading element <linear>

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Code check passed (In source directory, run sh tools/code_check.sh)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review
    another open pull request
    to support the maintainers

Note to maintainers: Remember to use Squash-Merge

@github-actions github-actions bot added the 🏢 edifice Ignition Edifice label Apr 27, 2021
@aaronchongth aaronchongth changed the title Aaron/xpath like trace Encode XML path in Element and add trace in parsing errors Apr 27, 2021
@aaronchongth aaronchongth force-pushed the aaron/xpath-like-trace branch from 7a3a599 to 5f437b5 Compare April 27, 2021 07:23
@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2021

Codecov Report

Merging #548 (2064fa1) into sdf11 (25004f0) will decrease coverage by 0.02%.
The diff coverage is 84.04%.

❗ Current head 2064fa1 differs from pull request most recent head acb8dab. Consider uploading reports for the commit acb8dab to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##            sdf11     #548      +/-   ##
==========================================
- Coverage   87.46%   87.43%   -0.03%     
==========================================
  Files          72       72              
  Lines       10349    10421      +72     
==========================================
+ Hits         9052     9112      +60     
- Misses       1297     1309      +12     
Impacted Files Coverage Δ
include/sdf/Element.hh 100.00% <ø> (ø)
include/sdf/Error.hh 60.86% <46.15%> (-14.14%) ⬇️
src/Utils.cc 85.93% <75.00%> (-3.35%) ⬇️
src/parser.cc 83.61% <96.77%> (+0.40%) ⬆️
src/Element.cc 97.54% <100.00%> (+0.04%) ⬆️
src/Error.cc 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 25004f0...acb8dab. Read the comment docs.

@aaronchongth aaronchongth requested a review from azeey April 27, 2021 08:31
@aaronchongth
Copy link
Collaborator Author

@osrf-jenkins run test

Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Nice work on constructing the xml path during parsing. I have a couple of minor comments as well a comment about the ABI test failure that we should address. I did notice that in the description of this PR, you said this closes #226, but that issue is about associating line numbers with sdf::Element. Are you planning to add that to this PR or should that come later in another PR?

include/sdf/Element.hh Show resolved Hide resolved
include/sdf/Error.hh Outdated Show resolved Hide resolved
src/Utils.cc Show resolved Hide resolved
@aaronchongth
Copy link
Collaborator Author

🤦‍♂️ I was working towards #538, and only read #226 bottom few comments. This should be a trivial addition, and can be added in this PR.

@aaronchongth aaronchongth force-pushed the aaron/xpath-like-trace branch from 1ae7778 to 7c04c40 Compare May 3, 2021 15:19
@aaronchongth aaronchongth requested a review from azeey May 3, 2021 17:18
@EricCousineau-TRI
Copy link
Collaborator

FYI @SeanCurtis-TRI

@EricCousineau-TRI
Copy link
Collaborator

@aaronchongth Can you update PR title to explicitly mention line numbers?

@aaronchongth aaronchongth changed the title Encode XML path in Element and add trace in parsing errors Encode XML path and line number in Element and add XML path setter Error. May 7, 2021
@azeey
Copy link
Collaborator

azeey commented May 10, 2021

Per VC, @aaron is updating the parser to set line numbers on sdf::Element objects and adding integration tests.

@azeey azeey requested a review from jennuine May 10, 2021 22:47
Copy link
Collaborator

@jennuine jennuine left a comment

Choose a reason for hiding this comment

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

LGTM! A few minor nit suggestions

include/sdf/Element.hh Outdated Show resolved Hide resolved
include/sdf/Error.hh Show resolved Hide resolved
src/parser.cc Outdated Show resolved Hide resolved
src/parser.cc Outdated Show resolved Hide resolved
@jennuine jennuine linked an issue May 12, 2021 that may be closed by this pull request
@EricCousineau-TRI
Copy link
Collaborator

Can you update PR review to say: Closes #226; Closes #510

I'm not sure if GitHub recognizes / parses and in a functional sense:
https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

Copy link
Collaborator

@EricCousineau-TRI EricCousineau-TRI left a comment

Choose a reason for hiding this comment

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

Awesome! (pending merge/de-conflict and remaining discussion items)

@jennuine
Copy link
Collaborator

Can you update PR review to say: Closes #226; Closes #510

I'm not sure if GitHub recognizes / parses and in a functional sense:
https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword

@EricCousineau-TRI I've linked the issue so it should close both regardless

image

@EricCousineau-TRI
Copy link
Collaborator

Ah, sweet - thanks for clarifying / correcting me!

@aaronchongth
Copy link
Collaborator Author

Apologies for the delay! I had some trouble getting my tests to pass for nested models and just managed to solve it, 1d46a84. Thanks for the reviews so far!

test/integration/element_tracing.cc Outdated Show resolved Hide resolved
test/integration/element_tracing.cc Outdated Show resolved Hide resolved
test/integration/element_tracing.cc Outdated Show resolved Hide resolved
test/integration/element_tracing.cc Outdated Show resolved Hide resolved
@aaronchongth
Copy link
Collaborator Author

@osrf-jenkins run test

@aaronchongth aaronchongth requested a review from jennuine May 17, 2021 02:57
Copy link
Collaborator

@jennuine jennuine 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! The only thing that needs changed is the input for sdf::testing::TestFile. The other comments are just a suggestion and minor question.

test/integration/element_tracing.cc Outdated Show resolved Hide resolved
src/Element_TEST.cc Outdated Show resolved Hide resolved
src/parser.cc Show resolved Hide resolved
Copy link
Collaborator

@azeey azeey left a comment

Choose a reason for hiding this comment

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

Great work!!

…parated arguments in sdf::testing::TestFile

Signed-off-by: Aaron Chong <[email protected]>
Signed-off-by: Aaron Chong <[email protected]>
@aaronchongth
Copy link
Collaborator Author

@osrf-jenkins run test

@aaronchongth aaronchongth requested a review from jennuine May 19, 2021 02:09
@aaronchongth aaronchongth enabled auto-merge (squash) May 19, 2021 02:10
Copy link
Collaborator

@jennuine jennuine left a comment

Choose a reason for hiding this comment

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

LGTM!

@aaronchongth aaronchongth merged commit 7be5c0b into sdf11 May 19, 2021
@aaronchongth aaronchongth deleted the aaron/xpath-like-trace branch May 19, 2021 18:10
azeey added a commit that referenced this pull request Jun 7, 2021
#548 introduced a behavior change on `sdf::Element::FilePath()` for elements loaded from strings. Before that PR, `FilePath()` returned `""` for such elements, but presently, it returns either `data-string` or `<data-string>`. This behavior change could cause failures in downstream applications once released (I know the test `INTEGRATION_save_world` in ign-gazebo will have test failures). 

Signed-off-by: Addisu Z. Taddese <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏢 edifice Ignition Edifice
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should add XPath-like traceability to error messages Associate sdf::Element with line number in file
5 participants