diff --git a/.changeset/search-tasty-crews-tie.md b/.changeset/search-tasty-crews-tie.md new file mode 100644 index 0000000000..3d5b1ad1b0 --- /dev/null +++ b/.changeset/search-tasty-crews-tie.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-search-backend-node': patch +--- + +Handle errors in collators and decorators and log them. diff --git a/plugins/search-backend-node/src/IndexBuilder.ts b/plugins/search-backend-node/src/IndexBuilder.ts index 5b446c6483..0cabb61f38 100644 --- a/plugins/search-backend-node/src/IndexBuilder.ts +++ b/plugins/search-backend-node/src/IndexBuilder.ts @@ -14,7 +14,11 @@ * limitations under the License. */ -import { DocumentCollator, DocumentDecorator } from '@backstage/search-common'; +import { + DocumentCollator, + DocumentDecorator, + IndexableDocument, +} from '@backstage/search-common'; import { Logger } from 'winston'; import { Scheduler } from './index'; import { @@ -105,12 +109,29 @@ export class IndexBuilder { this.logger.debug( `Collating documents for ${type} via ${this.collators[type].collate.constructor.name}`, ); - let documents = await this.collators[type].collate.execute(); + let documents: IndexableDocument[]; + + try { + documents = await this.collators[type].collate.execute(); + } catch (e) { + this.logger.error( + `Collating documents for ${type} via ${this.collators[type].collate.constructor.name} failed: ${e}`, + ); + return; + } + for (let i = 0; i < decorators.length; i++) { this.logger.debug( `Decorating ${type} documents via ${decorators[i].constructor.name}`, ); - documents = await decorators[i].execute(documents); + try { + documents = await decorators[i].execute(documents); + } catch (e) { + this.logger.error( + `Decorating ${type} documents via ${decorators[i].constructor.name} failed: ${e}`, + ); + return; + } } if (!documents || documents.length === 0) {