Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve theme error informations #947

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

riquito
Copy link

@riquito riquito commented Nov 5, 2023

I couldn't figure out why my local changes to the theme colors definition were not being picked up, so I went to the source.
Turned out my yaml file was using some improper fields.

This PR does:

  • print a specific warning if in the config color.theme was set to custom and no colors.yaml (or colors.yml) was found
  • print a specific warning if a color theme was found, but the parsing failed, and why it failed.

Contrary to before, if a color file definition exists and it cannot be parsed we immediately switch to the default (plus a warning). The previous logic was hiding format errors if there were other file extensions to try.

Some examples of the output (before regular lsd output):

if color.y(a)ml is found, but contains wrong data

Warning: cannot load custom theme. Theme file format invalid. date: unknown field `days-old`, expected one of `hour-old`, `day-old`, `older` at line 18 column 3.

if color.theme is set to "custom" in the config file, but no color.y(a)ml is present

Warning: cannot load custom theme. Cannot read theme file. No such file or directory (os error 2).

Sidenotes:

  • warning output bleed into cargo test. This was already happening with Warning: the 'themes' directory is deprecated, use 'colors.yaml' instead., I made it slightly worse. Perhaps in general warnings should be behind #[cfg(not(test))] or similar, didn't investigate in print_error either, considered it out of scope.
  • imho we should accept a specific extension for color.yml and the others. Iterating over extensions produces subtle bugs like this and there are no particular benefits (if the documentation tells you to create <filename.yml>, you create <filename.yml> - now you also get a warning)

TODO

  • Use cargo fmt
  • Add necessary tests
  • Update default config/theme in README (if applicable)
  • Update man page at lsd/doc/lsd.md (if applicable)

Copy link

muniu-bot bot commented Nov 5, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: riquito

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@riquito riquito force-pushed the improve-theme-error-informations branch from 3b35e1f to b76c3c2 Compare November 5, 2023 20:04
@muniu-bot muniu-bot bot added size/M and removed size/S labels Nov 5, 2023
@riquito riquito marked this pull request as ready for review November 5, 2023 20:22
@riquito
Copy link
Author

riquito commented Nov 20, 2023

Is there anything I need to do to improve this PR?

@zwpaper
Copy link
Member

zwpaper commented Nov 22, 2023

hi @riquito, sorry for the late reply, the PR looks good and I have started the CI.

thanks for the contribution!

Copy link

codecov bot commented Nov 22, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (89659e4) 85.76% compared to head (cb9930b) 85.87%.
Report is 6 commits behind head on master.

Files Patch % Lines
src/theme.rs 96.15% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #947      +/-   ##
==========================================
+ Coverage   85.76%   85.87%   +0.11%     
==========================================
  Files          51       51              
  Lines        5001     5026      +25     
==========================================
+ Hits         4289     4316      +27     
+ Misses        712      710       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants