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

Intermittent failures resolving filesystem $ref's #26

Closed
coltonlw opened this issue Aug 17, 2016 · 6 comments
Closed

Intermittent failures resolving filesystem $ref's #26

coltonlw opened this issue Aug 17, 2016 · 6 comments

Comments

@coltonlw
Copy link

We have discovered that json-schema-ref-parser will intermittently fail resolving $ref's from the local filesystem. The failure symptom is attempting to resolve the $ref relative to the current working directory, instead of the referring document. This is estimated to happen about 1 of every 10 times.

  1) PUT /users/{UserId} -> 200 "before all" hook: bound :
     Uncaught Error: Unable to expand schema:
{
    "$schema": "http:https://json-schema.org/draft-04/schema#",
    "$ref": "../definitions/user.json#"
}
Error:
Error: Error opening file "/Users/coltonlw/projects/definitions/user.json"
ENOENT: no such file or directory, open '/Users/coltonlw/projects/definitions/user.json'
      at /usr/local/lib/node_modules/abao/lib/test.coffee:134:19
      at /usr/local/lib/node_modules/abao/node_modules/call-me-maybe/index.js:13:28
      at _combinedTickCallback (internal/process/next_tick.js:67:7)
      at process._tickCallback (internal/process/next_tick.js:98:9)

json-schema-ref-parser is attempting to load "/Users/coltonlw/projects/definitions/user.json", however the directory structure is like this:

/Users/coltonlw/projects/core/raml/schemas/definitions/user.json

With the referring document located at

/Users/coltonlw/projects/core/raml/schemas/output/user.json

@coltonlw
Copy link
Author

To be clear this is using dereference() without using promises syntax, going to test promises now

@coltonlw
Copy link
Author

coltonlw commented Aug 17, 2016

After switching to promises syntax, I was able to run through 1000 iterations of my test without a failure, so I'd say the issue is somewhere there. Maybe related to call-me-maybe library.

@JamesMessinger
Copy link
Member

Odd. It doesn't make sense that it would behave incorrectly only 10% of the time, and the code is the same regardless of whether it uses promises or callbacks. I suspect that there's some other variable at play. Perhaps you have multiple tests running simultaneously, and some of them are making modifications to the same folder structure that others are reading?

@coltonlw
Copy link
Author

Nope, the folder structure isn't being modified. As soon as we switched to promises the issue stopped happening, maybe callbacks aren't playing nice with whatever async setup our testing library (abao) is using. I am new to nodejs so it's very possible I messed something up when I added json-schema-ref-parser to the abao testing library. You can see where we call into json-schema-ref-parser here, and further up in that file you can also see how abao is implementing async behavior:

https://github.com/flywheel-io/abao/blob/add-jsonschema-deref/lib/test.coffee#L113

@coltonlw
Copy link
Author

Here is what the code looked like when it had the issue, before switching to promises: https://github.com/flywheel-io/abao/blob/015bf54a5b9a72b847e89a7a2b27f4a1c454f62d/lib/test.coffee#L113

@coltonlw
Copy link
Author

This was due to my lack of knowledge in coffeescript syntax, closing

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

2 participants