@@ -221,14 +221,59 @@ Some examples of the information logged on various levels:
221221- all unexpected exceptions
222222- all command responses
223223
224- Application development
225- -----------------------
224+ Error handling and development
225+ ------------------------------
226226
227227As described in the previous sections, under normal conditions, all commands
228228return response wrapper objects. If an error occured it is indicated by the
229229error code in the response object and/or the lack of parsed parameters. These
230230errors have to be explicitly handled in the application.
231231
232- The command line programs implemented in the
233- `Instrumentman <https://github.com/MrClock8163/Instrumentman >`_ package can be
234- used as reference examples.
232+ The simplest solution is to check if the error code is simple ``OK ``:
233+
234+ .. code-block :: python
235+
236+ response = tps.ftr.setup_listing()
237+ if response.error != GeoComCode.OK :
238+ # handle error
239+
240+ When static type checkers are involved, it might be necessary check for both
241+ the error code and the existence of the parsed parameters.
242+
243+ .. code-block :: python
244+
245+ response = tps.ftr.setup_listing()
246+ if response.error != GeoComCode.OK and response.params is not None :
247+ # handle error
248+
249+ Different commands return different errors signaling the various issues.
250+ Some errors might be recoverable, some might not.
251+
252+ .. code-block :: python
253+
254+ response = tps.aut.fine_adjust(1 , 1 )
255+ if response.error == GeoComCode.AUT_NOT_ENABLED :
256+ response = tps.aus.switch_user_atr(True )
257+ if response.error == GeoComCode.OK :
258+ reponse = tps.aut.fine_adjust(1 , 1 )
259+ else :
260+ print (" Cannot activate ATR" )
261+ exit (1 )
262+
263+ if response.error == GeoComCode.AUT_NO_TARGET :
264+ response_ps = tps.aut.powersearch_next(' CLOCKWISE' , True )
265+ if response_ps.error != GeoComCode.OK :
266+ print (" Could not find target" )
267+ exit (1 )
268+ else :
269+ response = tps.aut.fine_adjust(1 , 1 )
270+
271+ if response.error != GeoComCode.OK :
272+ print (" ATR fine adjustment failed, and could not reackquire target" )
273+ exit (1 )
274+
275+ .. note ::
276+
277+ The command line programs implemented in the
278+ `Instrumentman <https://github.com/MrClock8163/Instrumentman >`_ package can
279+ be used as reference examples for development.
0 commit comments