modlog.create_case() should raise exception not fail silently when passing invalid action_type #3346

Closed
opened 2020-01-11 22:52:51 +01:00 by Bakersbakebread · 3 comments
Bakersbakebread commented 2020-01-11 22:52:51 +01:00 (Migrated from github.com)

Current behaviour is to return None when an invalid action_type is passed.

 # redbot/core/modlog.py
case_type = await get_casetype(action_type, guild)
    if case_type is None:
        return

Quick link

Current behaviour is to `return None` when an invalid `action_type` is passed. ```py # redbot/core/modlog.py case_type = await get_casetype(action_type, guild) if case_type is None: return ``` [Quick link](https://github.com/Cog-Creators/Red-DiscordBot/blob/V3/develop/redbot/core/modlog.py#L750)
mikeshardmind commented 2020-01-12 00:10:36 +01:00 (Migrated from github.com)

Not sure I agree with that, but changing that would be breaking so there's plenty of time for that to be discussed.

Not sure I agree with that, but changing that would be breaking so there's plenty of time for that to be discussed.
Jackenmen commented 2021-04-10 10:54:42 +02:00 (Migrated from github.com)

While it could be a tiny bit better (easier to detect a problem in your code and more Pythonic perhaps) if this raised an exception, it returning None is documented quite clearly and there's only one case it can return it in so I don't think it warrants possibly breaking someone by it just to make the API a bit cleaner.

While it could be a tiny bit better (easier to detect a problem in your code and more Pythonic perhaps) if this raised an exception, it returning `None` is documented quite clearly and there's only one case it can return it in so I don't think it warrants possibly breaking someone by it just to make the API a bit cleaner.
Jackenmen commented 2021-10-12 17:40:49 +02:00 (Migrated from github.com)

While it could be a tiny bit better (easier to detect a problem in your code and more Pythonic perhaps) if this raised an exception, it returning None is documented quite clearly and there's only one case it can return it in so I don't think it warrants possibly breaking someone by it just to make the API a bit cleaner.

This comment of mine doesn't make a lot of sense 🤔 I think I thought that this issue is referring to modlog.get_casetype(), not modlog.create_case()... So ignore my previous comment as I think that this DOES make sense to do as the breakage is minimal and I doubt that anyone would intentionally pass invalid action type to create_case().

With that out of the way... This should be quite simple, it just requires raising ValueError rather than returning. PRs are welcome.

> While it could be a tiny bit better (easier to detect a problem in your code and more Pythonic perhaps) if this raised an exception, it returning `None` is documented quite clearly and there's only one case it can return it in so I don't think it warrants possibly breaking someone by it just to make the API a bit cleaner. This comment of mine doesn't make a lot of sense 🤔 I think I thought that this issue is referring to `modlog.get_casetype()`, not `modlog.create_case()`... So ignore my previous comment as I think that this DOES make sense to do as the breakage is minimal and I doubt that anyone would intentionally pass invalid action type to `create_case()`. With that out of the way... This should be quite simple, it just requires raising `ValueError` rather than returning. PRs are welcome.
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#3346
No description provided.