@@ -222,17 +222,20 @@ def main():
222
222
madx_commands_string = get_madx_script_from_definition_dataframe (
223
223
deltas_df = knob_definition , lsa_knob = lsa_knob , trim = trim_value
224
224
)
225
- except (OSError , IOError ):
225
+
226
+ except (OSError , IOError ): # raised by pjlsa if knob not found
226
227
LOG .warning (f"Could not find knob '{ lsa_knob } ' in the given optics '{ lsa_optics } ' - skipping" )
227
228
unfound_knobs .append (lsa_knob )
228
229
229
- definition_file = f"{ lsa_knob .replace ('/' , '_' )} _definition.tfs"
230
- LOG .debug (f"Writing knob definition TFS file at '{ definition_file } '" )
231
- tfs .write (definition_file , knob_definition , save_index = True )
230
+ else : # we've managed to find knobs
231
+ # Don't write this in the try block, as it could raise IOError when failing
232
+ definition_file = f"{ lsa_knob .replace ('/' , '_' )} _definition.tfs"
233
+ LOG .debug (f"Writing knob definition TFS file at '{ definition_file } '" )
234
+ tfs .write (definition_file , knob_definition , save_index = True )
232
235
233
- madx_file = f"{ lsa_knob .replace ('/' , '_' )} _knob.madx"
234
- LOG .debug (f"Writing MAD-X commands to file '{ madx_file } '" )
235
- Path (madx_file ).write_text (madx_commands_string )
236
+ madx_file = f"{ lsa_knob .replace ('/' , '_' )} _knob.madx"
237
+ LOG .debug (f"Writing MAD-X commands to file '{ madx_file } '" )
238
+ Path (madx_file ).write_text (madx_commands_string )
236
239
237
240
if unfound_knobs :
238
241
LOG .info (f"The following knobs could not be found in the '{ lsa_optics } ' optics: \n \t \t " + "\n \t \t " .join (unfound_knobs ))
0 commit comments