From 0eba270ad3a91249f7e53b57024bd6debc83775a Mon Sep 17 00:00:00 2001 From: Paul Natsuo Kishimoto Date: Wed, 27 Jul 2022 11:32:36 +0200 Subject: [PATCH] Handle exception in JDBCBackend.set_data() Partly addresses #296 --- ixmp/backend/jdbc.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ixmp/backend/jdbc.py b/ixmp/backend/jdbc.py index 71408aa23..ea62f9946 100644 --- a/ixmp/backend/jdbc.py +++ b/ixmp/backend/jdbc.py @@ -805,7 +805,16 @@ def set_data(self, ts, region, variable, data, unit, subannual, meta): # Integer so JPype does not produce invalid java.lang.Long. jdata = java.LinkedHashMap({java.Integer(k): v for k, v in data.items()}) - self.jindex[ts].addTimeseries(region, variable, subannual, jdata, unit, meta) + try: + self.jindex[ts].addTimeseries( + region, variable, subannual, jdata, unit, meta + ) + except java.IxException as e: + match = re.search("node '([^']*)' does not exist in the database", str(e)) + if match: + raise ValueError(f"region = {match.group(1)}") from None + else: + raise def set_geo(self, ts, region, variable, subannual, year, value, unit, meta): self.jindex[ts].addGeoData(