Project

General

Profile

Actions

Bug #6849

closed

Psych.load_file throws TypeError for empty file

Added by BrandonMathis (Brandon Mathis) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]
Backport:
[ruby-core:47094]

Description

When parsing an empty file via Psych.load_file:
TypeError: no implicit conversion from nil to integer
I would expect that an empty hash or array would be returned.

This, more directly, relates to parsing YAML documents using YAML.load_file


Files

noname (500 Bytes) noname Anonymous, 08/14/2012 06:53 AM

Updated by zzak (zzak _) over 11 years ago

On ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

I can reproduce this using Psych.load_file.

However, when I try Psych#load as the implementation suggests[1]
leaving out the utf stuff "bom|utf-8"; it returns false:

$irb
require 'psych'
touch empty.yml
File.open('empty.yml', 'r') { |f| Psych.load(f,'empty file') }
#=> false

Something is up with the File.open mode used by psych:

$irb
touch empty.file
File.open('empty.file', 'r:bom|utf-8') { |f| puts f }
TypeError: no implicit conversion from nil to integer

1: https://github.com/tenderlove/psych/blob/master/lib/psych.rb#L299

On Thu, Aug 9, 2012 at 2:54 PM, BrandonMathis (Brandon Mathis)
wrote:

Issue #6849 has been reported by BrandonMathis (Brandon Mathis).


Bug #6849: Psych.load_file throws TypeError for empty file
https://bugs.ruby-lang.org/issues/6849

Author: BrandonMathis (Brandon Mathis)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin12.0.0]

When parsing an empty file via Psych.load_file:
TypeError: no implicit conversion from nil to integer
I would expect that an empty hash or array would be returned.

This, more directly, relates to parsing YAML documents using YAML.load_file

--
http://bugs.ruby-lang.org/

Updated by Anonymous over 11 years ago

On Tue, Aug 14, 2012 at 03:12:58AM +0900, Zachary Scott wrote:

On ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

I can reproduce this using Psych.load_file.

However, when I try Psych#load as the implementation suggests[1]
leaving out the utf stuff "bom|utf-8"; it returns false:

$irb
require 'psych'
touch empty.yml
File.open('empty.yml', 'r') { |f| Psych.load(f,'empty file') }
#=> false

Something is up with the File.open mode used by psych:

$irb
touch empty.file
File.open('empty.file', 'r:bom|utf-8') { |f| puts f }
TypeError: no implicit conversion from nil to integer

Ah, this is a bug in Ruby:

https://bugs.ruby-lang.org/issues/6487

It should be fixed in the next 1.9.3 patch release.

--
Aaron Patterson
http://tenderlovemaking.com/

Updated by zzak (zzak _) over 11 years ago

  • Status changed from Open to Closed

This is a duplicate of #6487

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0