Skip to content

Run XML through a linter before passing it to Solr #433

Closed

Description

@waldoj

Solr has absolutely no tolerance for XML errors. So we need a method of linting all of the XML and creating a blacklist of files with errors. We already have the functionality in ParserController::index_laws() to apply a blacklist, and it works fine, we just need to generate that blacklist.

I'm thinking xmllint. Specifically, xmllint --noout *. Its output isn't totally pure, but I think we can use a regex to extract all of the XML filenames from that list, unique it, and then use that as our blacklist. But I think we'll need to see how common xmllint is. It looks like it's easily installed (e.g., sudo apt-get install libxml2-utils on Ubuntu), but that's going to require more research.

Activity

  1. NSkelsey commented on Oct 4, 2013

    @NSkelsey
    Member

    Have you committed your local changes of OSC solr_home into UI? I am running into XML errors when I use it as the solr_home.

  2. waldoj commented on Oct 4, 2013

    @waldoj
    MemberAuthor

    I sure have. Are the XML errors when you're importing Virginia's XML files?

  3. NSkelsey commented on Oct 4, 2013

    @NSkelsey
    Member

    Ah, no. Just on startup

  4. waldoj commented on Oct 4, 2013

    @waldoj
    MemberAuthor

    Whoa. Mind pasting in the error you're getting?

  5. NSkelsey commented on Oct 4, 2013

    @NSkelsey
    Member

    Its a big one. I think it has to do with what I named my core in solr.xml

    552 [coreLoadExecutor-3-thread-1] ERROR org.apache.solr.core.CoreContainer ? Unable to create core: statedecoded
    org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] fieldType "statedec_facet_hierarchical": Plugin init failure for [schema.xml] analyzer/tokenizer: Error instantiating class: 'org.apache.lucene.analysis.core.KeywordTokenizerFactory'
    at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
    at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:467)
    at org.apache.solr.schema.IndexSchema.(IndexSchema.java:164)
    at org.apache.solr.schema.IndexSchemaFactory.create(IndexSchemaFactory.java:55)
    at org.apache.solr.schema.IndexSchemaFactory.buildIndexSchema(IndexSchemaFactory.java:69)
    at org.apache.solr.core.CoreContainer.createFromLocal(CoreContainer.java:619)
    at org.apache.solr.core.CoreContainer.create(CoreContainer.java:657)
    at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:364)
    at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:356)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:679)
    Caused by: org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] analyzer/tokenizer: Error instantiating class: 'org.apache.lucene.analysis.core.KeywordTokenizerFactory'
    at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
    at org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:362)
    at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:86)
    at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)
    at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
    ... 16 more
    Caused by: org.apache.solr.common.SolrException: Error instantiating class: 'org.apache.lucene.analysis.core.KeywordTokenizerFactory'
    at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:556)
    at org.apache.solr.schema.FieldTypePluginLoader$2.create(FieldTypePluginLoader.java:342)
    at org.apache.solr.schema.FieldTypePluginLoader$2.create(FieldTypePluginLoader.java:335)
    at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
    ... 20 more
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:553)
    ... 23 more
    Caused by: java.lang.IllegalArgumentException: Unknown parameters: {delimiter=~}
    at org.apache.lucene.analysis.core.KeywordTokenizerFactory.(KeywordTokenizerFactory.java:41)
    ... 28 more

  6. waldoj commented on Oct 4, 2013

    @waldoj
    MemberAuthor

    I've definitely done something wrong. I've seen this error, when we were working on this the other day. I'll have this solved in a few minutes—I have to look at my notes.

  7. waldoj commented on Oct 4, 2013

    @waldoj
    MemberAuthor

    Got it! I never committed three crucial directories. I'm on a train, with an increasingly bad 3G connection, but let's see if I can commit these changes.

  8. waldoj commented on Oct 4, 2013

    @waldoj
    MemberAuthor

    Still uploading! If it doesn't work in the next few minutes, If you don't see a commit soon, then it'll be a couple of hours, until I can get home and back to an internet connection. :-/ Once you can sync those changes, though, everything will work great. Thanks for pointing this out!

  9. waldoj commented on Oct 5, 2013

    @waldoj
    MemberAuthor

    Good Lord, that took forever. All set.

  10. NSkelsey commented on Oct 5, 2013

    @NSkelsey
    Member

    The commit solved my issue, thanks!

  11. waldoj commented on Nov 1, 2013

    @waldoj
    MemberAuthor

    Returning to the issue, I think we'll want to use this:

    find . -type f -print0 |xargs -0 xmllint --noout
    
  12. waldoj commented on Nov 5, 2013

    @waldoj
    MemberAuthor

    I fought and fought with this:

    exec('xmllint --noout ' . $path . '*', $output, $status);

    It kept returning a non-zero status, and I had no idea why. It was really frustrating. It turns out that was wholly accurate—xmllint was reporting that it had found some errors within XML, which is, in fact, a non-zero result. :-/

  13. waldoj commented on Nov 5, 2013

    @waldoj
    MemberAuthor

    OK, problem solved. Unfortunately, this requires libxml2-utils, which is yet another prerequisite. I've create a new issue to add a test for it in v1.0, and I'll add that requirement to the documentation now.

  14. 16 remaining items

  15. waldoj commented on Nov 8, 2013

    @waldoj
    MemberAuthor

    Ah, got it. I forgot about the subfolders. I wasn't having any luck using find to generate that list, which would of course have searched recursively, for reasons I never did figure out. But I'll try again—now that I'm directing output to a file, that might work OK.

  16. waldoj commented on Nov 11, 2013

    @waldoj
    MemberAuthor

    I'm going to pipe this through find and xargs and see if that fixes things. If so, I'll include this fix in today's v0.8 release.

  17. waldoj commented on Nov 11, 2013

    @waldoj
    MemberAuthor

    Nope. I tried all of these:

    find . -type f -exec xmllint --noout '{}' + > xmllint.txt
    find . -type f -print0 |xargs -0 xmllint --noout --output xmllint.txt
    find . -type f -print0 |xargs -0 xmllint --noout > xmllint.txt 2&1

    None of them piped any data to xmllint.txt, but instead sent it right to display. I have no idea of why. Will revisit this for v1.0. In the meantime, the linter runs only if LAW_LONG_URLS is disabled. If it's enabled, then an error is thrown, to alert the user that the XML is being trusted.

  18. waldoj commented on Apr 18, 2014

    @waldoj
    MemberAuthor

    This is infuriating and mystifying. Even this doesn't work:

    ob_start();
    exec('xmllint --noout *');
    $output = ob_get_clean();

    The data is sent directly to the browser, rather than being intercepted and stored within $output. How? I don't know. Witchcraft?

    It's appalling how much time I've spent on this.

  19. waldoj commented on Dec 22, 2014

    @waldoj
    MemberAuthor

    After an hour banging away at this, I've figured out the problem. It turns out that this is very much the fault of xmllint. It's writing to stderr, not stdout. xmllint finding errors in XML is not an error, it's a feature. It should be writing to stderr if there's an error with xmllint, not with XML. Anyway, that's why nothing can ever be captured.

    The standard solutions to this are ghastly (involving proc_open() and stream_get_contents()), so I'm inclined to just append 2>&1 >/dev/null to the end of the command (redirecting stderr to stdout), and capture that output.

  20. waldoj commented on Dec 22, 2014

    @waldoj
    MemberAuthor

    It's too late for me to start adding that code in just now. So, Future Me, here's what you need:

    exec('cd downloads/current/code-xml/; find . -type f -exec xmllint --noout \'{}\' + 2>&1 >/dev/null', $output);
    $output = implode("\n", $output);
  21. krusynth commented on Dec 22, 2014

    @krusynth
    Member

    Oh I also figured out how to handle nested folders with XML lint; I'll post that when I get back.

    On Dec 21, 2014, at 9:12 PM, Waldo Jaquith [email protected] wrote:

    It's too late for me to start adding that code in just now. So, Future Me, here's what you need:

    exec('cd downloads/current/code-xml/; find . -type f -exec xmllint --noout '{}' + 2>&1 >/dev/null', $output);
    $output = implode("\n", $output);
    —
    Reply to this email directly or view it on GitHub.

  22. krusynth commented on May 2, 2015

    @krusynth
    Member

    We're no longer feeding XML into Solr so this doesn't matter anyway. I'll keep this open if we want to post-process our XML generation (in which case we should rename the ticket), but otherwise this is no longer an issue.

  23. waldoj commented on May 2, 2015

    @waldoj
    MemberAuthor

    Well, since Solr is still an option for folks, and since Solr seizes up and dies if there's a single XML error, I think it's best to retain. After I put hours and hours into work into this damned problem, I'll just add in those two lines, test it, and be done with it. :)

  24. krusynth commented on May 2, 2015

    @krusynth
    Member

    Nono, we're using Solarium, not ingesting XML. So this isn't relevant anymore.

    On May 2, 2015, at 4:13 PM, Waldo Jaquith [email protected] wrote:

    Well, since Solr is still an option for folks, and since Solr seizes up and dies if there's a single XML error, I think it's best to retain. After I put hours and hours into work into this damned problem, I'll just add in those two lines, test it, and be done with it. :)

    —
    Reply to this email directly or view it on GitHub.

  25. waldoj commented on May 3, 2015

    @waldoj
    MemberAuthor

    I missed this memo. Huzzah!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions