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

Profile resolver error handling #1549

Closed
wants to merge 0 commits into from

Conversation

galtm
Copy link
Contributor

@galtm galtm commented Nov 13, 2022

Committer Notes

This PR enhances the XSLT profile resolver so that (a) if there is a fatal error, the resolver reports one such error and does not produce a final output, and (b) if there are no fatal errors, the resolver reports all nonfatal error and warning messages when producing the final output document.

  1. Separate before/after from starting/ending in modify phase because they are no longer synonyms
  2. Enhance message-handler.xsl for pipeline usage and testability
  3. Adapt XSLT to message handler returning PI
  4. Enable saving intermediate XML files for debugging purposes
  5. Add sample document for nonfatal errors/warnings

Included bug fixes for bugs I noticed during this work:

  • Enable param to have insertions before/after AND have param set
  • Fix merge phase bug where descendant controls weren't being flattened

All Submissions:

By submitting a pull request, you are agreeing to provide this contribution under the CC0 1.0 Universal public domain dedication.

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you included examples of how to use your new feature(s)?
  • Have you updated all OSCAL website and readme documentation affected by the changes you made? Changes to the OSCAL website can be made in the docs/content directory of your branch.

Testing Done

While qualifying these changes, I ran commands like the following in a Windows shell, from the resolver-pipeline directory.

java -cp C:\SaxonHE10-8J\saxon-he-10.8.jar net.sf.saxon.Transform -t -s:..\..\..\specifications\profile-resolution\profile-resolution-examples\broken_profile.xml -xsl:oscal-profile-RESOLVE.xsl -o:myoutput.xml

The command window output shows the error message as in the following example.

Terminating Error: Document not acquired: missing_profile.xml resolved as file:/C:/github/oscal/OSCAL/src/specifications/profile-resolution/profile-resolution-examples/missing_profile.xml (as OSCAL XML)
Error at xsl:message on line 150 column 60 of oscal-profile-RESOLVE.xsl:
  XTMM9000  Processing terminated by xsl:message at line 150 in oscal-profile-RESOLVE.xsl
     invoked by xsl:for-each at file:/C:/github/oscal/OSCAL/src/utils/util/resolver-pipeline/oscal-profile-RESOLVE.xsl#149
  In template rule with match="opr:terminate-if-severe-errors" on line 144 of oscal-profile-RESOLVE.xsl
     invoked by xsl:apply-templates at file:/C:/github/oscal/OSCAL/src/utils/util/resolver-pipeline/oscal-profile-RESOLVE.xsl#81
     invoked by xsl:iterate at file:/C:/github/oscal/OSCAL/src/utils/util/resolver-pipeline/oscal-profile-RESOLVE.xsl#77
  In template rule with match="/" on line 69 of oscal-profile-RESOLVE.xsl
Processing terminated by xsl:message at line 150 in oscal-profile-RESOLVE.xsl

In another command-line example with nonfatal errors and warnings, the command window output includes the messages near the end:

Warning: Found 2 elements of type <title>. Only the last will be present in result.
Error: Element of type <back-matter> is not valid inside <control> and will not be present in result.
Warning: set-parameter with param-id="a3_prm1" does not match any param id.
Execution time: 644.6529ms
Memory used: 30Mb

Behavior when using Oxygen transformation scenario: Messages appear in the Messages pane. (In the case of fatal error messages, this pane is underneath the Transformation problems pane.)

Copy link
Contributor Author

@galtm galtm left a comment

Choose a reason for hiding this comment

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

Some annotations to make large diffs more manageable

src/utils/util/resolver-pipeline/message-handler.xsl Outdated Show resolved Hide resolved
src/utils/util/resolver-pipeline/oscal-profile-RESOLVE.xsl Outdated Show resolved Hide resolved
src/utils/util/resolver-pipeline/oscal-profile-RESOLVE.xsl Outdated Show resolved Hide resolved
src/utils/util/resolver-pipeline/oscal-profile-RESOLVE.xsl Outdated Show resolved Hide resolved
Comment on lines 57 to 79
<xsl:template match="catalog[merge/as-is=$true-content]" priority="12" as="element(catalog)">
<!-- Template return value is element(catalog) possibly preceded by a
processing instruction from detect-multiple-structuring-directives. -->
<xsl:template match="catalog[merge/as-is=$true-content]" priority="12" as="item()+">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Example of the kind of data type change required by Item 3 in PR description.

@galtm
Copy link
Contributor Author

galtm commented Nov 13, 2022

@david-waltermire-nist , @wendellpiez : I'm a little concerned about potential conflicts between this PR and #1424 (which I haven't looked at in detail, but I see some of the same files). If I can help make file merges go more smoothly, let me know.

wendellpiez
wendellpiez previously approved these changes Dec 7, 2022
Copy link
Contributor

