这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@timheuer
Copy link

Using setFailed for error handling and moved log to debug

if (error) throw error
(error: any, data: any, response: any) => {
if (error) {
core.setFailed(`Tweet failed! Error data: ${error[0].message}`)
Copy link
Owner

Choose a reason for hiding this comment

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

Does setFailed just set the failure state and continue? (ie, it doesn't throw an exception or otherwise trampoline out of here). If so, I think that we should make it explicit that we're going to keep going, which wasn't obvious to me at first reading. I think that we should either return here or hoist the debug messages up above it so that it's more clear that they will always be executed.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, setFailed sets the failing exit code per https://github.com/actions/toolkit/tree/master/packages/core#exit-codes

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the ping - sorry that I forgot about this issue.

To clarify - my question isn't whether setError sets the error code. My question was whether it stops execution, which it looks to me like it does not? Shouldn't we follow up setError with a process.exit or something along those lines instead of continuing on?

Copy link
Author

Choose a reason for hiding this comment

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

yes if you use setFailed and the user hasn't set any 'continue on error' values in their workflow, then it will fail the action step.

Copy link
Owner

Choose a reason for hiding this comment

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

I don't mean the workflow step - I mean the action itself. What I mean is that calling core.setFailed just sets the error message and exit status and then the process itself will just continue. So you need to stop the process, that's why I was throwing.

See https://github.com/ethomson/test and https://github.com/ethomson/test/runs/1645271583?check_suite_focus=true for an illustration of what I mean.

Copy link
Author

Choose a reason for hiding this comment

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

Ah, got it now -- sorry I misunderstood what you were pointing out. I think throwing the errors then on validating input probably still makes sense. Since run() is the only real function afterwards and the last code execution is the result of the update post, the setFailed there probably makes sense to leave as is, as you'd be throwing to the end of execution anyway.

So an update could be to setFailed and throw on the validateInput function, and just keep setFailed on run() since it's the last execution.

Either way I get what you're saying now.

@timheuer
Copy link
Author

Bump @ethomson here to see if you'd consider taking these changes. Added setOutput here as well to enable a better workflow for Environments

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.

2 participants