Skip to content

Commit c50a910

Browse files
authored
fix: ignore mapped metadata sheet with not default (#678)
fixes #677
1 parent 7086a87 commit c50a910

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/steps/fetch-mapped-metadata.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ export default async function fetchMappedMetadata(state) {
3838
} catch (e) {
3939
throw new PipelineStatusError(500, `failed parsing of ${metadataPath}: ${e.message}`);
4040
}
41-
4241
const { data } = json.default ?? json;
42+
if (!data) {
43+
state.log.info(`default sheet missing in ${metadataPath}`);
44+
return;
45+
}
46+
4347
if (!Array.isArray(data)) {
4448
throw new PipelineStatusError(500, `failed loading of ${metadataPath}: data must be an array`);
4549
}

test/steps/fetch-mapped-metadata.test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { PipelineStatusError } from '../../src/index.js';
1515
import { StaticS3Loader } from '../StaticS3Loader.js';
1616
import fetchMappedMetadata from '../../src/steps/fetch-mapped-metadata.js';
1717
import { FileS3Loader } from '../FileS3Loader.js';
18+
import { Modifiers } from '../../src/utils/modifiers.js';
1819

1920
describe('Fetch Mapped Metadata', () => {
2021
it('parses KV sheet', async () => {
@@ -56,7 +57,7 @@ describe('Fetch Mapped Metadata', () => {
5657
await assert.rejects(promise, new PipelineStatusError(500, 'failed parsing of /mapped/metadata.json: Unexpected token \'h\', "this is no json!" is not valid JSON'));
5758
});
5859

59-
it('throws error on metadata with no data array', async () => {
60+
it('throws error on metadata with invalid data array', async () => {
6061
const promise = fetchMappedMetadata({
6162
log: console,
6263
contentBusId: 'foo-id',
@@ -68,13 +69,33 @@ describe('Fetch Mapped Metadata', () => {
6869
s3Loader: new StaticS3Loader()
6970
.reply('helix-content-bus', 'foo-id/live/mapped/metadata.json', {
7071
status: 200,
71-
body: '{}',
72+
body: '{ "data": "42" }',
7273
headers: new Map(),
7374
}),
7475
});
7576
await assert.rejects(promise, new PipelineStatusError(500, 'failed loading of /mapped/metadata.json: data must be an array'));
7677
});
7778

79+
it('ignores metadata with no data array', async () => {
80+
const state = {
81+
log: console,
82+
contentBusId: 'foo-id',
83+
partition: 'live',
84+
mapped: true,
85+
info: {
86+
path: '/mapped',
87+
},
88+
s3Loader: new StaticS3Loader()
89+
.reply('helix-content-bus', 'foo-id/live/mapped/metadata.json', {
90+
status: 200,
91+
body: '{}',
92+
headers: new Map(),
93+
}),
94+
};
95+
await fetchMappedMetadata(state);
96+
assert.strictEqual(state.mappedMetadata, Modifiers.EMPTY);
97+
});
98+
7899
it('throws error on generic error', async () => {
79100
const promise = fetchMappedMetadata({
80101
log: console,

0 commit comments

Comments
 (0)