-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
feat: support async custom functions #1058
Conversation
be99726
to
19ad179
Compare
Yeah, let’s show off our features!
…On Fri, Apr 10, 2020 at 16:35, Jakub Rożek ***@***.***> wrote:
@P0lip commented on this pull request.
---------------------------------------------------------------
In [docs/guides/custom-functions.md](#1058 (comment)):
> @@ -2,6 +2,10 @@
If the built-in functions are not enough for your [custom ruleset](../getting-started/rulesets.md), Spectral allows you to write and use your own custom functions.
+As of Spectral 5.4.0, custom functions can also be asynchronous.
+Be aware that linting should be deterministic. That being said, please refrain from introducing any logic that is prone to non-deterministic behavior, i.e. contacting external service you have no control of, and hence cannot predict the response.
> This could be a warning block.
Do you mean the warning block from SMD?
—
You are receiving this because you commented.
Reply to this email directly, [view it on GitHub](#1058 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AAAQONIWITQ7XSMYHODQTJTRL44F3ANCNFSM4MBPPGHQ).
|
Co-Authored-By: Phil Sturgeon <phil@stoplight.io>
if (res.ok) { | ||
this.cache.set(CACHE_KEY, await res.json()); | ||
} else { | ||
// you can either re-try or just throw an error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip What's the effect from throwing from within a function? Does the whole process crash down? Do we get a special kind of result or a console log?
From the function writer standpoint, what kind of code should be written
- if I don't want this failure being unnoticed
- if I prefer to see a CI build fail rather than having it pass for the wrong reasons
Note: I know this is kind off-topic with regards to the scope of the PR but... well... this is documentation and, to be honest, the doco actually lacks guidance about this.
Note 2: If you prefer this to be dealt with later, could you please log an issue to keep track of that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@P0lip What's the effect from throwing from within a function? Does the whole process crash down? Do we get a special kind of result or a console log?
We'd get a console.log, same as we do when any other custom function throws an exception.
The whole process would still keep on going.
if I prefer to see a CI build fail rather than having it pass for the wrong reasons
I'd return a regular error, i.e.
return [{ message: 'Network error. The check could not be performed' }]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so great! |
Closes #694
Checklist
Does this PR introduce a breaking change?