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

Exception when running example code #12

Open
stoopdapoop opened this issue Aug 7, 2022 · 6 comments
Open

Exception when running example code #12

stoopdapoop opened this issue Aug 7, 2022 · 6 comments

Comments

@stoopdapoop
Copy link
Contributor

So I've copied the example code from the readme:

            var client = new CraigslistStreamingClient();

            var request = new SearchForSaleRequest(
                "losangeles",
                SearchForSaleRequest.Categories.Electronics)
            {
                SearchText = "graphics card",
            };

            await foreach (var posting in client.StreamPostings(request))
            {
                Console.WriteLine($"{posting.Price} : {posting.Title} - {posting.PostingUrl}");
            }

But I get an exception after it iterates over a few of the results.

Exception thrown: 'System.ArgumentNullException' in System.Private.CoreLib.dll
Exception thrown: 'System.ArgumentNullException' in System.Private.CoreLib.dll
An exception of type 'System.ArgumentNullException' occurred in System.Private.CoreLib.dll but was not handled in user code
Value cannot be null.

This is in dotNet 6.0. I can provide more info if needed

@wesleythorsen1
Copy link
Owner

I am unable to reproduce. Do you have more details on the exception (stack trace) or what exact search parameters you used? It's possible that some of the values the PageParser is expecting from the craigslist html aren't returned, and is throwing this exception when parsing into a Posting object.

@stoopdapoop
Copy link
Contributor Author

Yeah, the above code is the exact code used, I only added a "using DotnetCraigslist;" at the top so it'd compile.

I got version 0.2.0 from nuget in visual studio.

Here's the stack trace:

<title>Document</title>
  Name Value Type
  StackTrace " at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)\r\n at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable1 source, Func2 selector)\r\n at DotnetCraigslist.PageParser.ParsePosting(PostingRequest request, Stream content)\r\n at DotnetCraigslist.CraigslistClient.d__8.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at DotnetCraigslist.CraigslistStreamingClient.d__5.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at DotnetCraigslist.CraigslistStreamingClient.d__5.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore1.ThrowForFailedGetResult(Int16 token)\r\n at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore1.GetResult(Int16 token)\r\n at DotnetCraigslist.CraigslistStreamingClient.d__5.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)\r\n at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()\r\n at Program.<$>d__0.MoveNext() in C:\Projects\deleteme\deleteme\Program.cs:line 13\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Program.<$>d__0.MoveNext() in C:\Projects\deleteme\deleteme\Program.cs:line 13" string

It outputs 2 of the results, then excepts on the third, which right now happens to be a link to this entry https://losangeles.craigslist.org/wst/ele/d/los-angeles-amd-matx-gaming-computer/7518591985.html

There's nothing that seems off about this page.

@wesleythorsen1
Copy link
Owner

I was able to reproduce, there was a bug with version 0.2.0. The bug has since been fixed and is deployed in the latest version (0.4.0).

@stoopdapoop
Copy link
Contributor Author

awesome, I can't try it till this friday, but I'll close this now and just re-open if I still have issues.

@stoopdapoop
Copy link
Contributor Author

Hey there, so I'm running 0.4.0 and it was working for a couple of days, but now I get a different exception when running the same code as above.

`

<title>Document</title>
  Name Value Type
$exception {"Value cannot be null. (Parameter 'source')"} System.ArgumentNullException
  ▶ Data {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
  HResult -2147467261 int
  HelpLink null string
  ▶ InnerException null System.Exception
  Message "Value cannot be null. (Parameter 'source')" string
  ParamName "source" string
  Source "System.Linq" string
  StackTrace " at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)\r\n at System.Linq.Enumerable.Select[TSource,TResult](IEnumerable1 source, Func2 selector)\r\n at DotnetCraigslist.PageParser.ParsePosting(PostingRequest request, Stream content)\r\n at DotnetCraigslist.CraigslistClient.d__8.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at DotnetCraigslist.CraigslistStreamingClient.d__5.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at DotnetCraigslist.CraigslistStreamingClient.d__5.MoveNext()\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore1.ThrowForFailedGetResult(Int16 token)\r\n at System.Threading.Tasks.Sources.ManualResetValueTaskSourceCore1.GetResult(Int16 token)\r\n at DotnetCraigslist.CraigslistStreamingClient.d__5.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)\r\n at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()\r\n at Program.<$>d__0.MoveNext() in C:\Projects\deleteme\deleteme\Program.cs:line 13\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Program.<$>d__0.MoveNext() in C:\Projects\deleteme\deleteme\Program.cs:line 13" string
  ▶ TargetSite {Void ThrowArgumentNullException(System.Linq.ExceptionArgument)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
  ▶ Static members    
  ▶ Non-Public members    
`

@stoopdapoop stoopdapoop reopened this Aug 17, 2022
@stoopdapoop
Copy link
Contributor Author

So I was able to dig and find what was causing the problem. Under some circumstances craigslist returns a page that states

"We've detected you are using a browser that is missing critical features.
Please visit craigslist from a modern browser."

This page doesn't have any results to parse, so the results parser crashes when trying access them. I wonder what can be done to prevent this.

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

2 participants