help icon indicating copy to clipboard operation
help copied to clipboard

ExecSync command fails without any error in the command being executed

Open hardikmodi1 opened this issue 1 year ago • 3 comments

Node.js Version

v18.18.2

NPM Version

v9.8.1

Operating System

Linux

Subsystem

child_process

Description

I am running tsc command using execSync with in gitlab pipelines. In most of the cases it works fine. But sometimes it fails without giving any error regarding tsc. Command I am executing is

execSync("yarn tsc", { stdio: 'inherit' });

I have wrapped this command in try catch and printed the exception, In cases where it fails it only prints following thing on console

Error: Command failed: yarn tsc
    at checkExecSyncError (node:child_process:890:11)
    at execSync (node:child_process:962:15)
    at /builds/scripts/tsc.ts:30:13
    at step (/builds/scripts/tsc.ts:44:23) {
  status: 129,
  signal: null,
  output: [ null, null, null ],
  pid: [204],
  stdout: null,
  stderr: null
}

Just rerunning the pipeline without any changes in the code this works fine.

Minimal Reproduction

No response

Output

No response

Before You Submit

  • [X] I have looked for issues that already exist before submitting this
  • [X] My issue follows the guidelines in the README file, and follows the 'How to ask a good question' guide at https://stackoverflow.com/help/how-to-ask

hardikmodi1 avatar Jul 05 '24 17:07 hardikmodi1

Can you reproduce this with any command, or is it specifically yarn commands / tsc commands?

avivkeller avatar Jul 06 '24 03:07 avivkeller

Tried only with tsc. So I am not sure if it reproducible with the other commands or not 😔

hardikmodi1 avatar Jul 06 '24 03:07 hardikmodi1

Could you possibly verify if it's reproducible with other commands? Does this command execute normally when run via the shell?

avivkeller avatar Jul 06 '24 03:07 avivkeller

Yes if I run via shell then it executes normally, even if I just retrigger the pipeline it works fine. It fails randomly with the given error

hardikmodi1 avatar Jul 06 '24 07:07 hardikmodi1

My gut feeling is that it's a yarn issue, given the fact it returned an exit code (129), but I'm not 100% sure.

@nodejs/child_process PTAL

avivkeller avatar Jul 06 '24 11:07 avivkeller

ExecSync is understood to be having issues, failing without errors on the commands it is executing. It created a lot of problems. Try these steps to find the cause and fix the problem:

  1. Check the exit status:
  • Check the status value of ExecSync results.
  • A flag other than 0 indicates that an error occurred.
  • Use console.error Print flags and error messages.
  1. Verify input:
  • Make sure the ExecSync command is correct.
  • Check grammar and upper/lower case letters.
  • Verify that the path to the file used is correct.
  1. Check access rights:
  • Verify that the user account using ExecSync has access to the required files and directories.
  • Try using sudo to run commands with administrator rights.
  1. Check for environmental problems:
  • Verify that required environment variables are set correctly.
  • Verify that the path to the file used is correct.
  1. Check recording:
  • Check application or operating system log files.
  • Error messages in the log file may help determine the cause of the problem.
  1. Check online resources:
  • Search for similar problems on the internet
  • Sites like Stack Overflow or GitHub may have solutions.
  1. Ask for help:
  • If the problem still cannot be solved Please ask your developer or IT professional for help. note:
  • Additional information about ExecSync may be found in the documentation of the library or framework used.
  • Information about specific problems and solutions may be found on the support website of the software or operating system being used. Additional resources:
  • Node.js child_process documentation
  • Stack Overflow: execSync failed.
  • GitHub: ExecSync issue [invalid URL removed] Hope this information helps fix your ExecSync issues!

SsomsakTH avatar Jul 06 '24 20:07 SsomsakTH

It's probably a yarn issue, given that other commands work

avivkeller avatar Oct 16 '24 15:10 avivkeller