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

Regression? #2

Open
betehess opened this issue Feb 1, 2016 · 6 comments
Open

Regression? #2

betehess opened this issue Feb 1, 2016 · 6 comments

Comments

@betehess
Copy link

betehess commented Feb 1, 2016

I have followed the installation instruction and tried the given example, with no luck:

$ jsonld compact -c "https://w3id.org/payswarm/v1" "http://recipes.payswarm.com/?p=10554"
jsonld.CompactError: Could not expand input before compaction.
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:142:23
    at done (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:274:18)
    at /usr/local/lib/node_modules/jsonld-cli/bin/jsonld:128:7
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:298:13
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:208:9
    at Processor.fromRDF (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:3300:3)
    at fromRDF (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:908:23)
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:903:7
    at doNTCallback0 (node.js:407:9)
    at process._tickCallback (node.js:336:13)
Error: {
  "name": "jsonld.CompactError",
  "message": "Could not expand input before compaction.",
  "details": {
    "cause": {
      "message": "Bad status code.",
      "statusCode": 500,
      "url": "http://recipes.payswarm.com/?p=10554",
      "body": []
    }
  }
}

Just in case it was because of the resource, I've tried that one as well:

$  jsonld compact -c http://schema.org http://www.theguardian.com/us
jsonld.CompactError: Could not process context before compaction.
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:151:25
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:2024:14
    at done (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:6763:20)
    at /usr/local/lib/node_modules/jsonld-cli/bin/jsonld:128:7
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:314:9
    at Processor.fromRDF (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:3300:3)
    at fromRDF (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:908:23)
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:903:7
    at doNTCallback0 (node.js:407:9)
    at process._tickCallback (node.js:336:13)
Error: {
  "name": "jsonld.CompactError",
  "message": "Could not process context before compaction.",
  "details": {
    "cause": {
      "name": "jsonld.InvalidUrl",
      "message": "Dereferencing a URL did not result in a JSON object. The response was valid JSON, but it was not a JSON object.",
      "details": {
        "code": "invalid remote context",
        "url": "http://schema.org",
        "cause": null
      }
    }
  }
}
@dlongley
Copy link
Member

dlongley commented Feb 1, 2016

That first example works now (there was a problem with the resource that has been fixed).

The second example doesn't work because of a long-standing bug (#1) that, in order to fix it, requires the command line tool to make use of the built-in document loader instead of the custom one it attaches. The built-in loader will set an Accept header including application/ld+json when retrieving contexts, which is required to load the context properly from http://schema.org. Since that header is not being sent by the custom loader when retrieving contexts, you're getting a somewhat ambiguous error about it in the second example.

The proper fix is for the command line tool to be updated to make better use of the built-in document loaders in jsonld.js (which would also fix a few other issues such as handling the Link header, etc).

@betehess
Copy link
Author

betehess commented Feb 2, 2016

I confirm the first example works.

But if I understand correctly your explanation, I should at least be able to use a local context:

