Skip to content

Commit 37f6eb8

Browse files
committed
fix: handle empty lines in docker push result
1 parent 239017e commit 37f6eb8

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/lib/docker-utils.spec.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ describe('pushImage', () => {
139139

140140
dockerApiNock.post(`/images/${dockerImageWithTag}/push`).reply(
141141
200,
142-
`{"status":"1.2.3: digest: sha256:17cdfd262dd5ed022949f33c54bdfc006d46799e2e2840022ef0798d58e374f6 size: 2200"}
143-
{"progressDetail":{},"aux":{"Tag":"1.2.3","Digest":"sha256:17cdfd262dd5ed022949f33c54bdfc006d46799e2e2840022ef0798d58e374f6","Size":2200}}`
142+
`
143+
{"status":"1.2.3: digest: sha256:17cdfd262dd5ed022949f33c54bdfc006d46799e2e2840022ef0798d58e374f6 size: 2200"}
144+
145+
{"progressDetail":{},"aux":{"Tag":"1.2.3","Digest":"sha256:17cdfd262dd5ed022949f33c54bdfc006d46799e2e2840022ef0798d58e374f6","Size":2200}}
146+
`
144147
);
145148

146149
await pushImage(dockerImageWithTag, undefined);

src/lib/docker-utils.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ export async function pushImage(existingTag: string, credentials: BasicCredentia
6565
.post<string>(`http://localhost/v1.41/images/${existingTag}/push`, {}, { headers });
6666

6767
for (const line of result.data.split('\n')) {
68-
const parsed = JSON.parse(line);
69-
if (parsed.errorDetail != null || parsed.error != null) {
70-
throw new Error(`Error while pushing image "${existingTag}": "${parsed.error}"`);
68+
// skip empty lines
69+
if (line.trim().length > 0) {
70+
const parsed = JSON.parse(line);
71+
if (parsed.error != null) {
72+
throw new Error(`Error while pushing image "${existingTag}": "${parsed.error}"`);
73+
}
7174
}
7275
}
7376

0 commit comments

Comments
 (0)