Skip to content

Weather widget crashes: ValueError: invalid literal for int() with base 10: '100.0' #689

@alex-sitnikov

Description

@alex-sitnikov

Description

YASB v1.8.7 crashes immediately on startup due to the weather widget failing to parse precipitation chance values.

Error

Traceback (most recent call last):
  File "D:\a\yasb\yasb\src\core\widgets\yasb\weather.py", line 69, in <lambda>
  File "D:\a\yasb\yasb\src\core\widgets\yasb\weather.py", line 465, in _update_label
ValueError: invalid literal for int() with base 10: '100.0'

Root Cause

In _update_label, the tooltip code does:

rain = self._weather_data["{hourly_chance_of_rain}"]
snow = self._weather_data["{hourly_chance_of_snow}"]

if rain != "N/A" and snow != "N/A" and (int(rain.rstrip("%")) > 0 or int(snow.rstrip("%")) > 0):

The weatherapi.com API sometimes returns chance_of_rain / chance_of_snow as a float (e.g. 100.0) instead of an integer. When process_weather_data formats this as "100.0%", and then _update_label tries int("100.0"), it throws a ValueError.

Suggested Fix

Replace int(rain.rstrip("%")) with int(float(rain.rstrip("%"))) (same for snow). This handles both integer and float string representations.

if rain != "N/A" and snow != "N/A" and (int(float(rain.rstrip("%"))) > 0 or int(float(snow.rstrip("%"))) > 0):
    precip: list[str] = []
    if int(float(rain.rstrip("%"))) > 0:
        precip.append(f"Rain {rain}")
    if int(float(snow.rstrip("%"))) > 0:
        precip.append(f"Snow {snow}")

Environment

  • YASB version: 1.8.7
  • Installed via: Scoop
  • OS: Windows 11
  • Weather API: weatherapi.com

Reproduction

The crash is 100% reproducible when chance_of_rain or chance_of_snow is returned as 100.0 by the API. The crash happens every 10 minutes when weather data is fetched, and also on startup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already exists

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions