lizmat / App-Rak

21st century grep / find / ack / ag / rg on steroids
Artistic License 2.0
152 stars 7 forks source link

Failure with json file search #20

Closed librasteve closed 1 year ago

librasteve commented 1 year ago

Hi

I am working (slowly) through your examples in the blog part I and have the below error.

Basically this is a docker image with just rakudo installed on ubuntu:latest https://github.com/p6steve/raku-Dockerfiles/tree/main/basic-ma

Welcome to Rakudo™ v2022.07. Implementing the Raku® Programming Language v6.d. Built on MoarVM version 2022.07.

My search target is ~/rakudo (the target dir for the rakudo build since those are the only files I have in this build) ;-)

I am hoping to install this cool tool everywhere so thus the shakedown...

~p6steve

root@5f31dd2db51a:~# rak --json-per-file '*<name>'
rakudo/tools/build/binary-release/Windows/META6.json
Star::Modules

rakudo/src/nqp-2022.07/nqp-2022.07/package.json
nqp-js-cross-compiling

rakudo/src/nqp-2022.07/nqp-2022.07/nqp-js-on-js/package.json
nqp-js-on-js

rakudo/src/nqp-2022.07/nqp-2022.07/src/vm/js/nqp-runtime/package.json
nqp-runtime

rakudo/src/nqp-2022.07/nqp-2022.07/src/vm/js/nqp-runtime/tables/shiftjis.json
Type Array does not support associative indexing.
  in sub stringify at /root/rakudo/share/perl6/site/sources/3A2871EBDC4A0F35E7C904144CBF80147A27AC84 (App::Rak) line 733
  in block  at /root/rakudo/share/perl6/site/sources/3A2871EBDC4A0F35E7C904144CBF80147A27AC84 (App::Rak) line 846
  in block  at /root/rakudo/share/perl6/site/sources/3A2871EBDC4A0F35E7C904144CBF80147A27AC84 (App::Rak) line 758
  in sub show-results at /root/rakudo/share/perl6/site/sources/3A2871EBDC4A0F35E7C904144CBF80147A27AC84 (App::Rak) line 744
  in sub rak-results at /root/rakudo/share/perl6/site/sources/3A2871EBDC4A0F35E7C904144CBF80147A27AC84 (App::Rak) line 626
  in sub action-json-per-file at /root/rakudo/share/perl6/site/sources/3A2871EBDC4A0F35E7C904144CBF80147A27AC84 (App::Rak) line 2444
  in sub main at /root/rakudo/share/perl6/site/sources/3A2871EBDC4A0F35E7C904144CBF80147A27AC84 (App::Rak) line 412
  in block <unit> at /root/rakudo/share/perl6/site/resources/C97545B72F13E645CCCB7F3CC631C73435E74E4C line 3
  in sub MAIN at /root/rakudo/share/perl6/site/bin/rak line 3
  in block <unit> at /root/rakudo/share/perl6/site/bin/rak line 1
lizmat commented 1 year ago

Could it be that rakudo/src/nqp-2022.07/nqp-2022.07/src/vm/js/nqp-runtime/tables/shiftjis.json is not a Hash at the top level? But an Array?

lizmat commented 1 year ago

If that is the case, then maybe your pattern should be '{ try .<name> }' ?

lizmat commented 1 year ago

Or something like '{ (try .<name>) // "(unknown)" }'

librasteve commented 1 year ago

oh ok - sure that works rak --json-per-file '{try .<name> // "(unknown)"}' --unique works beautifully I was blindly following the example you gave in your blog... https://dev.to/lizmat/its-time-to-rak-part-1-30ji I will make a comment now and close this as a code issue

lizmat commented 1 year ago

The example in the blog assumed that all JSON files were structured the same way. If they are not, you need to guard against that. I've considered auto-guarding against it, but then the file would just be silently ignored. Which could be worse, or better. YMMV :-)