Skip to content

Commit a285bc5

Browse files
pbrisbintravi
andauthored
feat(error): print more useful error for non-process failure (#449)
Co-authored-by: Matt Travi <126441+travi@users.noreply.github.com>
1 parent aa1a2bc commit a285bc5

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ import verifyConfig from "./lib/verify-config.js";
77

88
const debug = debugFactory("semantic-release:exec");
99

10+
function execErrorMessage(error) {
11+
return error.stdout && error.stdout.trim.length > 0
12+
? error.stdout
13+
: `${error.name}: ${error.message}`;
14+
}
15+
1016
export async function verifyConditions(pluginConfig, context) {
1117
if (!isNil(pluginConfig.verifyConditionsCmd) || !isNil(pluginConfig.cmd)) {
1218
verifyConfig("verifyConditionsCmd", pluginConfig);
1319

1420
try {
1521
await exec("verifyConditionsCmd", pluginConfig, context);
1622
} catch (error) {
17-
throw new SemanticReleaseError(error.stdout, "EVERIFYCONDITIONS");
23+
const message = execErrorMessage(error);
24+
throw new SemanticReleaseError(message, "EVERIFYCONDITIONS");
1825
}
1926
}
2027
}
@@ -35,7 +42,8 @@ export async function verifyRelease(pluginConfig, context) {
3542
try {
3643
await exec("verifyReleaseCmd", pluginConfig, context);
3744
} catch (error) {
38-
throw new SemanticReleaseError(error.stdout, "EVERIFYRELEASE");
45+
const message = execErrorMessage(error);
46+
throw new SemanticReleaseError(message, "EVERIFYRELEASE");
3947
}
4048
}
4149
}

test/integration.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,20 @@ test('Skip step if neither "cmd" nor step cmd is defined', async (t) => {
2222
await t.notThrowsAsync(success({}, {}));
2323
await t.notThrowsAsync(fail({}, {}));
2424
});
25+
26+
const assertReferenceError = test.macro(async (t, fn) => {
27+
const err = await t.throwsAsync(fn({ cmd: "echo ${iDont.exist}" }, {}));
28+
t.regex(err.message, /iDont is not defined/);
29+
});
30+
31+
test(
32+
"Throws a useful error for bad interpolation in verifyConditions",
33+
assertReferenceError,
34+
verifyConditions,
35+
);
36+
37+
test(
38+
"Throws a useful error for bad interpolation in verifyRelease",
39+
assertReferenceError,
40+
verifyRelease,
41+
);

0 commit comments

Comments
 (0)