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

Don't crash on incomplete vocabulary configuration #1409

Merged
merged 2 commits into from
Mar 23, 2023

Conversation

nichtich
Copy link
Contributor

If a vocabulary configuration has no void:uriSpace, an error message should be shown instead of crashing. This closes #1408.

If a vocabulary configuration has no `void:uriSpace`, an error message
should be shown instead of crashing. This fixes NatLibFi#1408.
@sonarcloud
Copy link

sonarcloud bot commented Feb 20, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link

codecov bot commented Feb 20, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (a22b389) 69.55% compared to head (a789a77) 69.57%.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1409      +/-   ##
============================================
+ Coverage     69.55%   69.57%   +0.01%     
- Complexity     1650     1651       +1     
============================================
  Files            32       32              
  Lines          4257     4259       +2     
============================================
+ Hits           2961     2963       +2     
  Misses         1296     1296              
Impacted Files Coverage Δ
model/Vocabulary.php 85.66% <100.00%> (+0.10%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@osma
Copy link
Member

osma commented Mar 10, 2023

Thanks for the PR!

I wonder what the implications are for omitting uriSpace. I mean, this PR obviously fixes the immediate crash, but the setting is used in several places in both PHP and JS code, so just returning a null value may have some consequences. Have you tried this in practice?

@nichtich
Copy link
Contributor Author

Without uriSpace, basic vocabulary information is shown but not concepts, so it's better than a white screen. One may further think about how do handle incompletely configured vocabularies but for our instance this fix is enough.

@osma
Copy link
Member

osma commented Mar 23, 2023

I tested this PR locally on a vocabulary with a commented out uriSpace setting. As expected it fixes the immediate PHP crash. But there are consequences on the JS side. When clicking a concept from the hierarchy, this error is shown on the JS console:

Uncaught SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
    makeCallbacks http://localhost/Skosmos/resource/js/scripts.js:363
    complete http://localhost/Skosmos/resource/js/scripts.js:555
    jQuery 6
    loadMappingProperties http://localhost/Skosmos/resource/js/scripts.js:497
    ajaxConceptMapping http://localhost/Skosmos/resource/js/docready.js:263
    success http://localhost/Skosmos/resource/js/docready.js:320
    jQuery 6
    <anonymous> http://localhost/Skosmos/resource/js/docready.js:308
    jQuery 8
    <anonymous> http://localhost/Skosmos/resource/js/docready.js:126
    jQuery 13

I traced this to some fragile JS code that is run when doing partial page loads. It can be fixed by this patch to view/scripts.twig that ensures that the var uriSpace declaration is always there:

diff --git a/view/scripts.twig b/view/scripts.twig
index 2b77ae9f..725444ec 100644
--- a/view/scripts.twig
+++ b/view/scripts.twig
@@ -31,6 +31,8 @@ var prefLabels = [{"lang": "{{ search_results|first.label.lang }}","label": "{{
 {% endif %}
 {% if request.vocab and request.vocab.uriSpace %}
 var uriSpace = "{{ request.vocab.uriSpace }}";
+{% else %}
+var uriSpace = null;
 {% endif %}
 var showNotation = {% if request.vocab and not request.vocab.config.showNotation %}false{% else %}true{% endif %};
 {% if request.vocab  %}

I will try to add this fix to this PR branch before merging it. It seems that the nichtich branch allows this. (BTW, it would be nice to have a more descriptive name for the PR branch - we generally use issueXXXX-some-short-description for branches that try to fix an already reported issue).

@sonarcloud
Copy link

sonarcloud bot commented Mar 23, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@osma osma added this to the 2.17 milestone Mar 23, 2023
@osma osma added the bug label Mar 23, 2023
@osma osma self-assigned this Mar 23, 2023
@osma
Copy link
Member

osma commented Mar 23, 2023

Thank you for the PR @nichtich ! This will go into the master branch and eventually the 2.17 release. But I will also cherry-pick the commits for the v2.16-maintenance branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done (verified in test.dev.finto.fi, set Milestone 3.0 for both issue & PR)
Development

Successfully merging this pull request may close these issues.

Skosmos crashes silently on missing void:uriSpace
2 participants