Skip to content

Commit 6af904f

Browse files
authored
Fix error when attempting to format an unlinked tempfile (#3164)
1 parent 115ea8f commit 6af904f

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Fixed error when attempting to log an unlinked tempfile.
5+
46
3.215.0 (2025-01-10)
57
------------------
68

gems/aws-sdk-core/lib/aws-sdk-core/log/param_formatter.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ def summarize_value(value)
5151
when String then summarize_string(value)
5252
when Hash then '{' + summarize_hash(value) + '}'
5353
when Array then summarize_array(value)
54-
when File then summarize_file(value.path)
55-
when Pathname then summarize_file(value)
54+
when File then summarize_file(value)
55+
when Pathname then summarize_filepath(value)
5656
else value.inspect
5757
end
5858
end
5959

60-
def summarize_file(path)
60+
def summarize_file(file)
61+
"#<File:#{file.path} (#{file.size} bytes)>"
62+
end
63+
64+
def summarize_filepath(path)
6165
"#<File:#{path} (#{File.size(path)} bytes)>"
6266
end
6367

gems/aws-sdk-core/spec/aws/log/formatter_spec.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def format(pattern, options = {})
3434
end
3535

3636
it 'provides a :request_params replacement' do
37+
file = Tempfile.create
38+
# This is not available on windows, see:
39+
# - https://docs.ruby-lang.org/en/3.4/Tempfile.html#class-Tempfile-label-Unlink+after+creation
40+
# - https://github.com/aws/aws-sdk-ruby/issues/3163
41+
File.unlink(file.path) unless RUBY_DESCRIPTION.match?(/mswin|ming|cygwin/)
42+
file.write('foo=bar')
43+
3744
response.context.params = {
3845
foo: 'bar',
3946
attributes: {
@@ -43,15 +50,19 @@ def format(pattern, options = {})
4350
config: {
4451
nested: true,
4552
path: Pathname.new(__FILE__),
53+
tmpfile: file,
4654
complex: double('obj', inspect: '"inspected"')
4755
},
48-
huge: '-' * 1000
56+
huge: '-' * 1000,
57+
list: ['one', 'two']
4958
}
5059
formatted = format('{:request_params}', max_string_size: 20)
5160
size = File.size(__FILE__)
5261
expect(formatted).to eq(<<-FORMATTED.strip)
53-
{foo:"bar",attributes:{"color"=>"red","size"=>"large"},config:{nested:true,path:#<File:#{__FILE__} (#{size} bytes)>,complex:"inspected"},huge:#<String "--------------------" ... (1000 bytes)>}
62+
{foo:"bar",attributes:{"color"=>"red","size"=>"large"},config:{nested:true,path:#<File:#{__FILE__} (#{size} bytes)>,tmpfile:#<File:#{file.path} (#{file.size} bytes)>,complex:"inspected"},huge:#<String "--------------------" ... (1000 bytes)>,list:["one","two"]}
5463
FORMATTED
64+
ensure
65+
file.close
5566
end
5667

5768
it 'provides a :time replacement' do

0 commit comments

Comments
 (0)