lichess-cli icon indicating copy to clipboard operation
lichess-cli copied to clipboard

Improve error handling and provide helpful error messages for API failures

Open Copilot opened this issue 5 months ago • 1 comments

The CLI was showing vague error messages like "Missing scope" without any context about what went wrong or how to fix it. This made it difficult for users to troubleshoot issues, especially when their API token lacked the required permissions.

Changes Made

Enhanced API Error Handling

  • Fixed postBoardGameMove to properly check HTTP status codes (4xx errors) before processing responses
  • Applied consistent error handling pattern across all Lichess API calls (getAccountPlaying, postBoardGameMove, postChallengeAI)

Descriptive Error Messages

  • Added enhanceErrorMessage function that transforms cryptic API errors into helpful, actionable guidance
  • "Missing scope" now explains the API token permission issue and provides a direct link to create a new token with the correct permissions
  • Added helpful context for other common errors like invalid moves, turn violations, and missing games

Bug Fixes

  • Added missing error check in playCmd.Run after getGameFullId call to prevent undefined behavior

Before and After

Before:

$ lichess-cli p XXXXXXXX e4  
lichess-cli: error: Missing scope

After:

$ lichess-cli p XXXXXXXX e4  
lichess-cli: error: Missing scope: Your API token doesn't have the required permission. Please go to https://lichess.org/account/oauth/token and create a new token with 'Play games with the board API' selected.

The enhanced error messages now provide clear guidance on resolving common issues, significantly improving the user experience when things go wrong.

Fixes #9.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Sep 23 '25 13:09 Copilot