Altai-man / sample-cro-crud

Sample CRUD application written using Cro::HTTP
3 stars 3 forks source link

"Type check failed in assignment to $!value" error when attempting to run service.p6 #2

Open Xliff opened 4 years ago

Xliff commented 4 years ago

Here is the full exception message:

Type check failed in assignment to $!value; expected CookieValue but got Str ("\"2|1:0|10:157552209...)
  in submethod BUILD at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/site/sources/CD22D0E48942B9E09B5DEB54F2D03099153D588B (Cro::HTTP::Cookie) line 131
  in method unpack-cookie at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/site/sources/594B58A58F2284EEE6F7805156E042DA4D050BEE (Cro::HTTP::Request) line 168
  in method cookie-value at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/site/sources/594B58A58F2284EEE6F7805156E042DA4D050BEE (Cro::HTTP::Request) line 188
  in method existing-session at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/site/sources/F2761A62664DEACA7605AA777F6ADEADD7A9B229 (Cro::HTTP::Session::InMemory) line 95
  in block  at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/site/sources/F2761A62664DEACA7605AA777F6ADEADD7A9B229 (Cro::HTTP::Session::InMemory) line 89
  in block  at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/site/sources/D69ADAA9BE77DD33B9702EA1BCD4D35E6379EA88 (Cro::HTTP::Internal) line 22
  in block  at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/site/sources/A0FA8341EF2FAEC61CD720BC282DD850EC071B03 (Cro::HTTP::RequestParser) line 122
  in block  at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/site/sources/A0FA8341EF2FAEC61CD720BC282DD850EC071B03 (Cro::HTTP::RequestParser) line 93
  in block  at /home/cbwood/Projects/rakudobrew/versions/moar-blead/install/share/perl6/site/sources/84057C1B326A87C95644C954217DFD610AA89CF2 (Cro::TCP) line 53
Xliff commented 4 years ago

It looks to be the cookie value that's failing. It's not specific to your project, as it looks to be internal to Cro.

FWIW, the value of the cookie looks like this: "2|1:0|10:1575522098|23:username-localhost-8888|44:OWZjMjY4NmNlNjU2NDQ3NGE2YWQ2Zjg5YmE3MzBmNDY

Please note the starting double-quote without one at the end.

Xliff commented 4 years ago

Here's a fix for the problem. I think there's a better way to fix it, but now it looks to be a Cro::HTTP issue, not an issue with this project:

diff --git a/lib/Cro/HTTP/Request.pm6 b/lib/Cro/HTTP/Request.pm6
index 988842f..07f3127 100644
--- a/lib/Cro/HTTP/Request.pm6
+++ b/lib/Cro/HTTP/Request.pm6
@@ -165,6 +165,9 @@ class Cro::HTTP::Request does Cro::HTTP::Message {
         my @res;
         for @str {
             my ($name, $value) = $_.split('=');
+            # cw: Horrible fix, but just to see if it works.
+            $value .= substr(1)
+              if $value.starts-with('"') && $value.ends-with('"').not;
             @res.push: Cro::HTTP::Cookie.new(:$name, :$value) if $name;
         }
         @res;
Altai-man commented 4 years ago

Hi. I just run the sample with latest rakudo and it works as a charm. I also have latest versions of cro deps. I indeed fixed a simple bug, but couldn't reproduce scary exception you got. Can you, please, provide a detailed step by step guide of reproducing this? With versions and so on.

Xliff commented 4 years ago

FWIW, there were no steps to reproduce. I followed git instructions and tried to start the blog. The first request caused that exception.

I will try again with latest Rakudo.

melezhik commented 2 years ago

I have the same issue

melezhik commented 2 years ago

it happens to me when there are some old cookies ... after cookies are cleaned the issue has gone

Altai-man commented 2 years ago

So I am looking into it after a year, hmm.

What cookie do you have (you posted the value, but not its name) and what origin does it have? The two cookies created by this project are color-theme and _session, both of them are not creating what you posted.

For your interest, I admit there was a dumb bug in the cookie value parser when there are two doublequotes, and this is fixed with https://github.com/croservices/cro-http/pull/157

But the issue is that your value (with " at the beginning and no one at the end) is then bogus and go against RFC 6265. Maybe something important creates such bogus set-cookie commands and we have to comply for the sake of backward compat, but unless we know what creates them we don't know if we should.

melezhik commented 2 years ago

Hi! t's hard to reproduce, as i said , the issue had gone after i cleaned the cookie . all i know.

my suggestion is cro would give more human readable information in that case, apparently the message i saw in a log, similar to what you had does not help to troubleshoot the problem ...