feat: add custom UnknownEditFormat exception with documentation link

This commit is contained in:
Paul Gauthier (aider) 2024-11-26 07:00:16 -08:00
parent bbd81c3cf7
commit 75bc2dd564
3 changed files with 8 additions and 2 deletions

View file

@ -22,7 +22,7 @@ from typing import List
from aider import __version__, models, prompts, urls, utils from aider import __version__, models, prompts, urls, utils
from aider.analytics import Analytics from aider.analytics import Analytics
from aider.commands import Commands from aider.commands import Commands
from aider.exceptions import LiteLLMExceptions from aider.exceptions import LiteLLMExceptions, UnknownEditFormat
from aider.history import ChatSummary from aider.history import ChatSummary
from aider.io import ConfirmGroup, InputOutput from aider.io import ConfirmGroup, InputOutput
from aider.linter import Linter from aider.linter import Linter
@ -157,7 +157,8 @@ class Coder:
res.original_kwargs = dict(kwargs) res.original_kwargs = dict(kwargs)
return res return res
raise ValueError(f"Unknown edit format {edit_format}") valid_formats = [c.edit_format for c in coders.__all__ if hasattr(c, "edit_format")]
raise UnknownEditFormat(edit_format, valid_formats)
def clone(self, **kwargs): def clone(self, **kwargs):
new_coder = Coder.create(from_coder=self, **kwargs) new_coder = Coder.create(from_coder=self, **kwargs)

View file

@ -765,6 +765,10 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
chat_language=args.chat_language, chat_language=args.chat_language,
detect_urls=args.detect_urls, detect_urls=args.detect_urls,
) )
except UnknownEditFormat as err:
io.tool_error(str(err))
io.offer_url(urls.edit_formats, "Open documentation about edit formats?")
return 1
except ValueError as err: except ValueError as err:
io.tool_error(str(err)) io.tool_error(str(err))
return 1 return 1

View file

@ -13,3 +13,4 @@ git_index_version = "https://github.com/Aider-AI/aider/issues/211"
install_properly = "https://aider.chat/docs/troubleshooting/imports.html" install_properly = "https://aider.chat/docs/troubleshooting/imports.html"
analytics = "https://aider.chat/docs/more/analytics.html" analytics = "https://aider.chat/docs/more/analytics.html"
release_notes = "https://aider.chat/HISTORY.html#release-notes" release_notes = "https://aider.chat/HISTORY.html#release-notes"
edit_formats = "https://aider.chat/docs/more/edit-formats.html"