◢███◤      ◢██◤                            ◢██◤                            
     ◢██◤       ◢██◤                            ◢██◤                             
    ◢██◤       ◢██◤                            ◢██◤                              
   ◢██◤       ◢██◤                            ◢██◤                               
  ◢██◤       ◢██◤                            ◢██◤                                
◢███◤       ◢██◤                            ◢██◤                          ◥██◣   
◥███       ◢█████◣    ◢████████◤ ◢███████◤ ◢██◤ ◢██◤                 ◢██◤   ██◣  
 ███      ◢███████◣        ◢██◤ ◢██◤ ◢██◤ ◢███████◤                 ◢██◤    ███  
 ███     ◢██◤  ◢██◤ ◢████████◤ ◢██◤      ◢█████◣                   ◢██◤     ███  
 ███    ◢██◤  ◢██◤ ◢██◤  ███◤ ◢██◤ ◢██◤ ◢██◤◥███◣                 ◢██◤      ███  
 ◥██   ◢██◤  ◢██◤ ◢████████◤ ◢███████◤ ◢██◤  ◥███◣               ◢██◤       ███◣ 
  ◥██◣                                                          ◢██◤       ◢███◤ 
                                 ◢███◤ ◢███◤ ◢██◤  ◢██◤ ◢█████████◤       ◢██◤   
                                ◢█████████◤ ◢██◤  ◢██◤ ◢██◤  ████◤       ◢██◤    
                               ◢██◤◢█◤◢██◤ ◢██◤  ◢██◤ ◢██◤   ███◤       ◢██◤     
                              ◢██◤   ◢██◤ ◢████████◤ ◢█████████◤       ◢██◤      
                             ◢██◤   ◢██◤ ◢████████◤ ◢█████████◤      ◢███◤       

0008
Common Script Errors and Causes
hzdtrz
There are a few common script errors that are almost always caused by the same general error. This post tries to list as many of them as we could think of. Add more in comments, and I'll copy into the main body. UPLOAD ERRORS {retval:"PARSE ERROR your.script: Error: Line NUM: Unexpected end of input",success:false} Where NUM is a number significantly larger than your script is long: almost always a missing }, ], or ) (in roughly that order of likeliness) {retval:"PARSE ERROR your.script: Error: Line NUM: Unexpected token ILLEGAL",success:false} Almost always an incorrect usage of a preprocessor expansion. Common examples: #fs.foo.bar // no parens #fs.foo.bar () // space before parens #fmcl // should be in caps #DB.F() // should be in lower case Note: The line number here is almost always close to accurate. Look above or below the number indicated by a few lines. {retval:"PARSE ERROR your.script (line 1): code must be wrapped in a function (must start with 'function (context, args){'",success:false} {retval:"PARSE ERROR your.script (line NUM): code must be wrapped in a function (must end with '}')",success:false} Usually caused by a comment above (first case) or after (second case) your main function. These comments must be inside the function. >>#up something.js Could not find the script source file. Don't specify .js, it is added automatically. RUNTIME ERRORS :::TRUST COMMUNICATION::: TypeError: Cannot read property 'foo' of null Where 'foo' is an argument you access in the script (like args.foo). Almost always this is caused by accessing arguments (like args.foo) in a script, but calling the script without arguments (i.e. foo.bar not foo.bar{}). Relatively easy fix: add "args=args||{}" to the top of your script, just inside the function :::TRUST COMMUNICATION::: TypeError: Cannot read property '1' of null Where 1 is almost always 1, but maybe 2 or 3. This is almost always caused by doing str.match(someRegex)[1], but the regex doesn't match the string at all. I usually do something like (str.match(someRegex)||[,"FAIL"])[1]. :::TRUST COMMUNICATION::: TypeError: someVar.split is not a function :::TRUST COMMUNICATION::: TypeError: someVar.match is not a function (etc) You are expecting a string (or array or object) but had something else. Common causes: t1 corps returning an object when shifting, and you expected a string and blindly tried to call string methods on it; certain parts of corps returning arrays when you think they return strings. Easiest fix: if you assume a type after calling an external script, check the type (with typeof) to make sure, and raise a better error if the type isn't what you want. For example, if you expect someVar to be a string, consider adding if(typeof someVar!="string")return someVar // someVar probably has an error message in it so may as well show it to the user
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -