Skip to content

Expect original Rexfile path in messages #1563

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

Merged
merged 3 commits into from
Jan 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Revision history for Rex
- Correct example for file_read command

[ENHANCEMENTS]
- Show Rexfile path in loading messages

[MAJOR]

Expand Down
22 changes: 10 additions & 12 deletions lib/Rex/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -763,13 +763,9 @@ sub load_rexfile {
for (@warnings) {
chomp;

# remove /loader/.../ prefix before filename
s{/loader/[^/]+/}{}sxm;
my $message = _tidy_loading_message( $_, $rexfile );

# convert Rexfile to human-friendly name
s{__Rexfile__.pm}{Rexfile}msx;

Rex::Logger::info( "\t$_", 'warn' );
Rex::Logger::info( "\t$message", 'warn' );
}
}

Expand All @@ -780,12 +776,7 @@ sub load_rexfile {
my $e = $@;
chomp $e;

# remove the strange path to the Rexfile which exists because
# we load the Rexfile via our custom code block.
$e =~ s|/loader/[^/]+/||smg;

# convert Rexfile to human-friendly name
$e =~ s{__Rexfile__.pm}{Rexfile}msx;
$e = _tidy_loading_message( $e, $rexfile );

my @lines = split( $/, $e );

Expand All @@ -796,6 +787,13 @@ sub load_rexfile {
}
}

sub _tidy_loading_message {
my ( $message, $rexfile ) = @_;

$message =~ s{/loader/[^/]+/__Rexfile__[.]pm}{$rexfile}gmsx;
return $message;
}

sub exit_rex {
my ( $exit_code_override, $signal ) = @_;

Expand Down
1 change: 1 addition & 0 deletions t/load_rexfile.t
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ sub _setup_test {

$expected->{$extension} = -r $file ? cat($file) : $default_content;
$expected->{$extension} =~ s{%REX_CLI_PATH%}{$rex_cli_path}msx;
$expected->{$extension} =~ s{%REXFILE_PATH%}{$rexfile}gmsx;
}

# reset log
Expand Down
2 changes: 1 addition & 1 deletion t/rexfiles/Rexfile_fatal.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ERROR - Compile time errors:
ERROR - syntax error at Rexfile line 5, near "abc
ERROR - syntax error at %REXFILE_PATH% line 5, near "abc
ERROR -
ERROR - task "
ERROR - Compilation failed in require at %REX_CLI_PATH% line 756.
2 changes: 1 addition & 1 deletion t/rexfiles/Rexfile_fatal_print.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ERROR - Compile time errors:
ERROR - syntax error at Rexfile line 8, near "abc
ERROR - syntax error at %REXFILE_PATH% line 8, near "abc
ERROR -
ERROR - print"
ERROR - Compilation failed in require at %REX_CLI_PATH% line 756.
4 changes: 2 additions & 2 deletions t/rexfiles/Rexfile_warnings.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
WARN - You have some code warnings:
WARN - This is warning at Rexfile line 5.
WARN - Use of uninitialized value in concatenation (.) or string at Rexfile line 6.
WARN - This is warning at %REXFILE_PATH% line 5.
WARN - Use of uninitialized value in concatenation (.) or string at %REXFILE_PATH% line 6.
4 changes: 2 additions & 2 deletions t/rexfiles/Rexfile_warnings_print.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
WARN - You have some code warnings:
WARN - This is warning at Rexfile line 5.
WARN - Use of uninitialized value in concatenation (.) or string at Rexfile line 6.
WARN - This is warning at %REXFILE_PATH% line 5.
WARN - Use of uninitialized value in concatenation (.) or string at %REXFILE_PATH% line 6.
4 changes: 2 additions & 2 deletions t/rexfiles/Rexfile_warnings_print.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is STDERR message
WARN - You have some code warnings:
WARN - This is warning at Rexfile line 5.
WARN - Use of uninitialized value in concatenation (.) or string at Rexfile line 6.
WARN - This is warning at %REXFILE_PATH% line 5.
WARN - Use of uninitialized value in concatenation (.) or string at %REXFILE_PATH% line 6.