➜ http GET http://schema.org Accept:application/ld+json > schema.org
➜ head schema.org
{"@context":    {
        "type": "@type",
        "id": "@id",
        "cat": "http://www.w3.org/ns/dcat#",
        "qb": "http://purl.org/linked-data/cube#",
        "org": "http://www.w3.org/ns/org#",
        "grddl": "http://www.w3.org/2003/g/data-view#",
        "ma": "http://www.w3.org/ns/ma-ont#",
        "owl": "http://www.w3.org/2002/07/owl#",
        "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
➜ jsonld compact --context schema.org http://www.theguardian.com/us
jsonld.CompactError: Could not process context before compaction.
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:151:25
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:2024:14
    at done (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:6763:20)
    at /usr/local/lib/node_modules/jsonld-cli/bin/jsonld:128:7
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:298:13
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:208:9
    at Processor.fromRDF (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:3300:3)
    at fromRDF (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:908:23)
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:903:7
    at doNTCallback0 (node.js:407:9)
Error: {
  "name": "jsonld.CompactError",
  "message": "Could not process context before compaction.",
  "details": {
    "cause": {
      "name": "jsonld.InvalidUrl",
      "message": "Dereferencing a URL did not result in a valid JSON-LD object. Possible causes are an inaccessible URL perhaps due to a same-origin policy (ensure the server uses CORS if you are using client-side JavaScript), too many redirects, a non-JSON response, or more than one HTTP Link Header was provided for a remote context.",
      "details": {
        "code": "loading remote context failed",
        "url": "http://www.theguardian.com/schema.org",
        "cause": {
          "message": "Bad status code.",
          "statusCode": 404,
          "url": "http://www.theguardian.com/schema.org",
          "body": []
        }
      }
    }
  }
}

Right now, I am actually just trying to extract the JSON-LD (and other metadata) from a given resource but I cannot find a way to do that.

@dlongley
Copy link
Member

dlongley commented Feb 2, 2016

@betehess,

Try saving the context with a .json extension. It should work then (it did for me).

@betehess
Copy link
Author

betehess commented Feb 2, 2016

I have tried to save the context with a .json extension. I've also tried to save the resource locally. Still no luck :-/

➜  http GET http://schema.org Accept:application/ld+json > schemaorg.json
➜  jsonld compact --context schemaorg.json http://www.theguardian.com/us
jsonld.CompactError: Could not process context before compaction.
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:151:25
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:2024:14
    at done (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:6763:20)
    at /usr/local/lib/node_modules/jsonld-cli/bin/jsonld:128:7
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:298:13
    at _typedParse (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:73:9)
    at _parse (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:189:12)
    at Request._callback (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:292:18)
    at Request.self.callback (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/node_modules/request/request.js:199:22)
    at emitTwo (events.js:87:13)
Error: {
  "name": "jsonld.CompactError",
  "message": "Could not process context before compaction.",
  "details": {
    "cause": {
      "name": "jsonld.InvalidUrl",
      "message": "Dereferencing a URL did not result in a valid JSON-LD object. Possible causes are an inaccessible URL perhaps due to a same-origin policy (ensure the server uses CORS if you are using client-side JavaScript), too many redirects, a non-JSON response, or more than one HTTP Link Header was provided for a remote context.",
      "details": {
        "code": "loading remote context failed",
        "url": "http://www.theguardian.com/schemaorg.json",
        "cause": {
          "message": "Bad status code.",
          "statusCode": 404,
          "url": "http://www.theguardian.com/schemaorg.json",
          "body": "\n\n<!DOCTYPE html>\n<!--[if lt IE 7]> <html class=\"lt-ie9 lt-ie8 lt-ie7\" lang=\"en\"> <![endif]-->\n<!--[if IE 7]>    <html class=\"lt-ie9 lt-ie8\" lang=\"en\"> <![endif]-->\n<!--[if IE 8]>    <html class=\"lt-ie9\" lang=\"en\"> <![endif]-->\n<!--[if gt IE 8]><!--> <html lang=\"en\"> <!--<![endif]-->\n    <head>\n        <meta charset=\"utf-8\" />\n        <title>404 | Guardian News &amp; Media</title>\n        <meta name=\"description\" content=\"\" />\n        <meta name=\"author\" content=\"the Guardian\" />\n        <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\" />\n        <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n        <!-- Include core base and module styles -->\n        <link rel=\"stylesheet\" type=\"text/css\" href=\"https://pasteup.guim.co.uk/css/core.pasteup.min.css\" />\n        <!-- Add layout styles for browsers over 30em or less than IE9, but not IE mobile or IE6. -->\n        <link rel=\"stylesheet\" media=\"all and (min-width: 30em)\" type=\"text/css\" href=\"https://pasteup.guim.co.uk/css/layout.pasteup.min.css\" />\n        <!--[if (lt IE 9) & (!IEMobile)]>\n            <link rel=\"stylesheet\" type=\"text/css\" href=\"https://pasteup.guim.co.uk/css/layout.pasteup.min.css\" />\n        <![endif]-->\n        <style>\n            .u-unstyled {\n                list-style: none;\n            }\n            .u-unstyled  li {\n                display: block;\n                float:left;\n                width: 40%;\n                padding: 10px 2.5%;\n                margin: 0 2.5%;\n                border-bottom: 1px solid #F4F4EE;\n            }\n            .global-navigation a {\n                display: block; /* Expands touch area of links */\n            }\n        </style>\n    </head>\n    <body>\n        <div class=\"fluid-wrap\">\n            <div class=\"topbar\">\n                <div class=\"topbar-menu-container\">\n                    <ul class=\"topbar-menu pull-left\">\n                        <li><a href=\"/\">Home</a></li>\n                    </ul>\n                </div>\n            </div>\n            <img src=\"https://static.guim.co.uk/static/60ed206dbccc8b808a7792d47862f9cfb7cd3d67/common/images/logos/the-guardian/titlepiece.gif\">\n            <div class=\"fluid-row margin-top\">\n                <div class=\"col-12 start-col margin-bottom\">\n                    <h1>Sorry - we haven’t been able to serve the page you asked for.</h1>\n                </div>\n            </div><!-- /.row -->\n\n            <div class=\"fluid-row margin-top\">\n                <div class=\"col-12 start-col\">\n                    <div class=\"hd zone-border zone-border-medium\">\n                        <h2 class=\"sub-heading\">404</h2>\n                    </div>\n                    <p>You may have followed a broken or outdated link, or there may be an error on our site.</p>\n                    <p>Please follow one of the links below to continue exploring.</p>\n                    <nav>\n                        <ul role=\"navigation\" class=\"u-unstyled global-navigation\">\n                            <li><a href=\"/\">home</a></li>\n                            <li class=\"zone-news\"><a href=\"/uk\" class=\"zone-color\">UK</a></li>\n                            <li class=\"zone-news\"><a href=\"/world\" class=\"zone-color\">world</a></li>\n                            <li class=\"zone-sport\"><a href=\"/sport\" class=\"zone-color\">sport</a></li>\n                            <li class=\"zone-sport\"><a href=\"/football\" class=\"zone-color\">football</a></li>\n                            <li class=\"zone-comment\"><a href=\"/commentisfree\" class=\"zone-color\">comment</a></li>\n                            <li class=\"zone-culture\"><a href=\"/culture\" class=\"zone-color\">culture</a></li>\n                            <li class=\"zone-business\"><a href=\"/business\" class=\"zone-color\">economy</a></li>\n                            <li class=\"zone-lifeandstyle\"><a href=\"/lifeandstyle\" class=\"zone-color\">life</a></li>\n                            <li class=\"zone-lifeandstyle\"><a href=\"/fashion\" class=\"zone-color\">fashion</a></li>\n                            <li class=\"zone-environment\"><a href=\"/environment\" class=\"zone-color\">environment</a></li>\n                            <li><a href=\"/technology\" class=\"zone-color\">tech</a></li>\n                            <li><a href=\"/money\" class=\"zone-color\">money</a></li>\n                            <li><a href=\"/travel\" class=\"zone-color\">travel</a></li>\n                            <li><a href=\"https://soulmates.guardian.co.uk/\" class=\"zone-color\">soulmates</a></li>\n                            <li><a href=\"http://m.jobs.guardian.co.uk/\" class=\"zone-color\" target=\"_blank\">jobs</a></li>\n                            <li><a href=\"/guardian-masterclasses\" class=\"zone-color\" target=\"_blank\">masterclasses</a></li>\n                        </ul>\n                    </nav>\n                </div><!-- /.col-12 -->\n\n            </div><!-- /.row -->\n\n            <div class=\"footer zone-border zone-border-medium margin-top\">\n                <ul class=\"inline with-separators\">\n                    <li><a href=\"/help\">Help</a></li>\n                    <li><a href=\"/help/contact-us\">Contact us</a></li>\n                    <li><a target=\"_blank\" href=\"https://www.surveymonkey.com/s/theguardian-beta-feedback\">Feedback</a></li>\n                    <li><a href=\"/help/terms-of-service\">Terms &amp; conditions</a></li>\n                    <li><a href=\"/help/privacy-policy\">Privacy policy</a></li>\n                </ul>\n                <p><small>&copy; Guardian News and Media Limited or its affiliated companies. All rights reserved. Registered in England and Wales. No. 908396. Registered office: PO Box 68164, Kings Place, 90 York Way, London N1P 2AP</small></p>\n            </div>\n        </div><!-- /.fluid-wrap -->\n\n        <script>\n            var s_account=\"guardiangu-network\";\n        </script>\n        <script src=\"http://image.guardian.co.uk/omni/omniture.js\"></script>\n        <script>\n            s.pageType =\"errorPage\"\n            s.prop19 = \"frontend\";\n            s.t();\n        </script>\n        <noscript>\n            <img src=\"http://hits.guardian.co.uk/b/ss/guardiangu-network/1/H.24.2/?v19=frontend&v7=404&ns=guardian&c19=frontend&c9=404&c30=non-content&c6=&c13=&pageType=errorPage&pageName=404&g=http%3A%2F%2Fm.guardian.co.uk%2F/404&\" alt=\"\" style=\"display: none;\" />\n        </noscript>\n\n        <script src=\"https://pasteup.guim.co.uk/js/lib/requirejs/2.1.5/require.min.js\"></script>\n\n        <script>\n            require.config({\n                paths: {\n                    'ophan/http-status' : '//j.ophan.co.uk/ophan.http-status',\n                }\n            });\n            require(['ophan/http-status'], function(reporter) {\n              reporter.reportStatus('next-gen', 404);\n            });\n        </script>\n\n        <img src=\"//beacon.guim.co.uk/count/40x.gif\" alt=\"\" style=\"display: none;\" rel=\"nofollow\" />\n\n    </body>\n</html>\n"
        }
      }
    }
  }
}
➜  http GET http://www.theguardian.com/us > theguardian.html
➜  jsonld compact --context schemaorg.json theguardian.html
jsonld.CompactError: Could not expand input before compaction.
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:142:23
    at done (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld/js/jsonld.js:274:18)
    at /usr/local/lib/node_modules/jsonld-cli/bin/jsonld:128:7
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:328:9
    at Object.jsdom.env.done (/usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/lib/request.js:123:15)
    at /usr/local/lib/node_modules/jsonld-cli/node_modules/jsonld-request/node_modules/jsdom/lib/jsdom.js:249:18
    at doNTCallback0 (node.js:407:9)
    at process._tickCallback (node.js:336:13)
Error: {
  "name": "jsonld.CompactError",
  "message": "Could not expand input before compaction.",
  "details": {
    "cause": {
      "message": "RDFa extraction error.",
      "contentType": "html",
      "url": "theguardian.html"
    }
  }
}

@dlongley
Copy link
Member

dlongley commented Feb 2, 2016

@betehess,

You're right, I thought it was working for me but I was seeing a really long stack trace that looked like output instead. Not working for me either.

cc: @davidlehn

@davidlehn
Copy link
Member

I filed an issue about schema.org accept header q parameter parsing. In the mean time, I put out a new jsonld-request lib that removes spaces before q paramters:
https://github.com/digitalbazaar/jsonld-request/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants