[V3 Core] Support already loaded packages #2116

Merged
laggron42 merged 3 commits from patch-24 into V3/release/3.0.0 2018-10-07 23:18:29 +02:00
laggron42 commented 2018-09-09 21:34:16 +02:00 (Migrated from github.com)

Type

  • Bugfix
  • Enhancement
  • New feature

Description of the changes

When loading an already loaded package, this error shows:

Exception during loading of cog
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/redbot/core/core_commands.py", line 96, in _load
    await bot.load_extension(spec)
  File "/usr/local/lib/python3.6/dist-packages/redbot/core/bot.py", line 221, in load_extension
    raise discord.ClientException(f"there is already a package named {name} loaded")
discord.errors.ClientException: there is already a package named audio loaded

This PRs catch the exception and explain what's wrong.
screen shot 2018-09-09 at 21 33 58

### Type - [x] Bugfix - [ ] Enhancement - [ ] New feature ### Description of the changes When loading an already loaded package, this error shows: ```py Exception during loading of cog Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/redbot/core/core_commands.py", line 96, in _load await bot.load_extension(spec) File "/usr/local/lib/python3.6/dist-packages/redbot/core/bot.py", line 221, in load_extension raise discord.ClientException(f"there is already a package named {name} loaded") discord.errors.ClientException: there is already a package named audio loaded ``` This PRs catch the exception and explain what's wrong. ![screen shot 2018-09-09 at 21 33 58](https://user-images.githubusercontent.com/23153234/45268103-1408db00-b478-11e8-8b83-6fea9ce342ac.png)
palmtree5 (Migrated from github.com) reviewed 2018-09-09 21:34:16 +02:00
tekulvw (Migrated from github.com) reviewed 2018-09-09 21:34:16 +02:00
Twentysix26 (Migrated from github.com) reviewed 2018-09-09 21:34:16 +02:00
Kowlin (Migrated from github.com) reviewed 2018-09-09 21:34:16 +02:00
Tobotimus commented 2018-09-10 02:23:55 +02:00 (Migrated from github.com)

Thanks for opening this Pull Request @retke! I've been wanting this for a while 😄

Thanks for opening this Pull Request @retke! I've been wanting this for a while :smile:
calebj (Migrated from github.com) requested changes 2018-09-12 02:17:56 +02:00
calebj (Migrated from github.com) left a comment

While you're working on this, I think you should make the behavior of Red's Bot.load_extension() match upstream. Since the return value of that function is always None, it doesn't hurt to enhance it in Red. I suggest having it return the initialized cog object upon success, None if it's already loaded, or ClientException if there is no setup() function like d.py does.

The reason for the suggested change is: currently, Red's load_extension throws the same exception for both when the module is missing a setup() function AND when the cog is already loaded. Matching the upstream behavior removes this ambiguity and allows your code to distinguish between the failure cases.

While you're working on this, I think you should make the behavior of Red's Bot.load_extension() match upstream. Since the return value of that function is always None, it doesn't hurt to enhance it in Red. I suggest having it return the initialized cog object upon success, None if it's already loaded, or ClientException if there is no setup() function like d.py does. The reason for the suggested change is: currently, Red's load_extension throws the same exception for both when the module is missing a setup() function AND when the cog is already loaded. Matching the upstream behavior removes this ambiguity and allows your code to distinguish between the failure cases.
Tobotimus (Migrated from github.com) approved these changes 2018-10-07 23:18:00 +02:00
Tobotimus (Migrated from github.com) left a comment

Thanks @retke 😃

Thanks @retke :smiley:
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!2116
No description provided.