@wendellpiez wendellpiez left a comment

Choose a reason for hiding this comment

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

Thanks again for all the tremendous work here, it's looking nice!

@aj-stein-nist
Copy link
Contributor

Hi @galtm, thanks for submitting yet another excellent PR. We had to rebase develop and that leads to the "This branch has conflicts that must be resolved" conflicts below. I can help you with that, please let me know if and when you need that help. Thanks.

@galtm
Copy link
Contributor Author

galtm commented Jan 12, 2023

Hi, @aj-stein-nist . Thanks for notifying me and offering to help. The files listed are files that I haven't touched, which should make it easier. I'll try to look into this today or tomorrow and I'll keep you posted.

@galtm
Copy link
Contributor Author

galtm commented Jan 13, 2023

@aj-stein-nist : I resolved the merge conflicts. If anything doesn't look right to you, let me know. Thanks.

@wendellpiez : When I did the force-push, GitHub "dismissed" your earlier code review.

@david-waltermire
Copy link
Contributor

@david-waltermire-nist , @wendellpiez : I'm a little concerned about potential conflicts between this PR and #1424 (which I haven't looked at in detail, but I see some of the same files). If I can help make file merges go more smoothly, let me know.

We should figure out how to move forward with this given your concerns.

Would it make sense to move this PR against #1424?

@galtm
Copy link
Contributor Author

galtm commented Jan 19, 2023

Would it make sense to move this PR against #1424?

Would that mean that this PR can't be merged until #1424 is merged? #1424 is a draft and has been open for about 5 months. To keep things moving, can you merge this change onto develop and rebase #1424 on top?

If I could understand the essence of what is changing with #1424 I could look into whether there are any potential merge conflicts with this PR that might be hard to resolve. However, I don't know how to make sense of the 56 commits that probably resulted from rebasing the develop branch. Which commits should I be looking at in that list?

@david-waltermire david-waltermire added the Profile Resolution Issues relating to profile resolution. label Jan 23, 2023
@david-waltermire
Copy link
Contributor

Would it make sense to move this PR against #1424?

Would that mean that this PR can't be merged until #1424 is merged? #1424 is a draft and has been open for about 5 months. To keep things moving, can you merge this change onto develop and rebase #1424 on top?

If I could understand the essence of what is changing with #1424 I could look into whether there are any potential merge conflicts with this PR that might be hard to resolve. However, I don't know how to make sense of the 56 commits that probably resulted from rebasing the develop branch. Which commits should I be looking at in that list?

I think your suggestion of merging this now and rebasing #1424 on top is a good path.

wendellpiez
wendellpiez previously approved these changes Jan 23, 2023
Copy link
Contributor

@wendellpiez wendellpiez left a comment

Choose a reason for hiding this comment

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

Beautiful work here, and much interesting progress.

@galtm
Copy link
Contributor Author

galtm commented Feb 4, 2023

2/4/23: Pushed 2 commits to fix minor issues I noticed while working on something unrelated.

@galtm
Copy link
Contributor Author

galtm commented Mar 10, 2023

3/9/23: Manually resolved merge conflicts now that #1685 has been merged into develop branch.

@aj-stein-nist aj-stein-nist self-requested a review as a code owner July 11, 2023 12:40
</x:expect>
<x:expect label="The target control does not appear" test="empty($x:result//*[@id='a1-stmt'])"/>
</x:scenario>
<x:scenario label="Explicit binding to a param that needs to be set *and* have new params inserted">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wendellpiez : Does this test scenario cover the situation in issue #1859?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so ... what is being described is wanting to add a new prop to an existing param, but not being able to use alter. Apparently alter is a no-op against params. set-param is the available workaround (it can be used to add new content). But the spec does not say that you can't target param elements using alter/add, so that should also work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. You're right, this scenario isn't the same as what the issue is about. But I think the XSLT in this PR fixes the issue. If I create a similar test scenario with

<alter control-id="a1">
    <add position="starting" by-id="a1_prm1">
        <prop ns="https://fedramp.gov/ns/oscal" name="param-label" value="AC-1(a)"/>
    </add>
</alter>

then I can see that the new prop gets added at the beginning of the existing param, like this:

<param id="a1_prm1">
    <prop ns="https://fedramp.gov/ns/oscal" name="param-label" value="AC-1(a)"/>
    <label>A1 Parameter 1</label>
    <constraint>at least every 3 years</constraint>
</param>

Should I add the new test scenario?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure! I guess I was not looking closely enough, or not looking at the current code, to see that this should actually work.

If it actually works, so much the better, we only need to be able to show that it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed commit 5d3b9b3 to this PR branch, to provide a test of the situation in #1859. I also tweaked the label of the other test scenario to distinguish the two scenarios from each other more.

