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

_load_hash(): warning can fail to identify problematic file #5

Open
jkeenan opened this issue Feb 19, 2018 · 0 comments
Open

_load_hash(): warning can fail to identify problematic file #5

jkeenan opened this issue Feb 19, 2018 · 0 comments

Comments

@jkeenan
Copy link

jkeenan commented Feb 19, 2018

Today I needed to generate a CPAN river file, which I did by following the same procedures as I have done many times, namely, my local branch of https://github.com/dagolden/zzz-index-cpan-meta. The second of the three basic programs you have to run for this objective is https://github.com/dagolden/zzz-index-cpan-meta/blob/master/calculate-upstream-from-meta.pl. In the course of running this program, I got these two warnings:

CPAN::Meta::YAML found a duplicate key 'no_index' in line '' 
    at /home/jkeenan/perl5/perlbrew/perls/perl-5.26.0/lib/5.26.0/CPAN/Meta/YAML.pm line 514.

CPAN::Meta::YAML found a duplicate key 'file' in line 'lib/QtCore.pm' 
    at /home/jkeenan/perl5/perlbrew/perls/perl-5.26.0/lib/5.26.0/CPAN/Meta/YAML.pm line 514.

A CPAN search for QtCore enabled me to quickly identify the YAML file in the second warning: http://cpansearch.perl.org/src/VADIML/QtCore-4.004/META.yml. Since this file is from an unauthorized release from 2008, nothing to lose sleep over.

In the first case, however, the file where we have a duplicate of no_index is not recorded. That suggests to me that in these lines from inside _load_hash():

        if ( exists $hash->{$key} ) {
            warn "CPAN::Meta::YAML found a duplicate key '$key' in line '$lines->[0]'";
        }

... it's possible for $lines->[0] to be either empty or all whitespace -- meaning that we can't identify the file which has the duplicate keys. _load_hash() is called at several points within the module, but I suspect the problematic invocation is here:

        # Do we have a value?
        if ( length $lines->[0] ) {
            # Yes
            $hash->{$key} = $self->_load_scalar(
                shift(@$lines), [ @$indent, undef ], $lines
            );
        } else {
            # An indent
            shift @$lines;
            unless ( @$lines ) {
                $hash->{$key} = undef;
                return 1;
            }
            if ( $lines->[0] =~ /^(\s*)-/ ) {
                $hash->{$key} = [];
                $self->_load_array(
                    $hash->{$key}, [ @$indent, length($1) ], $lines
                );
            } elsif ( $lines->[0] =~ /^(\s*)./ ) {
                my $indent2 = length("$1");
                if ( $indent->[-1] >= $indent2 ) {
                    # Null hash entry
                    $hash->{$key} = undef;
                } else {
                    $hash->{$key} = {};
                    $self->_load_hash(
                        $hash->{$key}, [ @$indent, length($1) ], $lines  # <-- likely source of warning
                    );
                }
            }
        }
    }

I don't know whether this is worth fixing -- after all, this was one out of 30,000+ distributions on CPAN and, given that we're parsing YAML rather than JSON, probably an older distribution. But it should be noted in case anyone is doing refactoring in this part of the module.

Thank you very much.
Jim Keenan

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

No branches or pull requests

1 participant