@actions/core#error TypeScript Examples

The following examples show how to use @actions/core#error. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From retry with MIT License 6 votes vote down vote up
async function runRetryCmd(): Promise<void> {
  // if no retry script, just continue
  if (!ON_RETRY_COMMAND) {
    return;
  }

  try {
    await execSync(ON_RETRY_COMMAND, { stdio: 'inherit' });
  } catch (error) {
    info(`WARNING: Retry command threw the error ${error.message}`)
  }
}
Example #2
Source File: index.ts    From retry with MIT License 6 votes vote down vote up
async function runAction() {
  await validateInputs();

  for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
    try {
      // just keep overwriting attempts output
      setOutput(OUTPUT_TOTAL_ATTEMPTS_KEY, attempt);
      await runCmd(attempt);
      info(`Command completed after ${attempt} attempt(s).`);
      break;
    } catch (error) {
      if (attempt === MAX_ATTEMPTS) {
        throw new Error(`Final attempt failed. ${error.message}`);
      } else if (!done && RETRY_ON === 'error') {
        // error: timeout
        throw error;
      } else if (RETRY_ON_EXIT_CODE && RETRY_ON_EXIT_CODE !== exit){
        throw error;
      } else if (exit > 0 && RETRY_ON === 'timeout') {
        // error: error
        throw error;
      } else {
        await runRetryCmd();
        if (WARNING_ON_RETRY) {
          warning(`Attempt ${attempt} failed. Reason: ${error.message}`);
        } else {
          info(`Attempt ${attempt} failed. Reason: ${error.message}`);
        }
      }
    }
  }
}
Example #3
Source File: index.ts    From retry with MIT License 6 votes vote down vote up
runAction()
  .then(() => {
    setOutput(OUTPUT_EXIT_CODE_KEY, 0);
    process.exit(0); // success
  })
  .catch((err) => {
    // exact error code if available, otherwise just 1
    const exitCode = exit > 0 ? exit : 1;

    if (CONTINUE_ON_ERROR) {
      warning(err.message);
    } else {
      error(err.message);
    }

    // these can be  helpful to know if continue-on-error is true
    setOutput(OUTPUT_EXIT_ERROR_KEY, err.message);
    setOutput(OUTPUT_EXIT_CODE_KEY, exitCode);

    // if continue_on_error, exit with exact error code else exit gracefully
    // mimics native continue-on-error that is not supported in composite actions
    process.exit(CONTINUE_ON_ERROR ? 0 : exitCode);
  });