pdf-raku / PDF-Class-raku

PDF Document Object Model (under construction)
Artistic License 2.0
7 stars 3 forks source link

Error during installation (testing phase) #11

Closed frithnanth closed 6 years ago

frithnanth commented 6 years ago

Hello, I'm trying to upgrade this module, because I have an error message processing some PDF files using PDF::API6: Probable version skew in pre-compiled [...] (PDF::Font)' (cause: no object at index 776) But I'm getting this error during the testing phase:

$ zef install 'PDF::Class:ver<0.1.2>'
===> Searching for: PDF::Class
===> Testing: PDF::Class:ver<0.1.2>:auth<github:p6-pdf>:api<PDF-1.7>
eval error:     use PDF::Class;
    use PDF::Catalog;
    my PDF::Class $pdf .= new;

    my PDF::Catalog $doc = $pdf.catalog;
    try {
        $doc.PageMode   = 'UseToes';
        CATCH { default { say "err, that didn't work: $_" } }
    }

    # same again, bypassing type checking
    $doc<PageMode>  = :name<UseToes>;

  in block  at t/00-readme.t line 25
unknown /ShadingType 42 - supported range is 1..7
No Doc handler class [PDF PDF::COS::Type]::Unknown
No Doc handler class [PDF PDF::COS::Type]::Annot::Caret
Probable version skew in pre-compiled '/home/nando/.zef/store/PDF-Class-0.1.2.tar.gz/PDF-Class-0.1.2/lib/PDF/OutputIntent.pm (PDF::OutputIntent)' (cause: no object at index 776)
  in method find-delegate at /home/nando/.zef/store/PDF-Class-0.1.2.tar.gz/PDF-Class-0.1.2/lib/PDF/Class/Loader.pm (PDF::Class::Loader) line 32
  in method load-delegate at /home/nando/.zef/store/PDF-Class-0.1.2.tar.gz/PDF-Class-0.1.2/lib/PDF/Class/Loader.pm (PDF::Class::Loader) line 105
  in block <unit> at t/load-delegate.t line 23

# Looks like you planned 18 tests, but ran 11
===> Testing [FAIL]: PDF::Class:ver<0.1.2>:auth<github:p6-pdf>:api<PDF-1.7>
Aborting due to test failure: PDF::Class:ver<0.1.2>:auth<github:p6-pdf>:api<PDF-1.7> (use --force-test to override)
  in code  at /opt/rakudo-pkg/share/perl6/sources/8244C3B17ACA61B0EC04857BB3283A8FAF7A186D (Zef::Client) line 374
  in method test at /opt/rakudo-pkg/share/perl6/sources/8244C3B17ACA61B0EC04857BB3283A8FAF7A186D (Zef::Client) line 354
  in code  at /opt/rakudo-pkg/share/perl6/sources/8244C3B17ACA61B0EC04857BB3283A8FAF7A186D (Zef::Client) line 523
  in sub  at /opt/rakudo-pkg/share/perl6/sources/8244C3B17ACA61B0EC04857BB3283A8FAF7A186D (Zef::Client) line 520
  in method install at /opt/rakudo-pkg/share/perl6/sources/8244C3B17ACA61B0EC04857BB3283A8FAF7A186D (Zef::Client) line 621
  in sub MAIN at /opt/rakudo-pkg/share/perl6/sources/81436475BD18D66BFD96BBCEE07CCCDC0F368879 (Zef::CLI) line 152
  in block <unit> at /opt/rakudo-pkg/share/perl6/resources/D822DF07A6D5CB602F97ED307F62A1B3B5D2C90D line 3
  in sub MAIN at /opt/rakudo-pkg/bin/zef line 2
  in block <unit> at /opt/rakudo-pkg/bin/zef line 2

I have the following modules installed:

