question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

“Cannot read property 'lastIndexOf' of undefined” when passing filename to spectral lint

See original GitHub issue

Describe the bug When specifying a path (like I have always done) with spectral lint, it throws the following error:

Cannot read property ‘lastIndexOf’ of undefined

Even with verbose mode, no other information (such as file or line number) is printed.

However, if I run the same command with just a path (i.e. leaving the filename out), it works as intended.

To Reproduce

  1. Run, i.e. spectral lint reference/vsapi/openapi.yaml
  2. See error above printed in console
  3. Run spectral lint reference/vsapi
  4. See No results with a severity of 'error' or higher found! printed in console.

Expected behavior The help text for spectral lint says:

Positionals:
  documents  Location of JSON/YAML documents. Can be either a file, a glob or fetchable resource(s) on the web.

But, it seems specifying a file breaks it (or at least it does in my case). Am I still supposed to be able to use a file path in Spectral v5? As the error doesn’t happen in Spectral v4.

Environment:

  • Library version: 5.3.0
  • OS: macOS Catalina (10.15.4)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
nulltokencommented, Apr 20, 2020

I can repro the issue.

MINGW64 /h/spectral ((3a181ce...))
$ npx @stoplight/spectral@latest lint https://raw.githubusercontent.com/stoplightio/spectral/develop/src/__tests__/__fixtures__/petstore.oas3.json
Cannot read property 'lastIndexOf' of undefined

However, it doesn’t seem to reproduce against the development branch.

MINGW64 /h/spectral ((3a181ce...))
$ yarn cli lint https://raw.githubusercontent.com/stoplightio/spectral/develop/src/__tests__/__fixtures__/petstore.oas3.json
yarn run v1.21.1
$ node -r ts-node/register -r tsconfig-paths/register src/cli/index.ts lint https://raw.githubusercontent.com/stoplightio/spectral/develop/src/__te
sts__/__fixtures__/petstore.oas3.json
Missing baseUrl in compilerOptions. tsconfig-paths will be skipped
OpenAPI 3.x detected

https://raw.githubusercontent.com/stoplightio/spectral/develop/src/__tests__/__fixtures__/petstore.oas3.json
  1:1   warning  openapi-tags           OpenAPI object should have non-empty `tags` array.
  3:10  warning  info-contact           Info object should contain `contact` object.
  3:10  warning  info-description       OpenAPI object info `description` must be present and non-empty string.
 17:13  warning  operation-description  Operation `description` must be present and non-empty string.
 20:18  warning  operation-tag-defined  Operation tags should be defined in global tags.
 64:14  warning  operation-description  Operation `description` must be present and non-empty string.
 67:18  warning  operation-tag-defined  Operation tags should be defined in global tags.
 86:13  warning  operation-description  Operation `description` must be present and non-empty string.
 89:18  warning  operation-tag-defined  Operation tags should be defined in global tags.

✖ 9 problems (0 errors, 9 warnings, 0 infos, 0 hints)

Done in 14.59s.

A new beta release should be issued shortly by @P0lip. We’ll ping you as soon as it’s available in order to check with you if the issue is still happening in your context.

2reactions
P0lipcommented, Apr 20, 2020

Although, 5.4.0-beta1 has just been released, 5.3.0 should be working again, so feel free to stick to 5.3.0 in case you don’t want to try out beta (that’s pretty stable anyway, but just called beta) Just make sure to clean yarn/npm cache and re-install it again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found