node进程捕捉错误

var childProcess = require('child_process');
var commitMessage = (function() {
	var spawn = childProcess.spawnSync(<common>, <param>);
	var errorText = spawn.stderr.toString().trim();
	if (errorText) {
	  console.log('Fatal error from `git log`.  You must have one commit before deploying.');
	  throw new Error(errorText);
	}
	else {
	  return spawn.stdout.toString().trim();
	}
})();
原文地址:https://www.cnblogs.com/honghong87/p/9310438.html