$ zef list --installed|grep PDF
===> Found via /opt/rakudo-pkg/share/perl6
===> Found via /home/nando/.perl6
PDF::API6:ver<0.1.0>:auth<github:p6-pdf>
PDF::Class:ver<0.1.0>:auth<github:p6-pdf>:api<PDF-1.7>
PDF::Content:ver<0.2.1>:auth<github:p6-pdf>:api<PDF-1.7>
PDF::Grammar:ver<0.1.5>:auth<github:p6-pdf>:api<PDF-1.7>
PDF:ver<0.2.8>:auth<github:p6-pdf>:api<PDF-1.7>

and perl6 version is:

perl6 -v
This is Rakudo version 2018.03 built on MoarVM version 2018.03
implementing Perl 6.c.
dwarring commented 6 years ago

Hi @frithnanth

Update: zef uninstall not zef nuke

I think there's some conflict between old and new versions. Does it help to do a reinstall of the PDF tool-chain as follows (allow ~ 30 mins):

% zef nuke PDF::API6 PDF::Class PDF::Content PDF PDF::Grammar % zef uninstall PDF::API6 PDF::Class PDF::Content PDF PDF::Grammar % zef install PDF::API6

After that, I'd also also recommend deleting any local .precomp directories

Hope this helps.

frithnanth commented 6 years ago

Hi @dwarring

I uninstalled and reinstalled the modules:

$ zef install PDF::API6                                
===> Searching for: PDF::API6
===> Updated cpan mirror: https://raw.githubusercontent.com/ugexe/Perl6-ecosystems/master/cpan.json
===> Updated p6c mirror: http://ecosystem-api.p6c.org/projects.json
===> Searching for missing dependencies: PDF, PDF::Class, PDF::Content
===> Searching for missing dependencies: PDF::Grammar
===> Testing: PDF::Grammar:ver<0.1.5>:auth<github:p6-pdf>:api<PDF-1.7>
# loading t/helloworld.pdf (set $TEST_PDF to override)
===> Testing [OK] for PDF::Grammar:ver<0.1.5>:auth<github:p6-pdf>:api<PDF-1.7>
===> Testing: PDF:ver<0.2.8>:auth<github:p6-pdf>:api<PDF-1.7>
===> Testing [OK] for PDF:ver<0.2.8>:auth<github:p6-pdf>:api<PDF-1.7>
===> Testing: PDF::Content:ver<0.2.1>:auth<github:p6-pdf>:api<PDF-1.7>
error processing 'RG' (SetStrokeRGB) operator
error processing 'TL' (SetTextLeading) operator
error processing 'Tf' (SetFont) operator
===> Testing [OK] for PDF::Content:ver<0.2.1>:auth<github:p6-pdf>:api<PDF-1.7>
===> Testing: PDF::Class:ver<0.1.2>:auth<github:p6-pdf>:api<PDF-1.7>
eval error:     use PDF::Class;
    use PDF::Catalog;
    my PDF::Class $pdf .= new;

    my PDF::Catalog $doc = $pdf.catalog;
    try {
        $doc.PageMode   = 'UseToes';
        CATCH { default { say "err, that didn't work: $_" } }
    }

    # same again, bypassing type checking
    $doc<PageMode>  = :name<UseToes>;

  in block  at t/00-readme.t line 25
unknown /ShadingType 42 - supported range is 1..7
No Doc handler class [PDF PDF::COS::Type]::Unknown
No Doc handler class [PDF PDF::COS::Type]::Annot::Caret
===> Testing [OK] for PDF::Class:ver<0.1.2>:auth<github:p6-pdf>:api<PDF-1.7>
===> Testing: PDF::API6:ver<0.1.0>:auth<github:p6-pdf>
("q", "BT", "/F1 16 Tf", "1 0 0 1 10 10 Tm", "(Hello, world) Tj", "17.6 TL", "T*", "ET", "q", "19 0 0 19 110.688 10 cm", "/Im1 Do", "Q", "Q").Seq
Text matrix updated by Tm to 1 0 0 1 10 10
===> Testing [OK] for PDF::API6:ver<0.1.0>:auth<github:p6-pdf>
===> Installing: PDF::Grammar:ver<0.1.5>:auth<github:p6-pdf>:api<PDF-1.7>
===> Installing: PDF:ver<0.2.8>:auth<github:p6-pdf>:api<PDF-1.7>
===> Installing: PDF::Content:ver<0.2.1>:auth<github:p6-pdf>:api<PDF-1.7>
===> Installing: PDF::Class:ver<0.1.2>:auth<github:p6-pdf>:api<PDF-1.7>
===> Installing: PDF::API6:ver<0.1.0>:auth<github:p6-pdf>