@aj-stein-nist aj-stein-nist changed the title Profile resolver error handling [DONOTMERGE] Profile resolver error handling Sep 27, 2023
@aj-stein-nist
Copy link
Contributor

Well, this is frustrating, I have a backup of this branch before rebase, but I am unable to push to your fork @galtm after "aligning" it to develop (with --strategy=ours to save time) but that did not work.

@galtm, can you check out my branch and push it here to reopen? Shorthand instructions below. Thanks. I was trying to spare you the effort of rebasing this yourself.

# Just for alignment on what remotes I mean
git add remote me git@github.com:galtm/OSCAL.git
git add remote aj git@github.com:aj-stein-nist/OSCAL.git
git fetch all
git checkout --track aj/profiler-error-handling-backup
git push me profiler-error-handling-backup:profiler-error-handling -f

Then you should be able to continue on this PR by ID and receive the credit you deserve. Apologies.

@aj-stein-nist aj-stein-nist mentioned this pull request Sep 28, 2023
9 tasks
@galtm
Copy link
Contributor Author

galtm commented Sep 28, 2023

@aj-stein-nist : I tried to follow your shorthand instructions, but I'm not sure if things worked. Here's the output I got from the push:

$ git push origin profiler-error-handling-backup:profiler-error-handling -f
Enumerating objects: 192, done.
Counting objects: 100% (157/157), done.
Delta compression using up to 8 threads
Compressing objects: 100% (81/81), done.
Writing objects: 100% (112/112), 53.52 KiB | 3.57 MiB/s, done.
Total 112 (delta 84), reused 44 (delta 26), pack-reused 0
remote: Resolving deltas: 100% (84/84), completed with 33 local objects.
To https://github.com/galtm/OSCAL.git
 + 0825b9fc4...5d3b9b302 profiler-error-handling-backup -> profiler-error-handling (forced update)

where origin is as follows (the git@github.com:... syntax didn't work for me when I tried to fetch).

origin  https://github.com/galtm/OSCAL.git (fetch)
origin  https://github.com/galtm/OSCAL.git (push)

Despite the lack of error messages, this PR page still says 0 commits. I thought it would add commits to this PR but they'd be aligned with where develop stands now. Did I misunderstand the result of those commands or what I'm supposed to do next?

It may be simpler for me to sync my develop branch, create a fresh branch from that, do a file-merge (outside Git) of the profile resolver file contents based on the files in a backup branch, and try again to push to the branch of this PR. I started doing that but still need to check the results. I'll be busy for a few hours, but I will come back to this in the late afternoon.

@aj-stein-nist
Copy link
Contributor

Well now I am confused because it does look like you "put it back" to the way it was from my backup if I simulate what a PR would like, so now I am scratching my head.

develop...galtm:OSCAL:profiler-error-handling

@aj-stein-nist aj-stein-nist changed the title [DONOTMERGE] Profile resolver error handling Profile resolver error handling Sep 28, 2023
@aj-stein-nist
Copy link
Contributor

It seems now I can reopen?

@aj-stein-nist
Copy link
Contributor

aj-stein-nist commented Sep 28, 2023

Well ti seems even though I have reopened it and commented it seems to ignore the state of the branch on your end even though it looks just as before (155 commits off of develop and the same series of changes I worked through last night). I guess I will try and reopen a new PR, @galtm. I sincerely apologize this mishap is frustrating and embarrassing on my end!

@aj-stein-nist aj-stein-nist mentioned this pull request Sep 28, 2023
9 tasks
@aj-stein-nist
Copy link
Contributor

Apologize, I guess we move #1943 in favor of this PR, I cannot even reopen it. Apologies and sincere thanks, @galtm.

galtm added a commit to galtm/OSCAL that referenced this pull request Sep 28, 2023
@galtm galtm mentioned this pull request Sep 28, 2023
7 tasks
@galtm
Copy link
Contributor Author

galtm commented Sep 28, 2023

I'm confused, too, because I thought rebasing against develop would mean that the list of commits and changed files would look like my work in isolation rather than the long list that I see in #1943.

I also realized that the code needs a few tweaks because the profiler resolver code is less deep in the directory hierarchy than it used to be.

I created #1944 with what I think is the right code, on top of the develop branch. Does it look right from your perspective?

@aj-stein-nist
Copy link
Contributor

I'm confused, too, because I thought rebasing against develop would mean that the list of commits and changed files would look like my work in isolation rather than the long list that I see in #1943.

I also realized that the code needs a few tweaks because the profiler resolver code is less deep in the directory hierarchy than it used to be.

I created #1944 with what I think is the right code, on top of the develop branch. Does it look right from your perspective?

I am looking at in a few minutes, we just wrapped our sprint review, thanks again @galtm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Profile Resolution Issues relating to profile resolution.
Projects
Status: Under Review
Development

Successfully merging this pull request may close these issues.

4 participants