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

JS API: Validate that importer result 'contents' is a string and improve ArgumentError output #1816

Merged
merged 5 commits into from
Nov 3, 2022

Conversation

Goodwine
Copy link
Member

@Goodwine Goodwine commented Oct 28, 2022

See: sass/sass-spec#1834

Example output:

sass.Exception [Error]: Invalid argument (contents): must be a string but was: Buffer.: Instance of 'NativeUint8List'
  ╷
1 │ @import './foo.wxss';
  │         ^^^^^^^^^^^^
  ╵
  - 1:9  root stylesheet
  - [...]

Before using toString() for Argument error:

sass.Exception [Error]: must be a string but was: Buffer
  ╷
1 │ @import './foo.wxss';
  │         ^^^^^^^^^^^^
  ╵
  - 1:9  root stylesheet
  - [...]

Original error:

sass.Exception [Error]: NoSuchMethodError: method not found: 'charCodeAt' (receiver.charCodeAt is not a function)
  ╷
1 │ @import './foo.wxss';
  │         ^^^^^^^^^^^^
  ╵
  - 1:9  root stylesheet
  - [...]

Fixes #1550

@Goodwine Goodwine requested a review from nex3 October 28, 2022 00:46
@Goodwine Goodwine changed the title Validate ImporterResult 'contents' and improve ArgumentError output JS API: Validate that importer result 'contents' is a string and improve ArgumentError output Oct 28, 2022
Copy link
Contributor

@nex3 nex3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this to sass-spec as well?

CHANGELOG.md Show resolved Hide resolved
@Goodwine
Copy link
Member Author

Goodwine commented Nov 1, 2022

Can you add a test for this to sass-spec as well?

I wasn't sure where were the tests actually, but I found them now 🙂

Added tests and updated to also handle legacy importers which I realized just now via testing that it wasn't handled (yay tests)

@Goodwine Goodwine requested a review from nex3 November 1, 2022 01:33
@Goodwine Goodwine merged commit f3293db into main Nov 3, 2022
@Goodwine Goodwine deleted the importer-js branch November 3, 2022 23:50
Goodwine added a commit to sass/embedded-host-node that referenced this pull request Nov 9, 2022
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

Successfully merging this pull request may close these issues.

Improve error message when a custom importer returns a Buffer instead of a string
2 participants