Skip to content

Commit

Permalink
feat(core): optimize error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 19, 2021
1 parent 36b3890 commit a4498ea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions packages/koishi-core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export class Command<U extends User.Field = never, G extends Channel.Field = nev
return this.context.match(session) && this.config.authority <= authority && !disable.includes(this.name)
}

getConfig<K extends keyof Command.Config>(key: K, session: Session): Exclude<Command.Config[K], (user: User) => any> {
const value = this.config[key] as any
return typeof value === 'function' ? value(session.user) : value
}

check(callback: Command.Action<U, G, A, O>, prepend = false) {
if (prepend) {
this._checkers.unshift(callback)
Expand All @@ -180,11 +185,6 @@ export class Command<U extends User.Field = never, G extends Channel.Field = nev
return this
}

getConfig<K extends keyof Command.Config>(key: K, session: Session): Exclude<Command.Config[K], (user: User) => any> {
const value = this.config[key] as any
return typeof value === 'function' ? value(session.user) : value
}

action(callback: Command.Action<U, G, A, O>, append = false) {
if (append) {
this._actions.push(callback)
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export class Context {
if (command) {
if (parent) {
if (command === parent) {
throw new Error('cannot set a command as its own subcommand')
throw new Error(`cannot set a command (${command.name}) as its own subcommand`)
}
if (command.parent) {
if (command.parent !== parent) {
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export namespace Domain {
private _assignOption(option: OptionDeclaration, names: readonly string[], optionMap: OptionDeclarationMap) {
for (const name of names) {
if (name in optionMap) {
throw new Error(format('duplicate option names: "%s"', name))
throw new Error(format('duplicate option name "%s" for command "%s"', name, this.name))
}
optionMap[name] = option
}
Expand Down

0 comments on commit a4498ea

Please sign in to comment.