{"record":{"id":"1b7a72ed65c98de5","repo":"hoppscotch/hoppscotch","slug":"malformed-collection","errorCode":"MALFORMED_COLLECTION","errorMessage":"MALFORMED_COLLECTION","messagePattern":"MALFORMED_COLLECTION","errorType":"error_code","errorClass":"HoppCLIError","httpStatus":null,"severity":"error","filePath":"packages/hoppscotch-cli/src/utils/mutators.ts","lineNumber":25,"sourceCode":"import { error } from \"../types/errors\";\nimport { FormDataEntry } from \"../types/request\";\nimport { isHoppErrnoException } from \"./checks\";\nimport { getResourceContents } from \"./getters\";\n\nconst getValidRequests = (\n  collections: HoppCollection[],\n  collectionFilePath: string\n) => {\n  return collections.map((collection) => {\n    // Validate requests using zod schema\n    const requestSchemaParsedResult = z\n      .array(entityReference(HoppRESTRequest))\n      .safeParse(collection.requests);\n\n    // Handle validation errors\n    if (!requestSchemaParsedResult.success) {\n      throw error({\n        code: \"MALFORMED_COLLECTION\",\n        path: collectionFilePath,\n        data: \"Please check the collection data.\",\n      });\n    }\n\n    // Recursively validate requests in nested folders\n    if (collection.folders.length > 0) {\n      collection.folders = getValidRequests(\n        collection.folders,\n        collectionFilePath\n      );\n    }\n\n    // Return validated collection\n    return {\n      ...collection,\n      requests: requestSchemaParsedResult.data,\n    };","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/hoppscotch/hoppscotch/blob/1acb8a3a7581e4db32ba0d529170c4669a2e1053/packages/hoppscotch-cli/src/utils/mutators.ts#L7-L43","documentation":"Thrown by `getValidRequests` (recursively, into nested folders) when zod fails to validate `collection.requests` against `z.array(entityReference(HoppRESTRequest))`. The schema validates each request object inside a folder; the first folder whose `requests` array contains an invalid request aborts with this code, attaching the collection file path and a generic hint.","triggerScenarios":"A request object is missing required fields (`method`, `endpoint`, `auth`, `headers`, `params`, `body`); a request was hand-edited and its `v` (version) field is invalid; an old collection exported by a much older Hoppscotch client whose request schema no longer satisfies `HoppRESTRequest`.","commonSituations":"Manually editing exported collection JSON; collection exported from an outdated self-hosted Hoppscotch; partial/corrupt export that truncated a request object.","solutions":["Re-export the collection from a current Hoppscotch client rather than hand-editing it.","Open the collection JSON and inspect each request object — every request needs `v`, `method`, `endpoint`, `name`, `headers`, `params`, `auth`, `body`, `preRequestScript`, `testScript`, `requestVariables`.","If only one folder is affected, isolate it: run `hopp test` on a trimmed collection to identify the offending request.","Upgrade the CLI to a version whose `HoppRESTRequest` schema matches the client that produced the collection."],"exampleFix":"// before: request object missing required `body` field\n{ \"v\": 1, \"name\": \"x\", \"method\": \"GET\", \"endpoint\": \"/u\", \"auth\": {\"authActive\": false, \"authType\": \"none\"}, \"headers\": [], \"params\": [] }\n\n// after: include body\n{ \"v\": 1, \"name\": \"x\", \"method\": \"GET\", \"endpoint\": \"/u\", \"auth\": {\"authActive\": false, \"authType\": \"none\"}, \"headers\": [], \"params\": [], \"body\": {\"contentType\": null, \"body\": \"\"} }","handlingStrategy":"validation","validationCode":"import { z } from 'zod';\nimport { entityReference } from 'verzod';\nimport { HoppRESTRequest } from '@hoppscotch/data';\n\nconst schema = z.array(entityReference(HoppRESTRequest));\nfunction validateRequests(requests: unknown[], label: string) {\n  const r = schema.safeParse(requests);\n  if (!r.success) console.error(`Folder ${label}:`, r.error.issues);\n  return r.success;\n}","typeGuard":"const hasValidRequests = (c: unknown): boolean =>\n  schema.safeParse((c as any)?.requests).success;","tryCatchPattern":"try { return getValidRequests(collections, path); }\ncatch (e) {\n  if (isHoppCLIError(e) && e.code === 'MALFORMED_COLLECTION') {\n    // quarantine the bad collection, continue with the rest\n    return collections.filter(c => schema.safeParse(c.requests).success);\n  } throw e;\n}","preventionTips":["Re-export collections from the Hoppscotch UI rather than hand-editing.","Run a zod pre-check in CI to fail before invoking hopp."],"tags":["validation","zod","schema","collection","requests"],"backgroundTag":null,"analyzedSha":"1acb8a3a7581e4db32ba0d529170c4669a2e1053","analyzedAt":"2026-08-12T11:34:52.648Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}