MCPcopy
hub / github.com/shelljs/shelljs / error

Function error

src/common.js:95–135  ·  view source on GitHub ↗
(msg, _code, options)

Source from the content-addressed store, hash-verified

93
94// Shows error message. Throws if fatal is true (defaults to config.fatal, overridable with options.fatal)
95function error(msg, _code, options) {
96 // Validate input
97 if (typeof msg !== 'string') throw new Error('msg must be a string');
98
99 var DEFAULT_OPTIONS = {
100 continue: false,
101 code: 1,
102 prefix: state.currentCmd + ': ',
103 silent: false,
104 fatal: config.fatal,
105 };
106
107 if (typeof _code === 'number' && isObject(options)) {
108 options.code = _code;
109 } else if (isObject(_code)) { // no 'code'
110 options = _code;
111 } else if (typeof _code === 'number') { // no 'options'
112 options = { code: _code };
113 } else if (typeof _code !== 'number') { // only 'msg'
114 options = {};
115 }
116 options = Object.assign({}, DEFAULT_OPTIONS, options);
117
118 if (!state.errorCode) state.errorCode = options.code;
119
120 var logEntry = convertErrorOutput(options.prefix + msg);
121 state.error = state.error ? state.error + '\n' : '';
122 state.error += logEntry;
123
124 // Throw an error, or log the entry
125 if (options.fatal) {
126 var err = new Error(logEntry);
127 err.code = options.code;
128 throw err;
129 }
130 if (msg.length > 0 && !options.silent) log(logEntry);
131
132 if (!options.continue) {
133 throw new CommandError(new ShellString('', state.error, state.errorCode));
134 }
135}
136exports.error = error;
137
138//@

Callers 1

parseOptionsFunction · 0.70

Calls 3

isObjectFunction · 0.85
convertErrorOutputFunction · 0.85
logFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…