Skip to content

Commit a3de12a

Browse files
committed
Improve error logging in case of KeyError and AttributeError
Signed-off-by: Enrico Usai <[email protected]>
1 parent c0af586 commit a3de12a

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

cookbooks/aws-parallelcluster-slurm/files/default/head_node_slurm/slurm/pcluster_fleet_config_generator.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import copy
1414
import json
1515
import logging
16+
import traceback
1617

1718
import yaml
1819

@@ -139,11 +140,13 @@ def generate_fleet_config_file(output_file, input_file):
139140

140141
fleet_config[queue][compute_resource] = config_for_fleet
141142

142-
except KeyError as e:
143-
message = f"Unable to find key {e} in the configuration"
144-
message += f" of queue: {queue}" if queue else " file"
145-
message += f", compute resource: {compute_resource}" if compute_resource else ""
146-
143+
except (KeyError, AttributeError) as e:
144+
if isinstance(e, KeyError):
145+
message = f"Unable to find key {e} in the configuration file."
146+
else:
147+
message = f"Error parsing configuration file. {e}. {traceback.format_exc()}."
148+
message += f" Queue: {queue}" if queue else ""
149+
message += f" Compute resource: {compute_resource}" if compute_resource else ""
147150
log.error(message)
148151
raise CriticalError(message)
149152

test/unit/slurm/test_fleet_config_generator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
(
3030
{"Scheduling": {"SlurmQueues": [{"Name": "q1"}]}},
3131
CriticalError,
32-
"Unable to find key 'ComputeResources' in the configuration of queue: q1",
32+
"Unable to find key 'ComputeResources' in the configuration file. Queue: q1",
3333
),
3434
(
3535
{"Scheduling": {"SlurmQueues": [{"Name": "q1", "CapacityType": "ONDEMAND"}]}},
3636
CriticalError,
37-
"Unable to find key 'ComputeResources' in the configuration of queue: q1",
37+
"Unable to find key 'ComputeResources' in the configuration file. Queue: q1",
3838
),
3939
({"Scheduling": {"SlurmQueues": [{"Name": "q1", "CapacityType": "SPOT", "ComputeResources": []}]}}, None, None),
4040
(
@@ -44,7 +44,7 @@
4444
}
4545
},
4646
CriticalError,
47-
"Unable to find key 'Name' in the configuration of queue: q1",
47+
"Unable to find key 'Name' in the configuration file. Queue: q1",
4848
),
4949
(
5050
{
@@ -137,7 +137,7 @@
137137
}
138138
},
139139
CriticalError,
140-
"Unable to find key 'SpotPrice' in the configuration of queue: q1, compute resource: cr1",
140+
"Unable to find key 'SpotPrice' in the configuration file. Queue: q1 Compute resource: cr1",
141141
),
142142
(
143143
{
@@ -172,7 +172,7 @@
172172
}
173173
},
174174
CriticalError,
175-
"Unable to find key 'Networking' in the configuration of queue: q1, compute resource: cr1",
175+
"Unable to find key 'Networking' in the configuration file. Queue: q1 Compute resource: cr1",
176176
),
177177
(
178178
{
@@ -190,7 +190,7 @@
190190
}
191191
},
192192
CriticalError,
193-
"Unable to find key 'SubnetIds' in the configuration of queue: q1, compute resource: cr1",
193+
"Unable to find key 'SubnetIds' in the configuration file. Queue: q1 Compute resource: cr1",
194194
),
195195
(
196196
{

0 commit comments

Comments
 (0)