Lesson 11 of 18

Global Error Handling

Duration: 4:46 Watch on YouTube (external link, opens in new tab)

Markdown version

In this lesson

Roy Osherove uses the on failure tab, the global error handler, to export the FinalBuilder (external link, opens in new tab) log to an HTML file in a logs folder when anything fails. The first run cannot export the log because the folder does not exist, so he adds a create directory action before the export, and he shows how a send email action can attach the log file.

Transcript

689 words

[00:02] (external link, opens in new tab) Let's talk about global error handling and standard error handling. So let's say that if at any point in time here we have an error, we'd like to get an email with a log file or something like this. So by default there's a global error handler. Wherever anything happens, you can go to on failure and here you can basically add a task. So one of the tasks you'd like to do is for example to say that there's a log file. We can export a log to a file that's the FinalBuilder log.

[00:32] (external link, opens in new tab) So we can say let's create an output file in the FB project directory slash logs slash full dot log. It can be an HTML. Let's let's make it HTML actually. It could be text or XML. So let's make it a HTML and we can export from the root of the project. By default all included project will only export itself.

[01:04] (external link, opens in new tab) If we have multiple projects we that we that we have invoked from within FinalBuilder we can export those logs as well. We can make it only include air actions but we don't have to. And by default I just like this. We can also just include a specific fragment or just the entire log or just logs from a specific action. And that's it. So, let's say that we go into main

[01:34] (external link, opens in new tab) And we want to create some sort of failure. So, let's create a failure here in that we go like this. We give it a bad parameter. So now let me run this and see what happens and we definitely get errors here and we see that by default we got the on failure. Okay so this is very important on failure happened.

[02:05] (external link, opens in new tab) If we go to the main action, you'll see that the script stopped at this stage. We got on failure and if we are lucky enough and we configured everything okay, we should have a logs directory. However, we do not and that might be a problem, right? So, let's try to see what the hell happened. Export log file error exporting cannot create the file.

[02:35] (external link, opens in new tab) The system cannot find the path specified. So we don't have the path here. So we could try to create the path. For example, create let you see I'm searching here. Say create directory. We can create a directory called FB project directory slashblogs if one doesn't exist. And I can force a directory if one is not existing. So if I wanted to force it, I would say a /b C and I said force directories, it would create all the directories under C so that it can create this directory.

[03:13] (external link, opens in new tab) But for now, we just have a single directory and that's the one. And let me move that up. So now even if the directory does not exist, before we export, we create this directory. it will not delete it if it already exists. So let me try to run this again and this time we see we have export and that's actually completed. So when we go down and we want to see the file that was created we can open the directory. Now if we double click this you will see under FP demo we have logs directory and then we have full.

[03:46] (external link, opens in new tab) Let me double click this and now we see this interesting log file going on. We can actually open the description of each one and see what happened. And if we wanted to, we can even email stuff. So, we can let's look for the email. Send an email. So, you almost always have what you're looking for. You can say what's the SMTP host, sender, recipient, message, what to attach, and we can attach

[04:19] (external link, opens in new tab) Specific log files. We can say FB project directory /logs slash full.html. And this is important. Add the plus here. Otherwise, it will not be written. Only stuff written here will actually be used. And if it's missing, you can just ignore it. Otherwise, you're going to get an error. So that's the global error handling so far.