snyk / sweater-comb

API linting rules
Other
21 stars 8 forks source link

`sweater-comb workflow operation add-create` errors out with unhandled exception #212

Closed cmars closed 2 years ago

cmars commented 2 years ago

I wrapped sweater-comb with an npm script to make it easier to run:

  "scripts": {
    "api:workflow": "cd src/public; ../../node_modules/.bin/sweater-comb workflow",

I can create an OpenAPI spec with:

npm run api:workflow create-resource repo repos

> testapi@1.0.0 api:workflow /Users/cmars/Projects/rest-node-generate/test/fixtures/testapi
> cd src/public; ../../node_modules/.bin/sweater-comb workflow "create-resource" "repo" "repos"

(So far it's empty; I assume workflow update is coming soon, no problem)

However, when I try to add an operation, I get an uncaught error:

zksnyk:testapi cmars$ npm run api:workflow operation add-create `pwd`/./src/public/resources/repos/2022-02-05/spec.yaml repo repos

> testapi@1.0.0 api:workflow /Users/cmars/Projects/rest-node-generate/test/fixtures/testapi
> cd src/public; ../../node_modules/.bin/sweater-comb workflow "operation" "add-create" "/Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/./src/public/resources/repos/2022-02-05/spec.yaml" "repo" "repos"

(node:87026) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'index' of undefined
    at sourcemapReader (/Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/node_modules/@snyk/sweater-comb/node_modules/@useoptic/openapi-cli/node_modules/@useoptic/openapi-io/build/parser/sourcemap-reader.js:54:106)
    at Function.<anonymous> (/Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/node_modules/@snyk/sweater-comb/node_modules/@useoptic/openapi-cli/build/specs/streams/files.js:114:77)
    at step (/Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/node_modules/@snyk/sweater-comb/node_modules/@useoptic/openapi-cli/build/specs/streams/files.js:35:23)
    at Object.next (/Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/node_modules/@snyk/sweater-comb/node_modules/@useoptic/openapi-cli/build/specs/streams/files.js:16:53)
    at resume (/Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/node_modules/@snyk/sweater-comb/node_modules/@useoptic/openapi-cli/build/specs/streams/files.js:53:44)
    at /Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/node_modules/@snyk/sweater-comb/node_modules/@useoptic/openapi-cli/build/specs/streams/files.js:52:121
    at new Promise (<anonymous>)
    at Object.i.<computed> [as next] (/Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/node_modules/@snyk/sweater-comb/node_modules/@useoptic/openapi-cli/build/specs/streams/files.js:52:63)
    at Function.<anonymous> (/Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/node_modules/@snyk/sweater-comb/node_modules/@useoptic/openapi-cli/build/specs/streams/files.js:262:75)
    at step (/Users/cmars/Projects/rest-node-generate/test/fixtures/testapi/node_modules/@snyk/sweater-comb/node_modules/@useoptic/openapi-cli/build/specs/streams/files.js:35:23)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:87026) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:87026) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
acunniffe commented 2 years ago

Hey @cmars I just ran it again myself and could not reproduce this issue you are seeing.

I then went and tried your scripts and was able to repro then. I don't think the pwd is working as you expect. When you run an npm script it rewrites cwd and always runs it from root.

I've been testing from resources in end-end-tests like this ts-node ../../src/index.ts

We can can come up with a better way. I'm sure some folks on our team have a better idea about how npm scripts works than I do, but pretty sure that's the issue