Hey there stranger!
Sign up to get access.
Seek Errors When Coding Apps Script
About this Tutorial
00:13 I go through a few different things that you need to have in your head and sort of get over in order to be a successful coder.
00:20 But one of those is seek errors that I mentioned in that video, and I wanted to make sure that we did this together, not just not just say it, but live it.
00:33 And so in this video today, I'm gonna go with you and actually seek out some errors, some simple errors that might occur.
00:42 And once they occur, you'll see the error. We'll google some errors. And that is literally the, like the advice that I give you is if you get an error, don't get sad, don't get don't, don't stop.
00:56 Keep going. Try to find out what the error means. And one of the things that I mentioned is to actually create errors so you know what they mean when you unintentionally do it.
01:06 So we're gonna intentionally create some errors today and then see what those errors do. So we're just gonna go up to extensions app script up here.
01:13 I already have this function that is an unopened function, and all it does is create a custom menu of two items.
01:20 Those two items are both toast, which will show up a little menu down here around my face over here on the bottom right.
01:28 So that's all it does now, and we might add some more if we wanna see some more errors, but I have already saved this.
01:34 And actually I'm gonna this on open has to be, has to actually open the sheet, has actually has to be open.
01:41 So we will do that. I'm just gonna refresh the sheet and it'll open. It takes a bit a little bit of moment here for the unopened to actually run.
01:51 And there we go. We got a custom menu and now I'll show you what that looks like. Might be behind.
01:56 Ah, we have to always, the first time we run the script, we have to authorize it. We have to pick which account we have, we're gonna allow.
02:10 And then I think we have to run it again, and it should be right here under my face. There we go.
02:14 Okay, I'll move my face there. Menu item two. Did we click first item? Oh, they both say menu item two.
02:21 Okay let's go back to script and see. No they shouldn't. Oh, it's because there's two <laugh>. I already made an error here.
02:31 This is supposed to be menu item two here. So that's good. So now that was an error that didn't actually error out.
02:38 We just had the same result for two different things that I thought should be different. So let's see that again.
02:43 So first item should say down here in a toast menu, item one. Perfect. It's says finished script. And second item menu item two.
02:51 Great. So let's see, let's have a space here. Menu item one. First off, it Doesn't even let me save down here.
03:03 It's says Syntax error, syntax error, unexpected identifier line 10, file code js. So first off, in our, our files are over here and this is code js, correct?
03:15 And we go there's these numbers up and down here that say one through 16 right now. And every line of code that we add is gonna add a line, a number here.
03:26 So we can go to row 10 and we will see right here, function menu item. Now, if we don't know that we need this to be all one word, we, let's find out what this syntax error, if we just copy the entire, it actually gives us a button to copy.
03:45 We're gonna open a new a new window here. We're gonna Google it. And let's just go to the top result stack overflow, unexpected end of input.
03:55 That is not a, we have unexpected identifier, not unexpected end of input. So let's see, let's look at this one.
04:06 That actually is un unexpected identifier. And so this person is, does not have the same problem as us. But we can also scroll down to the answer.
04:18 If you encounter this problem specifically pertaining to a syntax error that you never had before, it may be Google switch over from Mozilla Rhino to Chrome v8.
04:29 I don't think that's correct. I don't think that's the issue. I mean, I know the issue, right? We have a space here, we have a pink thing, we have, this is even underlined red.
04:38 And right here, this curly bracket has a something red. So let's see what happens if we keep that menu item one, but we delete the parenthesis, we're gonna save command S and again, we have a problem and it says syntax error, syntax error, unexpected token.
04:59 And it gives us the curly bracket line 10, file code js, again, file code JS 10 here, and we can see the curly bracket right there.
05:08 And now, if we didn't know that we needed a parenthesis, what you could do now I'm gonna share with you, you know, we now know we have to have a parenthesis right here, but if you don't remember that, what you could do is create a brand new sheet and open it up, the app script, open up and you can, you'll see the syntax.
05:29 It'll say function space, my function with the parenthesis, then space, then a curly bracket. So you would be able to see the correct syntax if you wish.
05:41 Let's run it again. We'll get this error again and let's again copy and paste that into a Google search here.
05:52 First off, I do want to add over on this one. Let's see if we can just add at the, the beginning apps script.
06:00 Wonder if that gives us a better yeah, maybe on Reddit. Hmm. See they don't have the same problem. Okay, so apparently this person said there was an invisible character before my function declaration.
06:21 Pressing backspace in front of the function was enough to solve it. So there was some weird character right in front of this function or after the word function before on edit.
06:33 That might happen, maybe, let's see, I don't want to get too far away, but let's see what happens if we have no function.
06:40 Let's command s save syntax error. Unexpected token, same thing. We have this function, we have all this is wrong, right?
06:50 Function should be blue. First off, then a space, and then one word, no spaces, and then parenthesis. But let's see, is it the same exact error?
07:01 Oh, this actually saved <laugh>. Great. Okay, so we didn't get the correct index. This parenthesis probably should be connected to here.
07:10 But let's see if anything doesn't run, it still runs fine. In fact, that's a surprise to me. But that, that actually ran, I guess we don't need it to, the parenthesis does not have to actually be connected to the one word.
07:23 Here. We do need one word. Let's see if we save that un unexpected identifier as well. So can see the red underlying here.
07:33 Again, the solution is this all has to be one word. You need the parenthesis. But one thing I want to point out about this, when you have this unexpected token, what the first thing you might think about is that that is the wrong thing there.
07:51 That the curly bracket is wrong, but very common. Pr pr, the very common problem with errors is that actually the error occurs before the error.
08:04 So the problem is not the curly bracket at all in this case, it's the fact that we have missing parenthesis here.
08:11 Now, let's see if we miss out on the last parenthesis. Let's save. And it says syntax error, syntax error, unexpected end of input.
08:20 And again, it will tell us the line. So it'll tell us 18. And you saw me delete the pearl bracket on line 12, but it's telling us the errors on 18.
08:30 Why is that? It's because this curly bracket is being matched with the second one here. And it's saying this is all fine, but the actual problem there, the codes problem is over on line 18 cuz it's like we need some ending.
08:48 In fact, it's this beginning one. And if you notice let me select this curly bracket Whenever I select this one or even just put my cursor right next to it, in front of it, behind it, it highlights the ending curly bracket.
09:04 Same down here, line 14. It, it highlights line 16. So if we add a curly bracket here, right now, there is no highlight.
09:13 It doesn't have an end. So if we add one now it lines it up and it pairs it. Now this i, this, this editor here is very smart.
09:23 It knows we need another bracket so it knows which one is matched with which. Alright, let's go hunting for some more errors.
09:32 So again, I'm gonna save this now we have no more errors, it is still running fine. First item. Got our little toast here.
09:42 So let's go find some more errors. Let's see what happens if we misspell var here and maybe we have va, it'll say syntax error, unexpected identifier lying to, and it actually underlines the UI here when in actuality it should be v a R for variable.
09:58 You could also use const. Let's save that. Same thing there. If we have C O N S cons, it says unexpected identifier line two, same, it underlines ui.
10:13 But the actual problem is that we don't have variable or constant here. Constant. Let's see what happens if we misspell spreadsheet app, let's save it.
10:23 Totally fine for now. And actually let's not do that one because it's already open. It's not gonna run. Let's do that one menu item one.
10:31 Okay, let us save and we're gonna run it. Great reference error spreadsheet app is not defined. Again, you might get this error because you might not know that the spreadsheet app has to be capitalized as capitalized.
10:44 A and it's not telling us this, right? It's saying reference error, which what the hell does that mean? And it says spreadsheet app not defined, but let's copy and paste it into Google reference error spreadsheet app is not defined.
10:57 And we look here, take a look at tutorials. Oh my god, this is not an answer. <laugh> doesn't work like that.
11:08 Maybe this one doesn't work like that. You might have to guess that this is, I guess you have to guess that these are error message is not correct.
11:19 Error message in script after adding a column on edits fine spreadsheet app is spelled fine. All right? You're not gonna actually be able to google this.
11:30 But again, just watching this video, you now are well aware that this is, has to be a capital S spreadsheet app and we should, let's get un capitalized a save it.
11:41 Now we should get the same error. Let's dismiss that one. Spreadsheet app is not defined. See, it gives us the incorrect spelling that we spelled it.
11:52 Let's see Details. All right, doesn't tell us more details at all. All right, so we can know that it needs to be capital s, capital a spreadsheet app.
12:03 Let's see what happens if we don't capitalize the A and get active, we'll save it and we'll run it. Now you might think 13 minutes or 12 minutes into this video, like, oh my God, this is a long video and oh my God, this process takes a long time.
12:18 And it does, it does take a long time. If you don't know what you're doing as it probably does for anything, it takes a long time to juggle, right?
12:26 If you don't know how to juggle my hope is that with this video, you're able to see that we're not scared of errors.
12:35 That the errors might, if you Google them, they might not give you the exact answer. The errors might not actually say the exact thing that is wrong.
12:44 So it is a little confusing, right? But I hope to give you a little bit more information here and give you a little hope that now when you run into these errors, you'll know exactly what the problem is.
12:55 You'll, you'll remember it in an instant. And here we say type error spreadsheet app dot get active is not a function.
13:02 And in fact, we know that get active is a function. We know that. Like we, we added it, right? We typed it out, but did we type it out?
13:11 Now let's look at this. If we do spreadsheet app dot get active and we select it. If we select it here, it is a capital A, but the parentheses are not there.
13:23 So we might add toast. We might know toast, but look at this. This is not now, now this is not auto completing, but if we add the parenthesis and add toast, now it is auto completing.
13:36 So you're gonna get these errors. If one you try to type from memory, which I don't suggest you do two if you don't complete what's needed, right?
13:48 Every one of these functions will need a parenthesis except for the spreadsheet app, mail app, the very first one that's capitalized.
13:55 They don't need a parenthesis. But all of the functions from them after them will need a parenthesis. And you'll have to remember to add that.
14:05 That's the one thing you do have to type. And then you'll see this this auto complete. Now with this auto complete going, again, you won't have to type toast, but you do have to type the parenthesis and you have to write some kind of some message here.
14:24 You don't necessarily have to end with a semicolon, it's just that I'm used to that. All right, let's save that.
14:30 Let's not have the parenthesis and let's see what errors we get. Dismiss. It does allow us to save it, but it should.
14:41 There it is. Same thing. Get active dot toast is not a function. And, and of course we know it's a function, we absolutely know it.
14:48 So we're like, oh, what's the problem? What's the problem? No parenthesis Here. Great. If we misspell toast, let's save it and run it again.
14:57 Dismiss, run it again. Toes is not a function, of course it's not. It's supposed to be toast. Cool. So we have, you know, misspelled function.
15:09 We've misspelled menu item or the sort of function names. We've added spaces, we've seen errors without the parenthesis and we've seen errors in here on the bottom and we've seen errors when we run when we run the function here in a custom menu.
15:29 Also, you're gonna get the same issues. If, let's see, let's take out the t here and run. We'll select menu item one, we'll save it and then run menu item one type error spreadsheet app dot get active dot toes is not a function.
15:46 And again, it tells you the file, which is code dot js right here and 11, that's the 11th line. So let's rename this to errors and you'll see if we save that and then run it again.
16:03 Now it says errors dot js 11, right? That is the file name over there that you have to look at.
16:09 If you have multiple files, it's very helpful to know which file it is and what line your error is on.
16:15 And to summarize to finish up this summary sometimes the error is not, the problem is not where the error tells you it is, it's just before it or in front of it sometime before Google is gonna help you a little bit.
16:29 And I hope this video has helped you a lot in getting over these first bumps and humps of seeking out errors.
16:37 If you have any questions go ahead and drop 'em below or let me know. You know, members can email me all the time.
16:45 I'm happy to answer all your questions. Eventually <laugh>, thanks so much. Seek out the errors. They're like little baddies. If you get to a bad, just like playing a game, if you get to the end of a level and you see a batty, you know you're on the right track.
17:00 You know you're on the right way. Bye.
Sheet Stories / Video Notes + ADDED: Email Notifications
ChatGPT Clone in Google Sheets Part 2
Why Different Cell References in AI Integration in Sheets?
Show Sheet Tabs Based on Edit
Add Title Case to Google Sheets
How to Power Testimonials with Google Forms and Sheets
Getting Started Coding in Apps Script
Seek Errors When Coding Apps Script
Think Like a Programmer: Develop The Mindset of an Apps Script Coder
ChatGPT Clone in Google Sheets Part 1
Embed a Number in a Website from a Google Sheet
Create Navigation Like A Book or Presentation
Add Click Tracking To Your Google Sheets | Bitly in a Google Sheet
Hold a Giveaway Raffle in a Google Sheet
Embed a Headline in a Website from Google Sheets
Capture Emails from Website Form to a Google Sheet (Without Zapier)
Quickstart Tutorial OpenAI API in Google Sheets
Create a new Spreadsheet from just a Name in a Sheet.
Bjarne Asks: Can I show the Last Time of the Last Edit in a sheet?
Email Yourself a Cell from a Google Sheet, Every Day
OpenSea Data Inside Sheets
Create an Email Campaign Stats Calculator
Twitter App Clone in a Google Sheet
Dylan Asks: How to Automatically Delete Rows If Cell Contains Value
Highlight Row as You Move Your Cell Selection
Create a Timer with Apps Script
LinkTree in a Google Sheet
Password Protecting Data In a Google Sheet
Automatic Weekly Backup of Google Sheets
Create a CPM Custom Function (Create Better Calculators!)
Move Entire Row when a Cell is changed to "Yes" - The $75,000 Google Script
What Can You Automate in Google Sheets? Every single trigger available to Google Sheet users
Sync Two Tabs Without ImportRange()
Google Sheets Stories? No! But we'll add timestamped video notes to your google sheets.
Password Protecting Data In a Google Sheet Part 2 The Basics
Benoit Asks: How to Convert Case
Learn to Code in Google Sheets, For Programmers
Add a Checkbox to Turn on Dark Mode
Write Your First Script
Find Keywords in Any Column. Create quick search dropdown to find keywords
Basic CRM - Add a Powerful Script To Move Row Based on Status
How To Improve: 1,000 Business ideas: Business Idea Generator
Let's Make a Bookmarklet!
Troubleshooting Bitly in a Google Sheet Script
Unique Features - Design a Better Dashboard Part 2
How To Set Up Stripe Webhook to Google Sheets with Google Script
How to Edit a Macro
Sheet Stories / Video Notes + Clear 24 Hour Old Videos
Add A Timestamp to Task Lists (without Now Formula)
Make your Custom Functions Like Native Functions | Custom Function Autocomplete
Create a Changelog Between 2 Cells Custom Function | To learn Double For Loop
New Syntax for WhatChanged Formula in Google Script
How to Record Macros
2 Ways to Delete Lines Quickly (CAREFUL, it's a script!)
Deep Inside Dark Habits Google Script
How to Trigger Macros Daily
5 Ways to Create Coupon Codes | Create UUIDs
Create a Radio Button From Checkboxes Using Google Apps Script