Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions geemap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5567,7 +5567,7 @@ def stac_tile(
try:
percentile_2 = min([stats[s]["percentile_2"] for s in stats])
percentile_98 = max([stats[s]["percentile_98"] for s in stats])
except:
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The try block performs dictionary lookups and calls min()/max() on list comprehensions. These operations can raise KeyError (if a key is missing) or ValueError (if the list is empty). Catching these specific exceptions is preferred over the broad Exception class to avoid masking unrelated logic errors.

except (KeyError, ValueError):

percentile_2 = min(
[
stats[s][list(stats[s].keys())[0]]["percentile_2"]
Expand Down Expand Up @@ -11780,7 +11780,7 @@ def classify(
cmap = "Blues"
try:
cmap = plt.get_cmap(cmap, k)
except:
except Exception:
cmap = plt.cm.get_cmap(cmap, k)
if colors is None:
colors = [mpl.colors.rgb2hex(cmap(i))[1:] for i in range(cmap.N)]
Expand Down Expand Up @@ -12537,7 +12537,7 @@ def get_palette_colors(
"""
try:
cmap = plt.get_cmap(cmap_name, n_class)
except:
except Exception:
cmap = plt.cm.get_cmap(cmap_name, n_class)
colors = [mpl.colors.rgb2hex(cmap(i))[1:] for i in range(cmap.N)]
if hashtag:
Expand Down
2 changes: 1 addition & 1 deletion geemap/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ def js_to_python(
try:
if (line.replace(" ", ""))[line.find("!") + 1] != "=":
line = line.replace("!", "not ")
except:
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The string indexing logic [line.find("!") + 1] is prone to an IndexError if the '!' character is at the end of the string or if the resulting string is empty. It is better to catch IndexError specifically rather than the broad Exception class.

except IndexError:

print("continue...")
Comment on lines +610 to 611

line = line.rstrip()
Expand Down
4 changes: 2 additions & 2 deletions geemap/coreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def widget_template(

try:
toolbar_button = ipywidgets.ToggleButton(**widget_args)
except:
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The failure here is likely due to an unsupported keyword argument in ipywidgets.ToggleButton (such as layout in older versions), which raises a TypeError. Catching TypeError specifically is more precise for this version-compatibility check.

except TypeError:

widget_args.pop("layout")
toolbar_button = ipywidgets.ToggleButton(**widget_args)
toolbar_button.layout.width = "28px"
Comment on lines 547 to 552
Expand All @@ -555,7 +555,7 @@ def widget_template(

try:
close_button = ipywidgets.ToggleButton(**close_button_args)
except:
except Exception:
close_button_args.pop("layout")
close_button = ipywidgets.ToggleButton(**close_button_args)
close_button.layout.width = "28px"
Comment on lines 556 to 561
Expand Down
2 changes: 1 addition & 1 deletion geemap/geemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4372,7 +4372,7 @@ def add_labels(

try:
size = int(font_size.replace("pt", ""))
except:
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Since the try block specifically targets a potential failure in int() conversion, catching ValueError is more precise than catching the base Exception class. This is especially relevant here as you are re-raising a ValueError with a custom message.

except ValueError:

raise ValueError("font_size must be something like '10pt'")
Comment on lines +4375 to 4376

labels = []
Expand Down
2 changes: 1 addition & 1 deletion geemap/map_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def _normalize_color_to_hex(self, color: str | tuple) -> str:
if isinstance(color, tuple):
try:
return f"#{coreutils.rgb_to_hex(color)}"
except:
except Exception:
raise ValueError(f"Unable to convert rgb value to hex: {color}")
Comment on lines +417 to 418
elif re.search(r"^(?:[0-9a-fA-F]{3}){1,2}(?:[0-9a-fA-F]{1,2})?$", color):
# Add a # for hexadecimal strings of length 3 or 6, with optional
Expand Down
2 changes: 1 addition & 1 deletion geemap/timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

try:
from PIL import Image, ImageDraw, ImageFont, ImageSequence
except:
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

When handling optional dependency imports, it is best practice to catch ImportError specifically. Catching the broad Exception class can mask other unexpected errors that might occur during module initialization.

Suggested change
except Exception:
except ImportError:

pass
Comment on lines +30 to 31


Expand Down
Loading