Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix several TypeErrors in generate_dts() with unknown mon values #873

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

sprintnudel
Copy link
Contributor

@sprintnudel sprintnudel commented Feb 6, 2023

Description

When mon without encounter values generate an alarm calculate_cp(), calculate_candy_cost() and calculate_stardust_cost() called from within generate_dts() fail with an exception, since the values are Unknown.TINY strings and not ints.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (would cause existing functionality to change)

Motivation and Context

Users reported TypeErrors with MonEvent:

1

2023-02-06 18:08:24,809 [ERROR][ pokealarm][  man_1] Encountered error during processing: TypeError: unsupported operand type(s) for +: 'int' and 'str'
2023-02-06 18:08:24,810 [ERROR][ pokealarm][  man_1] Stack trace:
 Traceback (most recent call last):
  File "/opt/PokeAlarm/PokeAlarm/Manager.py", line 651, in run
    self.process_monster(event)
  File "/opt/PokeAlarm/PokeAlarm/Manager.py", line 817, in process_monster
    self._notify_alarms(mon, rule.alarm_names, "pokemon_alert")
  File "/opt/PokeAlarm/PokeAlarm/Manager.py", line 727, in _notify_alarms
    dts = event.generate_dts(self.__locale, self.__timezone, self.__units)
  File "/opt/PokeAlarm/PokeAlarm/Events/MonEvent.py", line 329, in generate_dts
    50,
  File "/opt/PokeAlarm/PokeAlarm/Utils.py", line 544, in calculate_cp
    cp_base = calculate_cp_base(monster_id, form_id, atk, de, sta)
  File "/opt/PokeAlarm/PokeAlarm/Utils.py", line 554, in calculate_cp_base
    / 10
TypeError: unsupported operand type(s) for +: 'int' and 'str'

2

2023-04-08 16:38:52,569 [ERROR][ pokealarm][ manager_0] Stack trace:
 Traceback (most recent call last):
  File "/home/user001/PokeAlarm/PokeAlarm/Manager.py", line 615, in run
    self.process_monster(event)
  File "/home/user001/PokeAlarm/PokeAlarm/Manager.py", line 772, in process_monster
    self._notify_alarms(mon, rule.alarm_names, "pokemon_alert")
  File "/home/user001/PokeAlarm/PokeAlarm/Manager.py", line 686, in _notify_alarms
    dts = event.generate_dts(self.locale, self.timezone, self.__units)
  File "/home/user001/PokeAlarm/PokeAlarm/Events/MonEvent.py", line 392, in generate_dts
    "stardust_cost": calculate_stardust_cost(self.mon_lvl, 50),
  File "/home/user001/PokeAlarm/PokeAlarm/Utils.py", line 774, in calculate_stardust_cost
    if start_level >= target_level:
TypeError: '>=' not supported between instances of 'str' and 'int'

3

2023-04-08 20:13:52,760 [ERROR][ pokealarm][ manager_0] Stack trace:
 Traceback (most recent call last):
  File "/home/user001/pokealarm/PokeAlarm/Manager.py", line 616, in run
    self.process_monster(event)
  File "/home/user001/pokealarm/PokeAlarm/Manager.py", line 773, in process_monster
    self._notify_alarms(mon, rule.alarm_names, "pokemon_alert")
  File "/home/user001/pokealarm/PokeAlarm/Manager.py", line 687, in _notify_alarms
    dts = event.generate_dts(self.locale, self.timezone, self.__units)
  File "/home/user001/pokealarm/PokeAlarm/Events/MonEvent.py", line 454, in generate_dts
    "ultra_stardust": f"{self.ultra_stardust:,}".replace(",", " "),
ValueError: Cannot specify ',' with 's'.

How Has This Been Tested?

Waiting for feedback from original reporters.

Wiki Update

  • This change requires an update to the Wiki.
  • This change does not require an update to the Wiki.

@sprintnudel
Copy link
Contributor Author

This is a follow up issue discovered after the fix from #870 was applied.

Copy link
Collaborator

@LegitDongo LegitDongo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's still a bug with monsters that don't have IVs

 Traceback (most recent call last):
  File "//workspace/pokealarm/PokeAlarm/Manager.py", line 651, in run
    self.process_monster(event)
  File "//workspace/pokealarm/PokeAlarm/Manager.py", line 817, in process_monster
    self._notify_alarms(mon, rule.alarm_names, "pokemon_alert")
  File "//workspace/pokealarm/PokeAlarm/Manager.py", line 727, in _notify_alarms
    dts = event.generate_dts(self.__locale, self.__timezone, self.__units)
  File "//workspace/pokealarm/PokeAlarm/Events/MonEvent.py", line 252, in generate_dts
    if int(self.great_level) == self.great_level:
ValueError: invalid literal for int() with base 10: '???'

This is with the default alarm

@sprintnudel
Copy link
Contributor Author

Seems I forgot to push the fix... 💯

@sprintnudel sprintnudel changed the title fix TypeError in generate_dts() with unknown IVs fix several TypeErrors in generate_dts() with unknown mon values Apr 8, 2023
@sprintnudel
Copy link
Contributor Author

Added another commit to deal with unknown mon level

@billyjbryant
Copy link
Collaborator

Looks like there's still a bug with monsters that don't have IVs

 Traceback (most recent call last):
  File "//workspace/pokealarm/PokeAlarm/Manager.py", line 651, in run
    self.process_monster(event)
  File "//workspace/pokealarm/PokeAlarm/Manager.py", line 817, in process_monster
    self._notify_alarms(mon, rule.alarm_names, "pokemon_alert")
  File "//workspace/pokealarm/PokeAlarm/Manager.py", line 727, in _notify_alarms
    dts = event.generate_dts(self.__locale, self.__timezone, self.__units)
  File "//workspace/pokealarm/PokeAlarm/Events/MonEvent.py", line 252, in generate_dts
    if int(self.great_level) == self.great_level:
ValueError: invalid literal for int() with base 10: '???'

This is with the default alarm

@LegitDongo : Is this now resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium type: bug Unexpected or incorrect behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants