Even probably the most skilled builders are topic to errors when coding, making understanding learn, debug, and resolve errors a substantial a part of their job. Moreover, when working with a CMS like HubSpot, it is important to know the place to search out error logs and what instruments are offered for debugging.
On this weblog, we’ll present the knowledge obligatory to totally perceive HubSpot’s error logging and the instruments you should use to debug and take a look at your code in HubSpot.
Understanding Errors in HubSpot
Step one to debugging is, after all, understanding the place HubSpot logs errors and understanding what they imply. Let’s discover this in additional element.
Design Supervisor
When coding within the Design Supervisor, errors are proven in actual time, indicated by a shade block to the aspect of the code and in a collapsible record on the backside of the interface. Module fields with errors could have an icon indicator subsequent to the sphere.
Deadly Errors
A deadly error, indicated by the colour crimson, will forestall a web page from efficiently rendering. It should be mounted earlier than the asset might be revealed. Deadly errors can happen in conditions similar to leaving out required HubL variables or together with miswritten HubL.
Warnings
A warning is indicated with the colour yellow. It will not essentially forestall the web page from rendering, however it’s extremely really useful that or not it’s investigated. A warning could possibly be displayed in conditions similar to references to non-existent property or required module fields with out default content material.
HubSpot CLI
When coding domestically, the terminal will show deadly errors when making an attempt to add recordsdata and stop an faulty file from being uploaded.
If utilizing VS Code, you should use the HubSpot VS Code extension to show deadly errors within the Issues tab forward of importing the file.
Warnings are usually not accounted for when utilizing the HubSpot CLI and would require checking the recordsdata within the Design Supervisor.
If you’re writing module or theme fields utilizing HubSpot’s JavaScript fields performance, the errors returned are much less detailed. On this case, it’s higher to make use of the hs cms convert-fields
command to first convert to JSON after which try and add to obtain a extra detailed error.
Web page Editor
The Web page Editor particularly calls out faulty content material in a web page’s settings, modules, and sections. Whereas that is usually useful info for not lacking any required content material, it will also be used to debug incorrectly formatted module fields and template defaults.
Code Alerts
When logged in and viewing a web page, click on the HubSpot Instruments sprocket button to navigate to Code Alerts or go on to https://app.hubspot.com/code-alerts/
. This dashboard lists all stay errors within the portal, listed by the web page on which the faulty property are getting used. When hovering over a listed error, you’ll be able to select to:
- Open the asset within the design supervisor.
- View an in depth syntax error.
- View the debug data on the listed web page.
Debugging Instruments
When your web site has errors which might be greater than a typo, you would possibly have to look deeper. HubSpot gives a number of instruments that will help you get into the nitty-gritty of your templates, modules, and even your portal’s information.
Three of the instruments we’ll handle (Bust Cache, Debug Mode, and Developer Mode) might be extra simply used by means of the HubSpot Developer Extension, a browser extension of helpful shortcuts for HubSpot builders.
Bust Cache
Made a repair however it doesn’t appear to be taking? It is likely to be that your browser’s cache is preserving your webpage from updating to the most recent model of your recordsdata. By including ?hsBustCache=[random#] to the tip of a URL, you’ll be able to drive the browser to point out a cleared cache model of the web page.
Debug Mode
Add ?hsDebug=true to the tip of a URL to render pages with non-minified and uncombined recordsdata, bust cache, and render debugging info within the browser developer instruments.
The debugging info will present a breakdown of rendering request timing, whether or not the web page might be prerendered, and the explanations if not, and likewise show errors and warnings proper within the web page supply.
Developer Mode
Developer Mode is a device used inside HubSpot’s web page editor fairly than on a stay URL. By including ?developerMode=true to the web page editor URL, it’ll add three useful extensions to the editor:
- An Open in Design Supervisor hyperlink on all modules to be able to go on to the code of a module.
- A Reset content material button to reset content material to its default state.
- A Present all Rows toggle, which is able to allow you to view and edit the dnd_rows on the web page.
Developer Data
When logged in and visiting a web page, you’ll be able to click on the HubSpot Instruments sprocket button to navigate to the Developer Data for that web page. The Developer Data is JSON-formatted information of all out there information when a web page is rendering, which might be accessed utilizing HubL. This consists of information similar to contact and firm info, portal settings, buffer modes, template property, theme properties, and far more.
Not solely is this handy for locating when you’re referencing a particular information set appropriately, however it might probably additionally aid you perceive precisely what information you’ll be able to entry and use inside your templates.
To higher view this information, it is suggested to have a JSON formatter extension put in in your browser.
HubL
Lastly, the HubL coding language itself can be utilized for debugging utilizing filters similar to |tojson and |pprint. |pprint can be utilized to print what sort a variable is whereas |tojson can return variable and module subject information in a JSON format.
Environments
Please word: when debugging a stay web site, it could possibly be detrimental to do testing on the stay web site itself, as one thing might break additional whereas testing, or testing would possibly require outputting information on the web page that shouldn’t be seen usually. Utilizing completely different environments inside HubSpot, like Content material Staging or a Sandbox atmosphere, will permit debugging with peace of thoughts. Let’s get into extra element.
Design Supervisor Preview
Debugging a module or template might be difficult as a result of any modifications revealed to the asset will instantly publish to any pages presently utilizing these property. Nonetheless, if coding within the Design Supervisor, modifications might be Previewed with out publishing just by clicking the Preview button within the high proper nook of the interface.
Previewing modules will open an interface with show choices on the high, a sidebar to check your fields, and a preview panel of the rendered output.
Previewing templates present two choices: to preview with or with out show choices.
Draft
If the debugging requires testing one thing, similar to a number of modules working collectively or the usability of a template, it would require an precise web page to work with. That is the place merely Drafting a web page might come in useful. Making a web page and leaving it in Draft is a fast and straightforward solution to take a look at web page settings, modules, and templates out there to all portals.
Nonetheless, do not forget that any modifications revealed to a module or template can even be seen on any revealed pages utilizing these property. If an asset must be debugged whereas getting used on a web page, make a clone of it within the Design Supervisor and do the debugging with the clone.
Content material Staging
Out there to Skilled and Enterprise portals, Content material Staging is sort of much like creating pages in Draft however with the additional benefit of having the ability to stage already current pages. Upon publishing that staged web page, the prevailing web page can be up to date. Staging is especially nice if it’s essential to fully rework an current web page or replace a number of pages, similar to within the case of a site-wide redesign.
Sandbox
Out there to Enterprise customers solely, a sandbox account might be created to totally take a look at all facets of a portal (property, information, workflows, integrations, and many others.) with out affecting any stay content material. Nonetheless, do not forget that the sandbox is a one-way sync from Manufacturing to Sandbox. As soon as testing has been accomplished, the answer should be duplicated throughout the Manufacturing portal.
Grasp HubSpot Debugging At present
Debugging is crucial for any developer working with HubSpot or another CMS. You’ll be able to effectively establish and resolve points in your code by understanding the varied error varieties, understanding the place to search out them, and using the highly effective debugging instruments offered by HubSpot. From the Design Supervisor and HubSpot CLI to Content material Staging and Sandbox environments, HubSpot provides a complete suite of debugging instruments to make sure your web sites and functions run easily.
Are you fighting debugging your HubSpot tasks or want skilled help to optimize your HubSpot improvement workflow? Attain out to the Lynton crew. Our crew of skilled HubSpot builders is prepared that will help you sort out any coding points and enhance your improvement course of!