Skip to content

Erro lidando com evento None AttributeError: 'NoneType' object has no attribute 'name' #2

@gbromulorosa

Description

@gbromulorosa

Quando o protocolo de eventos tenta processar um event None, este levanta AttributeError ao invés de EventParsingException

{"level": "ERROR", "message": "Error in parser schema procedure", "context": {"id": null, "flow_id": null, "event_name": null}, "extra": {"event": "null"}, "stacktrace": "\"Traceback (most recent call last):\\n  File \\\"/home/romulorosa/.local/lib/python3.7/site-packages/events_protocol/server/parser/event_processor.py\\\", line 37, in parse_event\\n    event = cls.event_validator.from_json(str_event)\\n  File \\\"/home/romulorosa/.local/lib/python3.7/site-packages/events_protocol/core/model/base.py\\\", line 86, in from_json\\n    _data = json.loads(data)\\n  File \\\"/usr/lib/python3.7/json/__init__.py\\\", line 341, in loads\\n    raise TypeError(f'the JSON object must be str, bytes or bytearray, '\\nTypeError: the JSON object must be str, bytes or bytearray, not NoneType\""}
Traceback (most recent call last):
  File "/home/romulorosa/.local/lib/python3.7/site-packages/events_protocol/server/parser/event_processor.py", line 37, in parse_event
    event = cls.event_validator.from_json(str_event)
  File "/home/romulorosa/.local/lib/python3.7/site-packages/events_protocol/core/model/base.py", line 86, in from_json
    _data = json.loads(data)
  File "/usr/lib/python3.7/json/__init__.py", line 341, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/romulorosa/.local/lib/python3.7/site-packages/events_protocol/server/parser/event_processor.py", line 26, in process_event
    event: Event = cls.parse_event(raw_event)
  File "/home/romulorosa/.local/lib/python3.7/site-packages/events_protocol/server/parser/event_processor.py", line 53, in parse_event
    raise EventParsingException(dict(error="Unknown error"))
events_protocol.core.exception.EventParsingException: ('INVALID_COMMUNICATION_PROTOCOL', {'error': 'Unknown error'}, <EventErrorType.BAD_PROTOCOL: 'badProtocol'>, False)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/romulorosa/.local/lib/python3.7/site-packages/events_protocol/server/parser/event_processor.py", line 32, in process_event
    return EventBuilder.error_for(exception, event).to_json()
  File "/home/romulorosa/.local/lib/python3.7/site-packages/events_protocol/core/builder.py", line 26, in error_for
    if event.name
AttributeError: 'NoneType' object has no attribute 'name'

Código de replicação

from events_protocol.server.parser.event_processor import EventProcessor
EventProcessor.process_event(None)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions