Skip to content

Commit e4b4bc3

Browse files
committed
Improved error handling for image loading
1 parent 5be42c4 commit e4b4bc3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/provider/opencv/template-matching-finder.class.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,16 @@ export class TemplateMatchingFinder implements FinderInterface {
118118
}
119119

120120
public async findMatches(matchRequest: MatchRequest, debug: boolean = false): Promise<MatchResult[]> {
121-
const needle = await this.loadNeedle(
122-
await this.source.load(matchRequest.pathToNeedle)
123-
);
124-
if (needle.empty) {
121+
let needle;
122+
try {
123+
const needleInput = await this.source.load(matchRequest.pathToNeedle);
124+
needle = await this.loadNeedle(needleInput);
125+
} catch (e) {
126+
throw new Error(
127+
`Failed to load ${matchRequest.pathToNeedle}. Reason: '${e.message}'.`,
128+
);
129+
}
130+
if (!needle || needle.empty) {
125131
throw new Error(
126132
`Failed to load ${matchRequest.pathToNeedle}, got empty image.`,
127133
);

0 commit comments

Comments
 (0)