6 bin/ scripts [pdf-rewriter.pl pdf-append.p6 pdf-checker.p6 pdf-info.p6 pdf-revert.p6 pdf-burst.p6] installed to:
/home/nando/.perl6/bin

There are some non-fatal errors, but the modules have been installed. Still, when I run this program:

use PDF::API6;

my PDF::API6 $pdf .= open('old.pdf');
my $page = $pdf.page(1);
my $font = $pdf.core-font('Helvetica-Bold');
$page.text: {
  .font = $font, 20;
  .text-position = 200, 700;
  .say('Hello World!');
}
$pdf.save-as('new.pdf');

I get this error:

Cannot find method 'specialize' on object of type Perl6::Metamodel::ClassHOW+{<anon>}
  in method mixin at /home/nando/.perl6/sources/822169956771DB33FC0D5BAD82085542A72639DE (PDF::COS::Tie) line 200
  in method coerce at /home/nando/.perl6/sources/9E089E43DB4C2FF54174FCC674C74CD710DDD2AA (PDF::COS::Coercer) line 63
  in method coerce at /home/nando/.perl6/sources/5091F292E9E62412B6143E4C6F25AA9CDE28AC2B (PDF::COS) line 28
  in sub  at /home/nando/.perl6/sources/822169956771DB33FC0D5BAD82085542A72639DE (PDF::COS::Tie) line 56
  in block  at /home/nando/.perl6/sources/822169956771DB33FC0D5BAD82085542A72639DE (PDF::COS::Tie) line 106
  in method tie at /home/nando/.perl6/sources/822169956771DB33FC0D5BAD82085542A72639DE (PDF::COS::Tie) line 61
  in method tie at /home/nando/.perl6/sources/822169956771DB33FC0D5BAD82085542A72639DE (PDF::COS::Tie) line 125
  in method AT-KEY at /home/nando/.perl6/sources/B8B8813B96AB3C0DAEC7B650580E7B18F08E5E8B (PDF::COS::Tie::Hash) line 54
  in method ref-count at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 22
  in method ref-count at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 22
  in method ref-count at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 22
  in method ref-count at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 22
  in method ref-count at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 29
  in method ref-count at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 22
  in method ref-count at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 22
  in method ref-count at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 22
  in method body at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 67
  in method ast at /home/nando/.perl6/sources/4F8D91227F7DC384FC722C468900C06197500BA9 (PDF::IO::Serializer) line 259
  in method ast at /home/nando/.perl6/sources/AD3EF7527B03D7E88AE13AFFE91836B2747B9109 (PDF) line 127
  in method save-as at /home/nando/.perl6/sources/AD3EF7527B03D7E88AE13AFFE91836B2747B9109 (PDF) line 149
  in method save-as at /home/nando/.perl6/sources/3A0455208EBF84A2A5453574B6FDBDD294BDB416 (PDF::Class) line 61
  in method save-as at /home/nando/.perl6/sources/AD3EF7527B03D7E88AE13AFFE91836B2747B9109 (PDF) line 144
  in method save-as at /home/nando/.perl6/sources/3A0455208EBF84A2A5453574B6FDBDD294BDB416 (PDF::Class) line 61
  in method save-as at /home/nando/.perl6/sources/AD3EF7527B03D7E88AE13AFFE91836B2747B9109 (PDF) line 130
  in method save-as at /home/nando/.perl6/sources/3A0455208EBF84A2A5453574B6FDBDD294BDB416 (PDF::Class) line 61
  in block <unit> at ./test.p6 line 13

