File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ #
3+ # Copyright (C) 2026 CERN.
4+ #
5+ # CDS-Doson is free software; you can redistribute it and/or modify it under
6+ # the terms of the MIT License; see LICENSE file for more details.
7+
8+ """CDS-Dojson exceptions module."""
9+
10+
11+ class ModelMissingException (Exception ):
12+ """CDSDoJSONException class."""
13+
14+ description = "[Record did not match any available model]"
15+
16+
17+ class MultipleModelsException (Exception ):
18+ """CDSDoJSONException class."""
19+
Original file line number Diff line number Diff line change 2828from invenio_query_parser .walkers .match_unit import MatchUnit
2929from invenio_query_parser .walkers .pypeg_to_ast import PypegConverter
3030
31+ from cds_dojson .exceptions import ModelMissingException , MultipleModelsException
32+
3133# Cache of (name, model, parsed_query_ast) tuples keyed by entry_point_group.
3234# Entry points and their query ASTs are static for the lifetime of a process,
3335# so scanning importlib_metadata and re-parsing pypeg2 queries on every call
@@ -87,20 +89,20 @@ def matcher(record, entry_point_group):
8789 name , model
8890 ))
8991 _matches .append ([name , model ])
90- try :
9192 if len (_matches ) > 1 :
9293 logger .error (
9394 ("Found more than one matches `{0}`, we'll use {1}"
9495 " for record {2}." ).format (
9596 _matches , default , record
9697 )
9798 )
98- return default
99- return _matches [0 ][1 ]
100- except IndexError :
101- logger .warning (
102- "Model *not* found, fallback to default {0} for record {1}" .format (
103- default , record
99+ raise MultipleModelsException (
100+ "Found more than one models {0} for record {1}" .format (
101+ _matches , record ))
102+ if len (_matches ) == 0 :
103+ logger .warning (
104+ "Model *not* found, fallback to default {0} for record {1}" .format (
105+ default , record
106+ )
104107 )
105- )
106- return default
108+ raise ModelMissingException ("Model *not* found" )
You can’t perform that action at this time.
0 commit comments