Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ import verifyConfig from "./lib/verify-config.js";

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

function execErrorMessage(error) {
return error.stdout && error.stdout.trim.length > 0
? error.stdout
: `${error.name}: ${error.message}`;
}

export async function verifyConditions(pluginConfig, context) {
if (!isNil(pluginConfig.verifyConditionsCmd) || !isNil(pluginConfig.cmd)) {
verifyConfig("verifyConditionsCmd", pluginConfig);

try {
await exec("verifyConditionsCmd", pluginConfig, context);
} catch (error) {
throw new SemanticReleaseError(error.stdout, "EVERIFYCONDITIONS");
const message = execErrorMessage(error);
throw new SemanticReleaseError(message, "EVERIFYCONDITIONS");
}
}
}
Expand All @@ -35,7 +42,8 @@ export async function verifyRelease(pluginConfig, context) {
try {
await exec("verifyReleaseCmd", pluginConfig, context);
} catch (error) {
throw new SemanticReleaseError(error.stdout, "EVERIFYRELEASE");
const message = execErrorMessage(error);
throw new SemanticReleaseError(message, "EVERIFYRELEASE");
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,20 @@ test('Skip step if neither "cmd" nor step cmd is defined', async (t) => {
await t.notThrowsAsync(success({}, {}));
await t.notThrowsAsync(fail({}, {}));
});

const assertReferenceError = test.macro(async (t, fn) => {
const err = await t.throwsAsync(fn({ cmd: "echo ${iDont.exist}" }, {}));
t.regex(err.message, /iDont is not defined/);
});

test(
"Throws a useful error for bad interpolation in verifyConditions",
assertReferenceError,
verifyConditions,
);

test(
"Throws a useful error for bad interpolation in verifyRelease",
assertReferenceError,
verifyRelease,
);