Skip to content

Commit b4148e2

Browse files
committed
cosign: clear errors if manifest or bundle payload found
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent 7397cfe commit b4148e2

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

src/cosign/cosign.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,24 @@ export class Cosign {
132132
const m0 = obj.manifests[0];
133133
if (m0?.artifactType === BUNDLE_V03_MEDIA_TYPE && typeof m0.digest === 'string') {
134134
signatureManifestDigest = m0.digest;
135+
errors = undefined; // clear errors if we have valid signature manifest
135136
} else if (m0?.artifactType === MEDIATYPE_EMPTY_JSON_V1 && typeof m0.digest === 'string') {
136137
signatureManifestFallbackDigest = m0.digest;
138+
errors = undefined; // clear errors if we have valid signature manifest
137139
}
138140
}
139141

140142
// signature payload
141143
if (!bundlePayload && obj && obj.mediaType === BUNDLE_V03_MEDIA_TYPE) {
142144
bundlePayload = obj as SerializedBundle;
145+
errors = undefined; // clear errors if we have valid bundle
143146
}
144147

145148
if (bundlePayload && signatureManifestDigest) {
146149
break;
147150
}
148151
}
149152

150-
if (!errors && !bundlePayload) {
151-
throw new Error(`Cannot find signature bundle from cosign command output: ${logs}`);
152-
}
153-
154153
return {
155154
bundle: bundlePayload,
156155
signatureManifestDigest: signatureManifestDigest || signatureManifestFallbackDigest,

src/sigstore/sigstore.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ export class Sigstore {
106106
const errorMessages = signResult.errors.map(e => `- [${e.code}] ${e.message} : ${e.detail}`).join('\n');
107107
throw new Error(`Cosign sign command failed with errors:\n${errorMessages}`);
108108
} else {
109-
throw new Error(`Cosign sign command failed with exit code ${execRes.exitCode}`);
109+
// prettier-ignore
110+
throw new Error(`Cosign sign command failed with: ${execRes.stderr.trim().split(/\r?\n/).filter(line => line.length > 0).pop() ?? 'unknown error'}`);
110111
}
111112
}
112113
const parsedBundle = Sigstore.parseBundle(bundleFromJSON(signResult.bundle));
@@ -209,7 +210,8 @@ export class Sigstore {
209210
throw lastError;
210211
}
211212
} else {
212-
throw new Error(`Cosign verify command failed: ${execRes.stderr}`);
213+
// prettier-ignore
214+
throw new Error(`Cosign verify command failed with: ${execRes.stderr.trim().split(/\r?\n/).filter(line => line.length > 0).pop() ?? 'unknown error'}`);
213215
}
214216
}
215217
}

0 commit comments

Comments
 (0)