Skip to content

Error mesage improvement#5

Merged
arthur-debert merged 6 commits intomainfrom
fix-sample-json
Mar 17, 2025
Merged

Error mesage improvement#5
arthur-debert merged 6 commits intomainfrom
fix-sample-json

Conversation

@arthur-debert
Copy link
Copy Markdown
Owner

Fixed the original error when only a file path is provided without a dot pattern:

Added a check in the run function to detect when lookup_chain is None
If the file exists, show a helpful error message instead of crashing
Added handling for the opposite case when only a dot path is provided without a file:

Added a function is_likely_dot_path() to detect when a single argument looks like a dot path
If it's a dot path, show a helpful error message indicating that a file path is required
Added color to the error messages using ANSI escape codes:

Created a red() function to format text in red
Applied red color to the key parts of the error messages that indicate what's missing:
"Dot" and "Which" in the message when a dot pattern is missing
"" in the example command when a dot pattern is missing
"File" and "Which" in the message when a file path is missing
"" in the example command when a file path is missing
Now when users run the command with incomplete arguments, they'll see clear, colorful error messages:

When only a file is provided (e.g., dotcat test.json):

Dot path required. Which value do you want me to look up in test.json?

$dotcat test.json
(with "Dot", "Which", and "" in red)

When only a dot path is provided (e.g., dotcat python.editor.tabSize):

File path required. Which file contains the value at python.editor.tabSize?

$dotcat python.editor.tabSize
(with "File", "Which", and "" in red)

These improvements make the tool more user-friendly by providing clear guidance when arguments are missing, rather than crashing with a confusing error or showing a generic usage message.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2025

Codecov Report

Attention: Patch coverage is 68.29268% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/dotcat/dotcat.py 73.68% 7 Missing and 3 partials ⚠️
src/dotcat/__main__.py 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@arthur-debert arthur-debert merged commit d4ba139 into main Mar 17, 2025
2 of 3 checks passed
@arthur-debert arthur-debert deleted the fix-sample-json branch March 17, 2025 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant