chiefwigms / picobrew_pico

MIT License
149 stars 63 forks source link

Z Manual Brew Session Fails Parsing #264

Closed tmack8001 closed 2 years ago

tmack8001 commented 3 years ago

If the session_type integer in the session file doesn't match an enum value then the PUT during bootup fails. We should just treat any and all invalid sessions after the latest CLEAN as a "dirty" session if we truly can't tell what it was. This way the bootup sequence isn't aborted with a 500 error like this and we get the best guess as to what this session is.

Also we should support 14 as a value... I guess and relay that as a MANUAL brew? Really not sure why anyone would manual brew in the Z ... but sure let's support it or at least not destroy the server interface.

Mar 13 03:39:47 raspberrypi rc.local[552]: [2021-03-13 03:39:47,227] ERROR in session_parser: An exception occurred parsing session file /picobrew_pico/app/sessions/brew/archive/20201026_184328#<z-uid>#af1e4e074575420e96c60168c6b398e9#MANUAL_BREW#14.json
Mar 13 03:39:47 raspberrypi rc.local[552]: [2021-03-13 03:39:47,227] ERROR in session_parser: Expecting value: line 2 column 1 (char 1)
Mar 13 03:39:47 raspberrypi rc.local[552]: [2021-03-13 03:39:47,400] ERROR in app: Exception on /Vendors/input.cshtml [PUT]
Mar 13 03:39:47 raspberrypi rc.local[552]: ValueError: 14 is not a valid SessionType
Mar 13 03:39:47 raspberrypi rc.local[552]: During handling of the above exception, another exception occurred:
Mar 13 03:39:47 raspberrypi rc.local[552]: Traceback (most recent call last):
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 2447, in wsgi_app
Mar 13 03:39:47 raspberrypi rc.local[552]:     response = self.full_dispatch_request()
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1952, in full_dispatch_request
Mar 13 03:39:47 raspberrypi rc.local[552]:     rv = self.handle_user_exception(e)
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/local/lib/python3.7/dist-packages/flask_cors/extension.py", line 165, in wrapped_function
Mar 13 03:39:47 raspberrypi rc.local[552]:     return cors_after_request(app.make_response(f(*args, **kwargs)))
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1821, in handle_user_exception
Mar 13 03:39:47 raspberrypi rc.local[552]:     reraise(exc_type, exc_value, tb)
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/local/lib/python3.7/dist-packages/flask/_compat.py", line 39, in reraise
Mar 13 03:39:47 raspberrypi rc.local[552]:     raise value
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1950, in full_dispatch_request
Mar 13 03:39:47 raspberrypi rc.local[552]:     rv = self.dispatch_request()
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1936, in dispatch_request
Mar 13 03:39:47 raspberrypi rc.local[552]:     return self.view_functions[rule.endpoint](**req.view_args)
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/local/lib/python3.7/dist-packages/webargs/core.py", line 443, in wrapper
Mar 13 03:39:47 raspberrypi rc.local[552]:     return func(*args, **kwargs)
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/picobrew_pico/app/main/routes_zseries_api.py", line 114, in process_zseries_put_request
Mar 13 03:39:47 raspberrypi rc.local[552]:     return process_zstate(request)
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/picobrew_pico/app/main/routes_zseries_api.py", line 185, in process_zstate
Mar 13 03:39:47 raspberrypi rc.local[552]:     "DirtySessionsSinceClean": dirty_sessions_since_clean(uid),
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/picobrew_pico/app/main/routes_zseries_api.py", line 201, in dirty_sessions_since_clean
Mar 13 03:39:47 raspberrypi rc.local[552]:     session_type = SessionType(s['type'])
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/lib/python3.7/enum.py", line 310, in __call__
Mar 13 03:39:47 raspberrypi rc.local[552]:     return cls.__new__(cls, value)
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/lib/python3.7/enum.py", line 564, in __new__
Mar 13 03:39:47 raspberrypi rc.local[552]:     raise exc
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/lib/python3.7/enum.py", line 548, in __new__
Mar 13 03:39:47 raspberrypi rc.local[552]:     result = cls._missing_(value)
Mar 13 03:39:47 raspberrypi rc.local[552]:   File "/usr/lib/python3.7/enum.py", line 577, in _missing_
Mar 13 03:39:47 raspberrypi rc.local[552]:     raise ValueError("%r is not a valid %s" % (value, cls.__name__))
Mar 13 03:39:47 raspberrypi rc.local[552]: ValueError: 14 is not a valid SessionType
Mar 13 03:39:47 raspberrypi rc.local[552]: 127.0.0.1 - - [13/Mar/2021 03:39:47] "PUT /Vendors/input.cshtml?type=ZState&token=<z-uid> HTTP/1.0" 500 -
tmack8001 commented 3 years ago

Pushed through a new enum value with https://github.com/chiefwigms/picobrew_pico/commit/283f96457073be24b38495dee8ed136d024f08cc. Leaving this open for now to track fixing the logic of the "check clean" to allow for invalid parsed sessions to be treated as "dirty"