question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return best command candidate on CommandService.ExecuteAsync

See original GitHub issue

Currently CommandService.ExecuteAsync does only return IResult, which contains an error category and an error message, but not the command which may fail because of preconditions or missing arguments before executing it. This makes it hard to add an error handler for commands that fail before they are executed.

For example, I added a SyntaxAttribute allowing to specify the correct command syntax and a short description for each argument and I want to display this command syntax if result.Error == CommandError.BadArgCount. As the command fails before executing it, neither CommandService.CommandExecuted nor CommandService.Log is fired. The only way to check for such errors is awaiting CommandService.ExecuteAsync and check for its result.

Although this allows determining the error, it doesn’t return to which command match the result applies to. Currently, I use the following as a workaround:

var context = new SocketCommandContext(_client, message);
var result = await _service.ExecuteAsync(context, position, _provider);

if(!result.IsSuccess) {
    if(result.Error != CommandError.UnknownCommand) {
        var search = _service.Search(context, position);
        if(search.IsSuccess && search.Commands.Count == 1) {
            var command = search.Commands.First().Command;
            // handle command failure here
        }
    }
}

This works fine as long as the result of CommandService.Search returns exactly one command, but what if there are more than one matches? The CommandService itself determines the best candidate when returning early, but returns its result only:

CommandService L374 CommandService L432

I think it would be useful to return the candidate as well (adding a property to the IResult interface or an additional event for pre-command failures.) or is there already a way to achieve this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Joe4evrcommented, Jul 20, 2018

Why not look for the candidate yourself first? The methods are there for you to use.

Also, please use the issue tracker only for actual bugs. Questions about usage should go in our channel on the DAPI server.

0reactions
foxbotcommented, Oct 21, 2018

I’m going to close this, since you can now use CommandExecuted to receive the command a result failed on (with the exception of search results - but you can apply your own logic for that)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Post-execution Handling for Text Commands
Async , ExecuteAsync will always return a successful ExecuteResult instead of the actual result. You can learn more about the impact in @FAQ.Commands.General....
Read more >
Siderite's Blog searching dependency injection
As you may know, dependency injection has been baked in in ASP.Net almost since the beginning, but it culminated with the MVC framework...
Read more >
Oracle® NoSQL Database
oracle.kv.impl.async.dialog.nio.NioChannelExecutor.runTasks(NioChann. elExecutor.java:1493. [KVSTORE-880]. 25. Fixed a bug where operations may return with ...
Read more >
https://huggingface.co/microsoft/CodeGPT-small-jav...
+O VER +Ġcon sume +find By +append Child +ATE G +OR ITY +B C +4 6 +get Timestamp +Ġc at +Ġb ootstrap +ri...
Read more >
java.io.File Scala Example
Invocation) def submitCommands(): Unit = { await( dummyCreates(ledger.ledgerId) .take(commandCount) .mapAsync(100)(ledger.commandService.submitAndWait) .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found