{"record":{"id":"36f0e11612fdceed","repo":"octobercms/october","slug":"cannot-switch-to-container-a-container-element-is","errorCode":null,"errorMessage":"Cannot switch to container: a container element is not found","messagePattern":"Cannot switch to container: a container element is not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"modules/backend/assets/foundation/controls/inspector/inspector.manager.js","lineNumber":85,"sourceCode":"        var options = $.extend(this.loadElementOptions(wrapper.$element), {\n                containerSupported: true\n            })\n\n        new $.oc.inspector.wrappers.popup(wrapper.$element, wrapper, options)\n\n        wrapper.cleanupAfterSwitch();\n        this.setContainerPreference(false);\n    }\n\n    InspectorManager.prototype.switchToContainer = function(wrapper) {\n        var $container = this.getContainerElement(wrapper.$element),\n            options = $.extend(this.loadElementOptions(wrapper.$element), {\n                containerSupported: true,\n                container: $container\n            });\n\n        if (!$container) {\n            throw new Error('Cannot switch to container: a container element is not found');\n        }\n\n        new $.oc.inspector.wrappers.container(wrapper.$element, wrapper, options);\n\n        wrapper.cleanupAfterSwitch();\n        this.setContainerPreference(true);\n    }\n\n    InspectorManager.prototype.createInspector = function(element) {\n        var $element = $(element);\n\n        if ($element.data('oc.inspectorVisible')) {\n            return false;\n        }\n\n        var $container = this.getContainerElement($element);\n\n        // If there's no container option, create the Inspector popup","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/backend/assets/foundation/controls/inspector/inspector.manager.js#L67-L103","documentation":"ReportDataPaginationParams is the value object dashboard report widgets use to paginate result sets. Its constructor enforces that `$recordsPerPage` is a positive integer (> 0) — zero or negative values are rejected immediately with this ApplicationException, since they make page math (offset = page * recordsPerPage) meaningless or division-based calculations fatal.","triggerScenarios":"Constructing with `(int) get('per_page')` when the parameter is absent so it casts to 0; a UI page-size selector that allows 0 or empty; defaulting recordsPerPage to 0 in a custom report widget before the user picks a size.","commonSituations":"Optional 'limit'/'per_page' request parameters that arrive empty and become 0; widgets initialized before configuration loads; tests constructing the object with 0 to mean 'no pagination'.","solutions":["Pass a positive page size, e.g. `new ReportDataPaginationParams(20, $page)`.","Guard user input before constructing: reject or default `per_page` values below 1 in the handler.","If 'no pagination' is needed, skip creating ReportDataPaginationParams entirely rather than passing 0."],"exampleFix":"// before\nnew ReportDataPaginationParams((int) array_get($params, 'per_page', 0), 0);\n\n// after\n$perPage = (int) array_get($params, 'per_page', 20);\nif ($perPage < 1) {\n    $perPage = 20;\n}\nnew ReportDataPaginationParams($perPage, 0);","handlingStrategy":"validation","validationCode":"// Validate at the request boundary\n$perPage = (int) request()->input('per_page', 20);\nif ($perPage < 1) {\n    throw new ValidationException(['per_page' => 'Records per page must be a positive integer']);\n}\n$params = new \\Dashboard\\Classes\\ReportDataPaginationParams($perPage, max(0, $page));","typeGuard":"/**\n * @param mixed $value\n * @returns {boolean}\n */\nfunction isPositivePageCount($value)\n{\n    return is_int($value) && $value > 0;\n}","tryCatchPattern":null,"preventionTips":["Default page size to a sane positive constant (e.g. 20) instead of 0 when input is missing.","Validate per_page/limit query parameters as integers >= 1 before building pagination.","Skip pagination entirely rather than passing 0 to mean 'all records'."],"tags":["october-cms","dashboard","reports","pagination","validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}