From the course: Debug Your Code with AI

Gathering context for debugging

From the course: Debug Your Code with AI

Gathering context for debugging

- [Instructor] We're going to gather context for debugging. We have this pretty obnoxious issue with lots of output. I have a little bit of an idea of what's going on, what's causing this. After all, I was the one that opened this issue and I provided a little bit of extra information, which I mean, it has been a while. This was a few years ago, and I don't quite remember exactly what was going on, but I think, I think I got it. So what happened was that there's a test that is calling a function, a module that it shouldn't be calling. And then the problem is that there are warnings happening and the test doesn't run. Or actually one, you know, a few of them run. One is failed because it fails because of that problem of the thing that it shouldn't call, like function, that it shouldn't call. And it issues a lot of warnings. And that, the problem with that is that when you run the tests with the plugin, it'll say, "Hey, there's no, there are no failed test. There's no report. I don't know what to do." So I think here, this is correct. The fix, which would help with many other problems here is that the priority in parsing needs to be the last line where Pytest reports how many passing, failing, and skip errors. So that means this one right here. So this is the source of truth, and then the rest is just extra, right? So we have at least this, then that's good. So what's the strategy here? This is the bug, this is the issue. Well, part of the problem is if I go and show you the actual plugin that is written in VimScript, and part of the biggest problem here is that, well, it's been a while since I've touched this file and it's, you know, a lot of, a lot of lines. So the, I'm going to scroll all the way to the bottom and it's over 1,000 lines. It's almost, almost 1,500 lines of a language that I don't use often. And you can see that this is, well, you know, full featured plugin in a language that is also not very popular. So we have an interesting mix here. We have a language that is not very popular. It is a very, it's a very complete plugin that has tons of content and lots of different functionality that I need to go through in order to understand exactly what's going on. This is what large language models can help us with. And so we are here to gather the context. So what will be the context? Well, instead of asking, instead of asking the AI tool to generate a test and, and try to execute that, well, I went ahead and did that for it. So now I'm going to use the web interface, I'm going to use Claude here. You can use other things and these techniques that I'm going to show you are going to be, well, pretty similar. Let's start by providing the context. What's important here is that I, this is a Vim plugin, right? So I explained what it is, a Vim plugin that tests Python code using Pytest. Pytest Vim plugin has to parse the output of the test and report that in a buffer. So this is written in VimScript and this is important because I need the large language model to understand that that is actually a thing that we're going to be doing. I will provide you, and here's the context that it is specifically. I will provide you the issue, I will provide you an example test file, which is something that I've written already, with its warning output and the complete Vim plugin and I want you to suggest me the potential fixes to the Vim plugin. I know it's a problem in the plugin so I'm making it easier by hinting to the large language model where the problem may be so he can focus on that. So I'm saying, in the Vim plugin, I want you to suggest me potential fixes. This is important to say as well. I do not want to regenerate the whole Vim file. It is, after all, 1,500 lines of VimScript which I don't need. The bigger the surface of a large language model that has to generate or produce, the greater the chance that he might make a mistake. So in this case, we're actually telling it to avoid that, and I do this. All right, what's the issue? I pasted the issue from the, the GitHub issue, the description. I'm providing the test file. This, right here, is the test file is pretty simple, is I just, I knew that how to make it very quick and very easy. The test file output, well this is what happens on inside the, the (indistinct) and this is the output. You can see there's a lot of, there's a lot of output here. And, and that's a problem. And then right here at the bottom, like I uploaded the, the whole plugin. So I'm going to, I'm going to let Claude, in this case, go through these and provide me a potential root, well, a potential root cause analysis, sure. Handle output functions, function lines 459 to 497. It identifies several issues. Now, with this amount of investigation, look at this. I mean with, it's still generating and I'll have to, I'll have to choose what path I want to follow. But with this amount of problems, what I need to do is actually, well use this to my advantage and not completely offload all of the investigation to the AI service or the AI tool. In this case, this allows me to make an informed decision, which is crucial when we're, when we're trying to go and perform some debugging. So I'll stop there and then later, we'll come back and go through some of these recommendations and try to gather an understanding.

Contents