Troubleshooting JSiteDescriptor: Errors and Fixes
1. Common error: “JSiteDescriptor not defined”
- Cause: The module or script that defines JSiteDescriptor wasn’t loaded before use.
- Fixes:
- Ensure script tag or module import appears before any code referencing JSiteDescriptor.
- For ES modules: use
import { JSiteDescriptor } from ‘…’;. - For globals: verify correct global name and that build step exposes it.
2. Common error: “Invalid descriptor format” or schema validation failures
- Cause: The descriptor object misses required fields or uses wrong types.
- Fixes:
- Validate against the expected schema: required keys, types (string, boolean, arrays), and nested shapes.
- Add defensive checks: throw clear errors when a required field is absent.
- Use a JSON schema validator (e.g., ajv) to produce precise messages.
3. Common error: “Failed to resolve site dependencies” or missing resources
- Cause: Descriptor references assets, modules, or routes that aren’t reachable or registered.
- Fixes:
- Confirm paths/URLs in descriptor are correct and accessible (relative vs absolute).
- Ensure referenced modules are exported and registered with the loader.
- For runtime loading, add retry/backoff and clearer logs for which dependency failed.
4. Common error: “Permission denied” or access-control related failures
- Cause: Descriptor triggers network calls blocked by CORS, CSP, or auth.
- Fixes:
- For CORS: enable appropriate Access-Control-Allow-Origin on target servers or use same-origin resources.
- For CSP: update policy to allow needed script/style sources.
- For auth: include required tokens/credentials and refresh flows; avoid leaking secrets in descriptors.
5. Common error: Performance issues or slow initialization
- Cause: Large descriptor, many synchronous fetches, blocking work during startup.
- Fixes:
- Lazy-load optional modules and assets; mark noncritical items for deferred loading.
- Convert synchronous initializers to async; show skeleton UI while loading.
- Compress assets, use CDN, and cache descriptor responses.
6. Common error: Incompatible version or breaking API changes
- Cause: Descriptor schema or JSiteDescriptor API changed between releases.
- Fixes:
- Check package/changelog for breaking changes; pin compatible version.
- Add an adapter layer that maps old descriptor shape to new API.
- Run automated migration scripts to update descriptors in bulk.
7. Debugging tips and best practices
- Logging: Add contextual logs (descriptor id, fields) and log validation errors with path info.
- Validation: Validate descriptors at build-time and runtime; fail fast with helpful messages.
- Tests: Create unit tests for descriptor parsing and integration tests for loading behavior.
- Tooling: Use JSON schema + linters in CI to catch issues before deployment.
- Fallbacks: Provide safe defaults or minimal fallback descriptors to keep the app running.
8. Quick checklist to resolve an issue
- Confirm JSiteDescriptor is loaded/imported correctly.
- Validate descriptor shape and required fields.
- Verify referenced assets/modules/routes exist and are accessible.
- Check network, CORS, CSP, and auth for blocked requests.
- Confirm version compatibility and review changelogs.
- Reproduce with logs and write a unit test covering the failing case.
If you share the exact error message and a sample descriptor, I can give a targeted fix.
Leave a Reply