Placeholder Image

字幕表 動画を再生する

  • everyone.

  • So the other day I was working on my web up, called it.

  • It does go on.

  • I run into a really nasty bug.

  • It took me a long time to solve it.

  • Maybe, like four hours.

  • You know, overall, it was just a terrible experience, just debugging it.

  • But I decided to take this opportunity to, you know, talk about debugging in this video.

  • So I'm gonna first walk you through how I solved this particular body.

  • Exactly.

  • And then along the way, I'm also gonna give you some general tips on debugging, so you'll be able to use thes tips on any programming language, even though I'm gonna be using python in this particular video.

  • Okay, so here's the website I'm making right now.

  • I'm running this website locally.

  • You can tell that just by looking at the Euro bar.

  • This is tthe e I P address that represents my local server.

  • Now, when you scroll down on this landing page on when you click this button that says sign up signing with Twitter, you can sign up or signing with Twitter, go to Twitter and then back to my website.

  • So that's the expected behaviour.

  • But The problem was when I put this website on heroic Ooh, which is a website that helps you host your own website in the cloud.

  • I started getting a buck.

  • Okay, so let me just quickly show you what the bug was exactly.

  • Let me go to the version off my website that's hosted heroic Ooh, right here on when I clicked the same button sun up signing with Twitter.

  • I got this error social network logging failure.

  • And the funny thing was, I was running exactly the same code for my local server as well as on heroin.

  • So what's happening here?

  • Okay, so the first thing I thought when I got this air is that the obvious difference between these two situations is the euros.

  • So I thought maybe I set up something incorrectly on Twitter's developer website in regards to that year else.

  • And that actually brings me to the first tip I wanted to talk about for debugging in general.

  • On that is to come up with a hypothesis on test it on, come up with another hypothesis on test that so you need to, you know, really think like a scientist when your debugging like I said the initial hypothesis I had for this particular bug was that maybe I set up something incorrectly on Twitter's developer website.

  • So I checked it on.

  • I checked.

  • You know, this section in particular.

  • Call back your L.

  • I checked.

  • If it's https or http, for example, I tried both, but none of those things worked.

  • So at that point, I wanted to come out with another hypothesis.

  • But I was sort of out of ideas, so I decided to first look into the code to try to see you know, the cause of the bug.

  • But before doing that, I wanted to, you know, reproduce the bug locally, or at least reproduce something similar to the bug locally.

  • And that's actually my second tip for debugging.

  • I think we're producing The bug locally is important because, you know, trying to find the cause of a bug usually takes a lot of trials and errors you need.

  • Thio sometimes play around with the coat, too on.

  • If you do it with the server, you might take a lot of time just communicating with the server.

  • So, ideally, when it's possible and when it's convenient, used to try to reproduce the same bug or a similar bug locally, and they analyze it there.

  • First on in this particular case, I just went back Thio Twitter's developer website.

  • And then I actually deleted one of the callback.

  • You or else, you know, the one for the local server on when I did that.

  • And when I tried the same thing again on the local server, I actually got the same error.

  • So this is not necessarily the same bug.

  • But I thought, you know, once I analyzed this particular error, I'll be able to use, you know, the east site I can get from that analysis to find the cause of the oars.

  • No, buck.

  • So that's exactly what I did, Aunt.

  • To analyze wth e error that I just created all my local silver.

  • More carefully, I started reading into the source code, and that's actually my third trip.

  • To read the source code carefully and then play around with it on this process was actually not that simple for me because I was using this pretty big open source library called Jungle All off.

  • You know, you don't always have to read the source code off every single library you're using.

  • But I think it's pretty common to have to be able to read other people's code.

  • For example, if you end up working with other developers at work.

  • Anyway, I started looking through this code base somewhere on I found this directory.

  • Ah, this is Porter.

  • So I thought, you know, this must be the relevant directory here because we're using a Twitter Loggins on, you know, for example, I found view.

  • Stop.

  • I file here in the traitor directory, and I thought it was relevant.

  • So what I did was I copied this foul and then pasted it locally to override some of the functions in this file.

  • Andi, I actually did the same thing for another file on.

  • I called it off of you.

  • Stop I because this was views DuPuy within the OSS directory and then, you know, looking through these two files, I thought, Okay, this view function right here in off use must be the view that's called when this girl is opened by the user.

  • That was sort of my hypothesis on to test that I decided to, you know, put some prints statements here.

  • That's actually my four step for debugging to be able to use Prince statements effectively.

  • So let me show you how I usually go about using Prince Tim.

  • It's for debugging here.

  • I'm just gonna write print.

  • Why Gay one.

  • You know why, Kay?

  • It's my name on the reason that I put my name in my prince statements.

  • What I'm debugging is so that they're very distinct.

  • You know, sometimes there are a lot of things being printed into the log on.

  • This way, it's gonna be much easier to find my prince statements.

  • And then the reason I put a number after my name is so that you know, we could do things like Prince like a one here and then print.

  • Why, Kate to hear.

  • And this way, if we see, both of them will know that.

  • You know, both of these parts are being executed.

  • But if we only see why, Kate, one in the log will know that you know, on Lee, this part is being executed.

  • But not this part.

  • So here, just as an example, we can you know, spam.

  • This whole function with Prince statements somewhere.

  • Eso y k three here.

  • And then why k for here on Let's see what happens.

  • Let me just refresh this page When I go to terminal, I see all of these like a 123 and four.

  • So from that we can tell that.

  • You know, all of these parts of this function are being executed, and then it goes to self that dispatch.

  • So let's look into this function.

  • OK, so I looked into that function and then I kept repeating the same pattern.

  • Basically analyze the code by using a bunch of prints statements and then try to understand what's the next function that I should look at.

  • And then eventually I got to dysfunction called Get requests token.

  • So I kept doing basically the same thing as what I did earlier for this function.

  • You know, I added a few more prints demons, and then I decided to focus on this particular variable called a response, because it looks like a response that we get from Twitter when we try todo twitter log in.

  • And so I'm printing the response viable here after the string response.

  • So let's see what that looks like.

  • It's just this one.

  • We have response, and then the response viable is response for three.

  • That's actually not that helpful.

  • So we need to examine it, you know, a little bit more carefully.

  • And that actually brings me to my fifth tip for debugging on that is to use a d bugger effectively.

  • So just in case you don't know what a de burger is, it's a way to run this code and then stop it wherever you want.

  • I examined the code more carefully, so here I can d'oh!

  • Import PDP python debunker and then p b that set trace this way we should be able to When we were fresh that page that way so earlier We should be able to stop it right here.

  • So in terminal, when you're in the d bugger you issued see something like this P p p t b.

  • And then there are a lot of different commands here, but the only command that matters Ah, here is peak, which you can use to print anything you wanna print.

  • So if you d'oh p response, you should be able to print that on if you d'oh response that dicked that keys you be able to see you know what variables this object task on there is a bunch of stuff here, but actually the only one that's important is content.

  • And if you do response that content actually response dark content.

  • This is why you see, I get callback euro not approved for this client application, which actually makes sense because, you know, I got rid of the euro for the local application.

  • So you might say, you know, what's the point of doing all of this?

  • Well, the point is that you know, I'm gonna go back Thio the original code and they hear what we can do is we can print not just response, but also response.

  • That's content.

  • I think so.

  • This way we'll be able to print more information about the error that we're getting.

  • We'll be able to do the same thing for our server in the cloud to.

  • So after that, I committed all of these changes on gets.

  • And there I pushed those changes to Haruko so we can test it there.

  • And they're, you know, on the Harold Cooper's off the Web sites.

  • I made sure you know, I'm still getting the same error on I checked the logs with this command.

  • And here this is what we're getting response.

  • Content is a bunch of stuff here, and then the message is could not authenticate you.

  • So it's obviously different from the era that we saw earlier.

  • And so I started thinking, you know, what could be the cause of this could not have sent to get you?

  • Well, you know, one common reason off not being able to authenticate it is that the passwords are wrong.

  • Right on.

  • It turned out when I was copying my Twitter keys Twitter ap I keys from local to heroic.

  • Ooh, using this thing called environment variables, I missed one letter from from one of my passwords, and that's actually why I was getting this bug.

  • And that's why I ended up spending for it's just debunking it.

  • You might say, You know, you could reject it like in the first place when you got the bug, but sometimes you just don't think of it on, you know, you end up wasting time.

  • Ah, anyway, that's it for this video.

  • Hopefully, you learn something new today.

  • If you have any other development tips, feel free to share them in the common six room because you know other people might be able to learn from them.

  • And I'm gonna put the code I showed you today at this euro A cz usual on the thank you.

  • As always for watching my videos.

  • I'll see you guys in the next one.

everyone.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

すべての開発者が知っておくべき5つのデバッグのヒント|Build a Startup #7 (5 Debugging Tips Every Developer Should Know | Build a Startup #7)

  • 2 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語