jeessy2/ddns-go · warning
Unknown trigger: ${trigger}
Error message
Unknown trigger: ${trigger} What it means
Tooltip._bindEvents switches on the configured trigger to attach show/hide listeners ('manual' is a no-op); any trigger value outside the supported set hits the default branch and logs this console.warn. The tooltip is still constructed but its trigger behavior is undefined/never bound.
Source
Thrown at static/tooltips.js:154
this.$element.addEventListener('mouseleave', _leave);
break;
case 'focus':
this.$element.addEventListener('focusin', _enter);
this.$element.addEventListener('focusout', _leave);
break;
case 'click':
this.$element.addEventListener('click', () => {
if (this.$tooltip) {
this.hide();
} else {
this.show();
}
});
break;
case 'manual':
break;
default:
console.warn(`Unknown trigger: ${trigger}`);
}
});
}
}
// 初始化所有带data-tooltip属性的元素
const initTooltips = () => {
window.tooltips = {};
document.querySelectorAll('[data-toggle="tooltip"]').forEach(element => {
let key = element.dataset.tooltipKey || element.id;
if (!key) {
key = crypto.randomUUID();
element.dataset.tooltipKey = key;
}
window.tooltips[key] = new Tooltip(element);
});
};
View on GitHub (pinned to 5874c2e666)
Solutions
- Correct the trigger option to one of the supported values handled by _bindEvents's switch cases.
- Validate the trigger value in the constructor and throw/throw early with the list of allowed values instead of only warning.
- Check library docs/migration guide if the trigger names changed between versions.
- Whitelist the trigger when it comes from configuration or markup before constructing the tooltip.
Example fix
// before
new Tooltip(el, { trigger: 'hover' }); // if only click/focus/manual supported
// after
new Tooltip(el, { trigger: 'click' }); // or the correct supported value Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_TRIGGERS = ['hover', 'click', 'focus', 'manual'];
function isValidTrigger(trigger) {
return SUPPORTED_TRIGGERS.includes(trigger);
}
if (!isValidTrigger(opts.trigger)) {
throw new Error(`trigger must be one of ${SUPPORTED_TRIGGERS.join(', ')}, got: ${opts.trigger}`);
} Type guard
function isValidTrigger(t) {
return ['hover', 'click', 'focus', 'manual'].includes(t);
} Prevention
- Use constants/enums for trigger names instead of raw strings.
- Validate constructor options early and fail fast with allowed values.
- Check docs when migrating tooltip libraries for renamed trigger options.
- Test each configured trigger in dev to catch the warning.
When it happens
Trigger: new Tooltip(el, { trigger: 'something' }) or data-trigger="something" where the value is not one of the handled cases (e.g. hover/click/focus/manual as implemented); often a typo like 'hovr' or a copied option name from another tooltip library.
Common situations: Typo in the trigger option; migrating from another library whose trigger names differ; passing user/config-provided trigger strings without validation.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- i18n: No translation for key "${key}"
- i18n: No such language "${lang}" in langDict ${langDict}
- throw new Error(resp)
AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03).
Data as JSON: /api/errors/882e4d525c65e3f2.
Report an issue: GitHub.