fix(history): emit diagnostic when HISTFILE is unset for -a/-w#1146
fix(history): emit diagnostic when HISTFILE is unset for -a/-w#1146dashitongzhi wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aligns history -a and history -w behavior with bash by emitting a stderr diagnostic when no effective history file can be determined (i.e., HISTFILE unset and no explicit file argument), while preserving the bash-compatible success exit code.
Changes:
- Updated
history -aandhistory -wcode paths to handleNonefromget_effective_history_file_pathby printingHISTFILE: parameter null or not setto stderr. - Refactored the previous
if let Some(...)flow intomatchto make theNonehandling explicit.
| None => { | ||
| writeln!(stderr, "brush: history: HISTFILE: parameter null or not set")?; | ||
| } |
| match get_effective_history_file_path( | ||
| config.default_history_file_path, | ||
| append_option.as_ref(), | ||
| ) { | ||
| history.flush( | ||
| file_path, | ||
| true, /* append? */ | ||
| true, /* unsaved items only */ | ||
| config.time_format.is_some(), /* write timestamps? */ | ||
| )?; | ||
| Some(file_path) => { | ||
| history.flush( | ||
| file_path, | ||
| true, /* append? */ | ||
| true, /* unsaved items only */ | ||
| config.time_format.is_some(), /* write timestamps? */ | ||
| )?; | ||
| } | ||
| None => { | ||
| writeln!(stderr, "brush: history: HISTFILE: parameter null or not set")?; | ||
| } |
| if let Some(append_option) = &self.append_session_to_file { | ||
| if let Some(file_path) = get_effective_history_file_path( | ||
| match get_effective_history_file_path( | ||
| config.default_history_file_path, | ||
| append_option.as_ref(), | ||
| ) { | ||
| history.flush( | ||
| file_path, | ||
| true, /* append? */ | ||
| true, /* unsaved items only */ | ||
| config.time_format.is_some(), /* write timestamps? */ | ||
| )?; | ||
| Some(file_path) => { | ||
| history.flush( | ||
| file_path, | ||
| true, /* append? */ | ||
| true, /* unsaved items only */ | ||
| config.time_format.is_some(), /* write timestamps? */ | ||
| )?; | ||
| } | ||
| None => { | ||
| writeln!(stderr, "brush: history: HISTFILE: parameter null or not set")?; | ||
| } | ||
| } | ||
|
|
||
| return Ok(ExecutionResult::success()); |
| )?; | ||
| } | ||
| None => { | ||
| writeln!(stderr, "brush: history: HISTFILE: parameter null or not set")?; |
| match get_effective_history_file_path( | ||
| config.default_history_file_path, | ||
| write_option.as_ref(), | ||
| ) { | ||
| history.flush( | ||
| file_path, | ||
| false, /* append? */ | ||
| false, /* unsaved items only? */ | ||
| config.time_format.is_some(), /* write timestamps? */ | ||
| )?; | ||
| Some(file_path) => { | ||
| history.flush( | ||
| file_path, | ||
| false, /* append? */ | ||
| false, /* unsaved items only? */ | ||
| config.time_format.is_some(), /* write timestamps? */ | ||
| )?; | ||
| } | ||
| None => { | ||
| writeln!(stderr, "brush: history: HISTFILE: parameter null or not set")?; | ||
| } |
|
@dashitongzhi Thanks for the contribution! The change looks relatively straightforward. I've unblocked the PR checks to run and will take another look. |
Performance Benchmark Report
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is Test Summary: bash-completion test suite
|
reubeno
left a comment
There was a problem hiding this comment.
Thanks for the contribution, and for your patience. I left one comment that I'd like you to address; other than that it's looking good.
| None => { | ||
| writeln!( | ||
| stderr, | ||
| "brush: history: HISTFILE: parameter null or not set" |
There was a problem hiding this comment.
As copilot's auto-comments called out, brush-core is embeddable in differently name shell apps, so we shouldn't hard-code brush.
If you look elsewhere in the code base you can see examples of what other builtins do. (Most of them probably omit the shell name, although the shell name can be dynamically queried via .current_shell_name() on the shell object.)
Could you please update this and the other error below accordingly?
When is unset and no explicit file argument is provided,
and previously silently succeeded with exit 0.
Bash emits a diagnostic in this situation.
This change converts the pattern to for both
(append_session_to_file) and (write_session_to_file) code
paths, emitting the following diagnostic to stderr when the history
file path resolves to None:
brush: history: HISTFILE: parameter null or not set
This matches bash's exact wording for compat-script friendliness.
Fixes reubeno#1135
8a5e0d7 to
90c747b
Compare
Summary
When
HISTFILEis unset and no explicit file argument is provided,history -aandhistory -wpreviously silently succeeded with exit 0. Bash emits a diagnostic to stderr in the same situation.This PR fixes the issue by emitting:
to stderr when the history file path resolves to
None, matching bash's exact wording for compat-script friendliness.Changes
brush-builtins/src/history.rs: Convertedif let Sometomatchfor both-a(append_session_to_file) and-w(write_session_to_file) code paths, adding aNonearm that writes the diagnostic to stderr.Notes
-nand-ralready return "not yet implemented" errors, so they don't need the HISTFILE check yet.Fixes #1135