-
-
Notifications
You must be signed in to change notification settings - Fork 46
Document mixin flow issues when using error
mixin
#174
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
Comments
error
mixinerror
mixin
Hmmm, I think if we force error returns to be strings before output, that might do it? |
But you're right, we can't stop compilation, because that defeats the purpose. |
I'm confused. Can you give an example, please? |
@oscarmarcelo I'm sorry, I totally misread the issue and solved the wrong problem. I don't see any way to make Sass stop compilation of a single mixin or function, without stopping the entire compilation process - which is what you get from a built-in But you do have the tools to implement it on your end if necessary. The only solution I know of would be to put the rest of the mixin behind an =width ($length)
@if $length == red
+error("Not red", null, true)
@else
width: not-color($length)
min-width: 1px That way you either get the error or the output, but never both. |
error
mixinerror
mixin
I'm sorry for opening this again, but I think I have viable solution to this issue. I'm still trying to understand how In the method I used in the example above (using input validation to interrupt the mixin flow instead of controlling with I suggest adding a ExampleUsing the code in the first message of this issue, the following test would pass: +describe("Errors")
+it("Shouldn't accept colors")
+output
+width(red)
+starts-with
/* ERROR: */
/* Not red */ |
The contains mixin compiles exactly the same as expect, but with a different wrapping comment to signal what the JS integration should compare between the blocks. You can use that to see if there is an error in the output (regardless of position). I'm not sure why the in any case - we can't check those values inside
+describe("Errors")
+it("Shouldn't accept colors")
+output
+width(red)
+contains
/* ERROR: */
/* Not red */ |
Yes, you are totally right! I guess I really have to abandon the method of using input validation to decide wether the mixin should continue its flow or not... |
Uh oh!
There was an error while loading. Please reload this page.
I found a kind of edge case, and honestly I don't think that there may be a viable solution without Sass implementing try/catch or something similar, but I'm pointing this anyway in case someone finds a solution, since I didn't find anything yet.
Consider the following:
Now if we replace
@error
by True's+throw.error
:+throw.error
now@return
s something to the mixin, allowing it to continue its flow, instead of stopping it.Error: <insert-map-here> isn't a valid CSS value.
).Now lets explore a bit further:
And the result is:
The flow should stop on the first error, but instead it continues the mixin flow, outputting additional content and errors.
Is there something that can be currently done about this?
The text was updated successfully, but these errors were encountered: