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

TypeError: (s || "").replace is not a function #398

Closed
bnb opened this issue Mar 30, 2020 · 6 comments · Fixed by #405
Closed

TypeError: (s || "").replace is not a function #398

bnb opened this issue Mar 30, 2020 · 6 comments · Fixed by #405
Labels
bug Something isn't working

Comments

@bnb
Copy link

bnb commented Mar 30, 2020

Describe the bug
When trying to run an action, I am getting the following error from @actions/core:

(node:2588) UnhandledPromiseRejectionWarning: TypeError: (s || "").replace is not a function
    at escapeData (/home/runner/work/_actions/cutenode/action-meeting/dev/node_modules/@actions/core/lib/command.js:66:10)
    at Command.toString (/home/runner/work/_actions/cutenode/action-meeting/dev/node_modules/@actions/core/lib/command.js:60:35)
    at issueCommand (/home/runner/work/_actions/cutenode/action-meeting/dev/node_modules/@actions/core/lib/command.js:23:30)
    at Object.issue (/home/runner/work/_actions/cutenode/action-meeting/dev/node_modules/@actions/core/lib/command.js:27:5)
    at error (/home/runner/work/_actions/cutenode/action-meeting/dev/node_modules/@actions/core/lib/core.js:127:15)
    at Object.setFailed (/home/runner/work/_actions/cutenode/action-meeting/dev/node_modules/@actions/core/lib/core.js:101:5)
    at action (/home/runner/work/_actions/cutenode/action-meeting/dev/index.js:62:10)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:2588) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2588) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

To Reproduce
Last commit where it works:

It stops working in this commit:

EDIT: Updated to only reflect the commit it stopped working in. This was triggered by passing an incorrect type to Octokit.js for the labels property - I was passing a string and it required an array. Since the project was erroring because of that and the error being passed was not a string, I was encountering this issue.

Expected behavior
For @actions/core to handle errors more effectively.

@bnb bnb added the bug Something isn't working label Mar 30, 2020
@bnb
Copy link
Author

bnb commented Mar 30, 2020

For reference, this is the method that's failing:

https://github.com/actions/toolkit/blob/master/packages/core/src/command.ts#L76

@bnb
Copy link
Author

bnb commented Mar 30, 2020

@gomorizsolt
Copy link

gomorizsolt commented Mar 31, 2020

As of right now, objects have to be stringified when using core.* utilities to output a log to the console.

try {
   // ...
} catch (err) {
   core.setFailed(err.toString());
}

There's an on-going feature request to support objects out of the box as well.

@bnb
Copy link
Author

bnb commented Mar 31, 2020

Thanks for that, it solved my problem. There is zero reason that should be limited to a string, and as far as I can tell it's not documented anywhere other than the code itself.

FWIW, here's a helper function for anyone that encounters this and is lazy:

const core = require('@actions/core')

function catchError (error) {
  const passErrorAsAStringBecauseItsRequired = error.toString()
  core.setFailed(passErrorAsAStringBecauseItsRequired)
}

module.exports = catchError

Just require this in and use it in your catch blocks and you should be good to go.

@gomorizsolt
Copy link

Doesn't core.setFailed() already sets the status code?

setFailed logs the message and sets a failing exit code

According to the docs, it's supposed to do so.

@bnb
Copy link
Author

bnb commented Mar 31, 2020

May have been me overcompensating for the errors I was having. I encountered several cases in trying to debug this for 5 hours where the action successfully passed but the code errored out since unhandled promise rejections were not fully erroring the process.

Updated.

Chocrates pushed a commit to froi/add_invite_user that referenced this issue Jun 18, 2020
froi pushed a commit to froi/add_invite_user that referenced this issue Jun 30, 2020
* Add debug for owner, repo

Signed-off-by: Zack Koppert <zkoppert@github.com>

* add dist

Signed-off-by: Zack Koppert <zkoppert@github.com>

* maybe this actions/toolkit#398

* Updating actions core

* test

Co-authored-by: Zack Koppert <zkoppert@github.com>
zrhoffman added a commit to zrhoffman/junit-report-annotations-action that referenced this issue Sep 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants