Silent null from Script Properties is how staging pointers and API bases "work" until they write nowhere. requireScriptProperty throws with the key name when the value is missing or blank so you fail at the top of the run, not halfway through a sync.
What you'll need
- A Script Property key you depend on (
ACTIVE_SPREADSHEET_ID,API_BASE, etc.) - A handler that should refuse to run without it
How to use this snippet
function requireScriptProperty(key) {
var v = PropertiesService.getScriptProperties().getProperty(key);
if (v == null || String(v).trim() === '') {
throw new Error('Missing Script Property: ' + key);
}
return v;
}
function openActiveSpreadsheet() {
var id = requireScriptProperty('ACTIVE_SPREADSHEET_ID');
return SpreadsheetApp.openById(id);
}
Tips
- Prefer this over
getProperty+ soft defaults for anything that can write to the wrong sheet. - Pair with a menu that lists required keys so ops can see what's unset before a nightly run.
- Don't put secrets in logs — throwing the key name is enough.
Soft tip: NitroGAS already has Script Properties helpers; Co-Pilot can leave a plain-English note next to the property list for whoever inherits the project. Happy Coding.