I'm attaching the PDF file I'm using here. pdf4.pdf

Thank you!

dwarring commented 6 years ago

Thanks @frithnanth. Will look at this over the next few days.

dwarring commented 6 years ago

Able to replicate this error when I follow the same steps.

Error and failure point changes when I set the include path and add some debugging:

perl6 -I. -I ../PDF-Content-p6/ -I ../PDF-p6/ -I ../PDF-Grammar-p6/ -I ../PDF-Class-p6 /tmp/tst.pl 
{:obj(${:Procset($["PDF", "Text"])}), :role(PDF::Resources)}
  in method mixin at /home/david/git/PDF-API6/../PDF-p6/lib/PDF/COS/Tie.pm (PDF::COS::Tie) line 200
{:obj(${:ExtGState(${:GS0(:ind-ref($[18, 0])), :GS1(:ind-ref($[17, 0]))}), :Font(${:C2_0(:ind-ref($[5, 0])), :TT0(:ind-ref($[14, 0])), :TT1(:ind-ref($[11, 0]))}), :ProcSet($["PDF", "Text"])}), :role(PDF::Resources)}
  in method mixin at /home/david/git/PDF-API6/../PDF-p6/lib/PDF/COS/Tie.pm (PDF::COS::Tie) line 200
{:obj(${}), :role(PDF::Resources)}
  in method mixin at /home/david/git/PDF-API6/../PDF-p6/lib/PDF/COS/Tie.pm (PDF::COS::Tie) line 200
Probable version skew in pre-compiled '/home/david/git/PDF-API6/../PDF-Class-p6/lib/PDF/Font.pm (PDF::Font)' (cause: no object at index 778)

I can reproduce the error with a very simple test program:

use PDF::API6;
use PDF::Font::CIDFontType2;

==SORRY!=== Error while compiling /tmp/site#sources/58028D652811A12AAA9177AE3895DE5D47ADE0FD (PDF::Font::CIDFontType2) Probable version skew in pre-compiled 'site#sources/BFD03D5F53D8E5928328176228516E260AB2C81D (PDF::Font)' (cause: no object at index 723) at /tmp/site#sources/58028D652811A12AAA9177AE3895DE5D47ADE0FD (PDF::Font::CIDFontType2):5

Evidently, PDF files with CIDFontType2 fonts are currently failing.

dwarring commented 6 years ago

Latest PDF 0.3.0 and PDF::Class 0.1.3 fixes the secondary error Cannot find method 'specialize' on object of type Perl6::Metamodel::ClassHOW error. In a nutshell the PDF::COS coercements were being caused by attempts to mixin a class instead of a role, giving this error.

perl6 -e'class C1 {}; class C2 {}; my C1 $c .=new; $c.^mixin: C2'
Cannot find method 'specialize' on object of type Perl6::Metamodel::ClassHOW
  in block <unit> at -e line 1

Still not entirely sure of the primary Probable version skew in pre-compiled errors during upgrades. From past experience these may indicate that classes or roles are being mutated at run-time, e.g. by adding extra methods.

frithnanth commented 6 years ago

Thank you

dwarring commented 6 years ago

Hopefully better now after changing the composition of some classes and additional fixes in the PDF module. Please try again when you get a chance.

dwarring commented 6 years ago

Also fixed some (but not all) the the noisy tests in PDF::Content and PDF::Class

frithnanth commented 6 years ago

I see that PDF::Content still displays some errors:

error processing 'RG' (SetStrokeRGB) operator
error processing 'TL' (SetTextLeading) operator
error processing 'Tf' (SetFont) operator

but the installation proceeds anyway. Thank you!