[Permissions] Schema checking gives unrelated errors #3185

Closed
opened 2019-12-12 14:59:35 +01:00 by Jackenmen · 7 comments
Jackenmen commented 2019-12-12 14:59:35 +01:00 (Migrated from github.com)

Command bugs

Command name

[p]permissions acl setglobal/setserver/updateglobal/updateserver

What cog is this command from?

Permissions

What were you expecting to happen?

Either get error about incorrect type of key or have Permissions automatically convert int to str.

What actually happened?

I got error "Top-level keys must be either COG or COMMAND"

How can we reproduce this issue?

  1. Create such yaml permissions file:
COMMAND:
  8:
    176070082584248320: true
  1. Upload it using one of the commands: [p]permissions acl setglobal/setserver/updateglobal/updateserver
  2. See error.

The above is reproduction for issue that was already fixed, but the unrelated errors can still happen for yaml file like this:

COMMAND:
  ping:
    default_but_spelt_incorrectly: false
# Command bugs #### Command name `[p]permissions acl setglobal/setserver/updateglobal/updateserver` #### What cog is this command from? Permissions #### What were you expecting to happen? Either get error about incorrect type of key or have Permissions automatically convert int to str. #### What actually happened? I got error "Top-level keys must be either `COG` or `COMMAND`" #### How can we reproduce this issue? 1. Create such yaml permissions file: ```yaml COMMAND: 8: 176070082584248320: true ``` 2. Upload it using one of the commands: `[p]permissions acl setglobal/setserver/updateglobal/updateserver` 3. See error. --- The above is reproduction for issue that was already fixed, but the unrelated errors can still happen for yaml file like this: ```yaml COMMAND: ping: default_but_spelt_incorrectly: false ```
mikeshardmind commented 2019-12-12 18:40:09 +01:00 (Migrated from github.com)

For anyone currently experiencing this issue:

Wrapping a numeric command in quotes will work fine.

COMMAND:
  "8":
    176070082584248320: true

I'm not sure if we should actually consider this as a bug with permissions, this was intended to catch a mistake like

COMMAND:
  176070082584248320: true

and quoting the command makes sure it was an explicit choice. I think we can be a little more intelligent about it, or at least give a more useful error if/when it occurs so that if it is intentional, people know how to handle it.

For anyone currently experiencing this issue: Wrapping a numeric command in quotes will work fine. ```yaml COMMAND: "8": 176070082584248320: true ``` I'm not sure if we should actually consider this as a bug with permissions, this was intended to catch a mistake like ```yaml COMMAND: 176070082584248320: true ``` and quoting the command makes sure it was an explicit choice. I think we can be a little more intelligent about it, or at least give a more useful error if/when it occurs so that if it is intentional, people know how to handle it.
Jackenmen commented 2019-12-13 00:51:25 +01:00 (Migrated from github.com)

The latter example wouldn't be valid because true is not a dict so it should still be possible to differentiate these 2 errors, right?

The latter example wouldn't be valid because `true` is not a dict so it should still be possible to differentiate these 2 errors, right?
mikeshardmind commented 2019-12-13 01:50:05 +01:00 (Migrated from github.com)

We can definitely be smarter about the rror handling here. Just requires someone to update the schema handling for this.

We can definitely be smarter about the rror handling here. Just requires someone to update the schema handling for this.
Jackenmen commented 2020-07-27 17:43:18 +02:00 (Migrated from github.com)

Reopening, apparently the issue with unrelated errors was never fixed, and the related PR only fixed integer commands and empty dict rules - you can still get unrelated error, when you for example spell default wrongly

Reopening, apparently the issue with unrelated errors was never fixed, and the related PR only fixed integer commands and empty dict rules - you can still get unrelated error, when you for example spell `default` wrongly
Flame442 commented 2023-08-23 00:27:01 +02:00 (Migrated from github.com)

The error message for non-boolean values is also currently broken. Example:

COMMAND:
    addrole:
        55555555555: 100
The error message for non-boolean values is also currently broken. Example: ```yaml COMMAND: addrole: 55555555555: 100 ```
Jackenmen commented 2026-11-09 21:56:23 +01:00 (Migrated from github.com)

I think this could either:

  • follow an approach similar to what we've done in Trivia a long while ago, see #5947
  • or switch to another schema library that can generate more accurate errors out of the box - I played a bit with voluptuous and think that we could get reasonable error messages with it, if we processed its exceptions ourselves (it does not have custom error messages like schema though it's not like what we do in Trivia really uses them in their intended way)
I think this could either: - follow an approach similar to what we've done in Trivia a long while ago, see #5947 - or switch to another schema library that can generate more accurate errors out of the box - I played a bit with `voluptuous` and think that we could get reasonable error messages with it, if we processed its exceptions ourselves (it does not have custom error messages like `schema` though it's not like what we do in Trivia really uses them in their intended way)
Owner

Behoben in 93d1d683e: Die verschachtelten Or()s im Schema führten dazu, dass jeder Fehler in der Datei als "Top-level keys must be either COG or COMMAND" gemeldet wurde. Die Regeln werden jetzt von einem kleinen Validator geprüft, der den Fehler an der tatsächlich falschen Stelle meldet. Bei default_but_spelt_incorrectly kommt jetzt "Keys under command names must be IDs (numbers) or default."; die Meldungen sind dieselben, bereits übersetzten Texte.


Generated by Claude Code

Behoben in 93d1d683e: Die verschachtelten `Or()`s im Schema führten dazu, dass jeder Fehler in der Datei als "Top-level keys must be either COG or COMMAND" gemeldet wurde. Die Regeln werden jetzt von einem kleinen Validator geprüft, der den Fehler an der tatsächlich falschen Stelle meldet. Bei `default_but_spelt_incorrectly` kommt jetzt "Keys under command names must be IDs (numbers) or `default`."; die Meldungen sind dieselben, bereits übersetzten Texte. --- _Generated by [Claude Code](https://claude.ai/code)_
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
2 participants
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#3185
No description provided.